Merge "Fix nits in allocation candidate limit handling"

This commit is contained in:
Zuul
2018-02-15 04:13:11 +00:00
committed by Gerrit Code Review
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 Endpoint interface for this node. This is used when picking the URL in the
service catalog. service catalog.
"""), """),
cfg.BoolOpt('randomize_allocation_candidates', cfg.BoolOpt(
default=False, 'randomize_allocation_candidates',
help=""" default=False,
help="""
If True, when limiting allocation candidate results, the results will be If True, when limiting allocation candidate results, the results will be
a random sampling of the full result set. If False, allocation candidates a random sampling of the full result set. If False, allocation candidates
are returned in a deterministic but undefined order. That is, all things 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 # needing to mess with the complex sql above or add additional
# columns to the DB. # 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 limit and limit <= len(alloc_request_objs):
if CONF.placement.randomize_allocation_candidates: if CONF.placement.randomize_allocation_candidates:
alloc_request_objs = random.sample(alloc_request_objs, limit) alloc_request_objs = random.sample(alloc_request_objs, limit)
else: else:
alloc_request_objs = alloc_request_objs[:limit] 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: elif CONF.placement.randomize_allocation_candidates:
random.shuffle(alloc_request_objs) random.shuffle(alloc_request_objs)
# Limit summaries to only those mentioned in the allocation requests. # Limit summaries to only those mentioned in the allocation requests.
if limit and limit <= len(alloc_request_objs): if limit and limit <= len(alloc_request_objs):
kept_summary_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: for summary in summary_objs:
rp_uuid = summary.resource_provider.uuid rp_uuid = summary.resource_provider.uuid
# Skip a summary if we are limiting and haven't selected an # Skip a summary if we are limiting and haven't selected an