Adds check for duplicate alloc_cands
This patch adds a check for duplicate allocation candidates in granular requests scenarios. To check the duplication, the __eq__ and and the __hash__ operators are added both to AllocationRequestResource class and to AllocationRequest class. Change-Id: I8b5b0212077ca930ee69d3f1c349f41433bae68e Closes-Bug: #1817458
This commit is contained in:
parent
e4f3c76fb4
commit
ac57123344
|
@ -2751,6 +2751,16 @@ class AllocationRequestResource(object):
|
|||
self.resource_class = resource_class
|
||||
self.amount = amount
|
||||
|
||||
def __eq__(self, other):
|
||||
return (self.resource_provider.id == other.resource_provider.id) and (
|
||||
self.resource_class == other.resource_class) and (
|
||||
self.amount == other.amount)
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.resource_provider.id,
|
||||
self.resource_class,
|
||||
self.amount))
|
||||
|
||||
|
||||
class AllocationRequest(object):
|
||||
|
||||
|
@ -2780,6 +2790,12 @@ class AllocationRequest(object):
|
|||
repr_str = encodeutils.safe_encode(repr_str, incoming='utf-8')
|
||||
return repr_str
|
||||
|
||||
def __eq__(self, other):
|
||||
return set(self.resource_requests) == set(other.resource_requests)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(tuple(self.resource_requests))
|
||||
|
||||
|
||||
class ProviderSummaryResource(object):
|
||||
|
||||
|
@ -3949,7 +3965,7 @@ def _merge_candidates(candidates, group_policy=None):
|
|||
|
||||
# Create all combinations picking one AllocationRequest from each list
|
||||
# for each anchor.
|
||||
areqs = []
|
||||
areqs = set()
|
||||
all_suffixes = set(candidates)
|
||||
num_granular_groups = len(all_suffixes - set(['']))
|
||||
for areq_lists_by_suffix in areq_lists_by_anchor.values():
|
||||
|
@ -4002,7 +4018,7 @@ def _merge_candidates(candidates, group_policy=None):
|
|||
# folded together. So do a final capacity check/filter.
|
||||
if _exceeds_capacity(areq, psum_res_by_rp_rc):
|
||||
continue
|
||||
areqs.append(areq)
|
||||
areqs.add(areq)
|
||||
|
||||
# It's possible we've filtered out everything. If so, short out.
|
||||
if not areqs:
|
||||
|
@ -4019,7 +4035,7 @@ def _merge_candidates(candidates, group_policy=None):
|
|||
psums = [psum for psum in all_psums if
|
||||
psum.resource_provider.root_provider_uuid in tree_uuids]
|
||||
|
||||
return areqs, psums
|
||||
return list(areqs), psums
|
||||
|
||||
|
||||
class AllocationCandidates(object):
|
||||
|
|
|
@ -143,19 +143,10 @@ tests:
|
|||
resources1: DISK_GB:800
|
||||
status: 200
|
||||
response_json_paths:
|
||||
# FIXME: Bug#1817458: When we request shared resource alone granularly,
|
||||
# we get duplicate allocation candidates for a same resource provider.
|
||||
# NOTE: This bug happens only on granular scenarios. See the next test.
|
||||
# $.allocation_requests.`len`: 2
|
||||
# $.provider_summaries.`len`: 2
|
||||
# $.allocation_requests..allocations["$ENVIRON['SHR_DISK_1']"].resources[DISK_GB]: 800
|
||||
# $.allocation_requests..allocations["$ENVIRON['SHR_DISK_2']"].resources[DISK_GB]: 800
|
||||
$.allocation_requests.`len`: 9
|
||||
$.allocation_requests.`len`: 2
|
||||
$.provider_summaries.`len`: 2
|
||||
# 4 duplicates for "shar_disk_1" and 5 for "shr_disk_2".
|
||||
# This looks like a number of the anchor_root_providers (including itself)
|
||||
$.allocation_requests..allocations["$ENVIRON['SHR_DISK_1']"].resources[DISK_GB]: [800, 800, 800, 800]
|
||||
$.allocation_requests..allocations["$ENVIRON['SHR_DISK_2']"].resources[DISK_GB]: [800, 800, 800, 800, 800]
|
||||
$.allocation_requests..allocations["$ENVIRON['SHR_DISK_1']"].resources[DISK_GB]: 800
|
||||
$.allocation_requests..allocations["$ENVIRON['SHR_DISK_2']"].resources[DISK_GB]: 800
|
||||
|
||||
- name: disk alone non-granular
|
||||
GET: /allocation_candidates
|
||||
|
|
Loading…
Reference in New Issue