Fix nits in allocation candidate limit handling

In the review for I5f3d4f49c34fd3cd6b9d2e12b3c3c4cdcb409bec some
non-blocking issues were identified. They are fixed here:

* inconsistent indentation in configuration setting
* creation of a uuid tracking set in the wrong block

Change-Id: I848d60f9a5d66cae584279f99a50b9e871540baf
This commit is contained in:
Chris Dent 2018-01-23 11:57:48 +00:00
parent 7e5d93edc5
commit 7f1dee5302
2 changed files with 9 additions and 10 deletions

View File

@ -50,9 +50,10 @@ Possible values:
Endpoint interface for this node. This is used when picking the URL in the
service catalog.
"""),
cfg.BoolOpt('randomize_allocation_candidates',
default=False,
help="""
cfg.BoolOpt(
'randomize_allocation_candidates',
default=False,
help="""
If True, when limiting allocation candidate results, the results will be
a random sampling of the full result set. If False, allocation candidates
are returned in a deterministic but undefined order. That is, all things

View File

@ -3567,24 +3567,22 @@ class AllocationCandidates(base.NovaObject):
# needing to mess with the complex sql above or add additional
# columns to the DB.
# Track the resource provider uuids that we have chosen so that
# we can pull out their summaries below.
alloc_req_rp_uuids = set()
if limit and limit <= len(alloc_request_objs):
if CONF.placement.randomize_allocation_candidates:
alloc_request_objs = random.sample(alloc_request_objs, limit)
else:
alloc_request_objs = alloc_request_objs[:limit]
# Extract resource provider uuids from the resource requests.
for aro in alloc_request_objs:
for arr in aro.resource_requests:
alloc_req_rp_uuids.add(arr.resource_provider.uuid)
elif CONF.placement.randomize_allocation_candidates:
random.shuffle(alloc_request_objs)
# Limit summaries to only those mentioned in the allocation requests.
if limit and limit <= len(alloc_request_objs):
kept_summary_objs = []
alloc_req_rp_uuids = set()
# Extract resource provider uuids from the resource requests.
for aro in alloc_request_objs:
for arr in aro.resource_requests:
alloc_req_rp_uuids.add(arr.resource_provider.uuid)
for summary in summary_objs:
rp_uuid = summary.resource_provider.uuid
# Skip a summary if we are limiting and haven't selected an