From b54b9a32922943c5aa7e1f28bfedcc04ba475e99 Mon Sep 17 00:00:00 2001 From: Dileep Ranganathan Date: Wed, 4 Apr 2018 04:53:43 -0700 Subject: Fixed HPA matching when no flavor is found 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 --- conductor/conductor/data/service.py | 3 +-- conductor/conductor/solver/optimizer/constraints/hpa.py | 11 ++++++----- conductor/conductor/tests/unit/solver/test_hpa.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'conductor') diff --git a/conductor/conductor/data/service.py b/conductor/conductor/data/service.py index 5912963..f4e3aac 100644 --- a/conductor/conductor/data/service.py +++ b/conductor/conductor/data/service.py @@ -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( diff --git a/conductor/conductor/solver/optimizer/constraints/hpa.py b/conductor/conductor/solver/optimizer/constraints/hpa.py index 9ef37df..98d95d9 100644 --- a/conductor/conductor/solver/optimizer/constraints/hpa.py +++ b/conductor/conductor/solver/optimizer/constraints/hpa.py @@ -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 diff --git a/conductor/conductor/tests/unit/solver/test_hpa.py b/conductor/conductor/tests/unit/solver/test_hpa.py index c9bbbbc..3964c06 100644 --- a/conductor/conductor/tests/unit/solver/test_hpa.py +++ b/conductor/conductor/tests/unit/solver/test_hpa.py @@ -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] -- cgit 1.2.3-korg