Fixed HPA matching when no flavor is found 27/41027/3
authorDileep Ranganathan <dileep.ranganathan@intel.com>
Wed, 4 Apr 2018 11:53:43 +0000 (04:53 -0700)
committerDileep Ranganathan <dileep.ranganathan@intel.com>
Fri, 6 Apr 2018 10:15:27 +0000 (03:15 -0700)
When no matching flavor is found the candidate list
should be discarded and the solution should be not_found.
Refactored the logic if there is already flavor_mapping.

Change-Id: I24ea91436a5a5c78698801f435a6deb9e9d447e9
Issue-ID: OPTFRA-213
Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
conductor/conductor/data/service.py
conductor/conductor/solver/optimizer/constraints/hpa.py
conductor/conductor/tests/unit/solver/test_hpa.py

index 5912963..f4e3aac 100644 (file)
@@ -454,10 +454,9 @@ class DataEndpoint(object):
             # exists. This is an invalid condition.
             if candidate.get("flavor_map") and candidate["flavor_map"].get(
                     label_name):
-                error = True
                 LOG.error(_LE("Flavor mapping for label name {} already"
                               "exists").format(label_name))
-                return {'response': None, 'error': error}
+                continue
 
             # RPC call to inventory provider for matching hpa capabilities
             results = self.ip_ext_manager.map_method(
index 9ef37df..98d95d9 100644 (file)
@@ -59,10 +59,11 @@ class HPA(constraint.Constraint):
             response = (cei.get_candidates_with_hpa(label_name,
                                                     _candidate_list,
                                                     flavorProperties))
-            if response:
-                _candidate_list = response
-            else:
-                LOG.error(_LE("Flavor mapping for label name {} already"
-                              "exists").format(label_name))
+            _candidate_list = response
+            if not response:
+                LOG.error(_LE("No matching candidates for HPA exists").format(
+                    label_name))
+                break
+                # No need to continue.
 
         return _candidate_list
index c9bbbbc..3964c06 100644 (file)
@@ -77,9 +77,9 @@ class TestHPA(unittest.TestCase):
         client_mock.call.return_value = None
         request_mock.cei = cei.ConstraintEngineInterface(client_mock)
 
-        self.assertEqual(self.candidate_list,
-                         self.hpa.solve(mock_decision_path,
-                                        self.candidate_list, request_mock))
+        self.assertEqual(None, self.hpa.solve(mock_decision_path,
+                                              self.candidate_list,
+                                              request_mock))
 
         client_mock.call.side_effect = [hpa_candidate_list_1,
                                         hpa_candidate_list_2]