From 1e635c3ce0efe9592be2ea5d6a70d8b75301b7ad Mon Sep 17 00:00:00 2001 From: Ruoyu Ying Date: Fri, 11 Jan 2019 20:33:18 +0800 Subject: Check flavor exist before hpa matching Check whether there is flavor info inside the candidate. If exists, continue to the hpa matching. Change-Id: I72762d90050ee35fea672cd06c038f2b6382f730 Signed-off-by: Ruoyu Ying Issue-ID: OPTFRA-412 --- conductor/conductor/data/plugins/inventory_provider/aai.py | 5 ++++- .../conductor/data/plugins/inventory_provider/hpa_utils.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'conductor') diff --git a/conductor/conductor/data/plugins/inventory_provider/aai.py b/conductor/conductor/data/plugins/inventory_provider/aai.py index f37a40a..bde5b03 100644 --- a/conductor/conductor/data/plugins/inventory_provider/aai.py +++ b/conductor/conductor/data/plugins/inventory_provider/aai.py @@ -1607,7 +1607,10 @@ class AAI(base.InventoryProviderBase): def match_hpa(self, candidate, features): """Match HPA features requirement with the candidate flavors """ hpa_provider = hpa_utils.HpaMatchProvider(candidate, features) - directives = hpa_provider.match_flavor() + if hpa_provider.init_verify(): + directives = hpa_provider.match_flavor() + else: + directives = None return directives diff --git a/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py b/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py index 84d4c87..8af2e36 100644 --- a/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py +++ b/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py @@ -53,10 +53,20 @@ def match_all_operator(big_list, small_list): class HpaMatchProvider(object): def __init__(self, candidate, req_cap_list): - self.flavors_list = candidate['flavors']['flavor'] + self.flavors_list = None + if isinstance(candidate.get('flavors'), dict) \ + and candidate.get('flavors').get('flavor'): + self.flavors_list = candidate.get('flavors').get('flavor') self.req_cap_list = req_cap_list self.m_vim_id = candidate.get('vim-id') + # Find out whether there is flavor info inside the candidate + def init_verify(self): + if self.flavors_list is not None: + return True + else: + return False + # Find the flavor which has all the required capabilities def match_flavor(self): # Keys to find capability match -- cgit 1.2.3-korg