yahoo-eng-team team mailing list archive
-
yahoo-eng-team team
-
Mailing list archive
-
Message #48990
[Bug 1565824] Re: config option generation doesn't work with itertools.chain generator
Reviewed: https://review.openstack.org/301166
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=ee53631886fff8c7e9d09b19b3456d0e80c5de88
Submitter: Jenkins
Branch: master
commit ee53631886fff8c7e9d09b19b3456d0e80c5de88
Author: Markus Zoeller <mzoeller@xxxxxxxxxx>
Date: Mon Apr 4 16:42:25 2016 +0200
config option generation doesn't work with a generator
The config options won't get emitted into "sample.config" when the
"itertools.chain" method is used to combine multiple lists. The reason
is that the generator created by "itertools.chain" doesn't get reset
after getting used in "register_opts". A simple complete example:
import itertools
a = [1, 2]
b = [3, 4]
ab = itertools.chain(a, b)
print("printing 'ab' for the first time")
for i in ab:
print(i)
print("printing 'ab' for the second time")
for i in ab:
print(i)
The combined list 'ab' won't get printed a second time. The same thing
happens when the "oslo.config" generator wants to print the file
"sample.config". The method "register_opts" gets called first and
sets the cursor of the generator to the end, which means the same
generator in "list_opts" is already at its end and iterates over
nothing.
This change creates a list with the generator. This list can be used
multiple times, first by "register_opts" and then by "list_opts".
The options get emitted into the "sample.config" file again.
Closes bug 1565824
Change-Id: Ib1bad2d76f34c5557b089f225511adfc0259fdb6
** Changed in: nova
Status: In Progress => Fix Released
--
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1565824
Title:
config option generation doesn't work with itertools.chain generator
Status in OpenStack Compute (nova):
Fix Released
Bug description:
Config options code like this doesn't generate output in the
sample.config file:
ALL_OPTS = itertools.chain(
compute_opts,
resource_tracker_opts,
allocation_ratio_opts
)
def register_opts(conf):
conf.register_opts(ALL_OPTS)
def list_opts():
return {'DEFAULT': ALL_OPTS}
The reason is that the generator created by "itertools.chain" doesn't
get reset after getting used in "register_opts". A simple complete
example:
import itertools
a = [1, 2]
b = [3, 4]
ab = itertools.chain(a, b)
print("printing 'ab' for the first time")
for i in ab:
print(i)
print("printing 'ab' for the second time")
for i in ab:
print(i)
The combined list 'ab' won't get printed a second time. The same thing
happens when the oslo.config generator wants to print the
sample.config file. This means we use either:
ab = list(itertools.chain(a, b))
or
ab = a + b
To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1565824/+subscriptions
References