Check flavor exist before hpa matching 56/75656/1
authorRuoyu Ying <ruoyu.ying@intel.com>
Fri, 11 Jan 2019 12:33:18 +0000 (20:33 +0800)
committerRuoyu Ying <ruoyu.ying@intel.com>
Fri, 11 Jan 2019 12:36:09 +0000 (20:36 +0800)
Check whether there is flavor info inside the candidate.
If exists, continue to the hpa matching.

Change-Id: I72762d90050ee35fea672cd06c038f2b6382f730
Signed-off-by: Ruoyu Ying <ruoyu.ying@intel.com>
Issue-ID: OPTFRA-412

conductor/conductor/data/plugins/inventory_provider/aai.py
conductor/conductor/data/plugins/inventory_provider/hpa_utils.py

index f37a40a..bde5b03 100644 (file)
@@ -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
 
 
index 84d4c87..8af2e36 100644 (file)
@@ -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