From 129de26419344224e42f176b4f14ff04e8a08be8 Mon Sep 17 00:00:00 2001 From: suzhengwei Date: Mon, 22 May 2017 16:16:46 +0800 Subject: [PATCH] avoid repeated actions in the solution Change-Id: If163aee969b51764d69d42655c05e0651e4f150c --- watcher/decision_engine/solution/default.py | 10 +++++++++- .../planner/test_weight_planner.py | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/watcher/decision_engine/solution/default.py b/watcher/decision_engine/solution/default.py index 8c0381628..be895df27 100644 --- a/watcher/decision_engine/solution/default.py +++ b/watcher/decision_engine/solution/default.py @@ -16,10 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from oslo_log import log + from watcher.applier.actions import base as baction from watcher.common import exception from watcher.decision_engine.solution import base +LOG = log.getLogger(__name__) + class DefaultSolution(base.BaseSolution): def __init__(self, goal, strategy): @@ -50,7 +54,11 @@ class DefaultSolution(base.BaseSolution): 'action_type': action_type, 'input_parameters': input_parameters } - self._actions.append(action) + if action not in self._actions: + self._actions.append(action) + else: + LOG.warning('Action %s has been added into the solution, ' + 'duplicate action will be dropped.', str(action)) def __str__(self): return "\n".join(self._actions) diff --git a/watcher/tests/decision_engine/planner/test_weight_planner.py b/watcher/tests/decision_engine/planner/test_weight_planner.py index ee41dc446..3c9cc48a2 100644 --- a/watcher/tests/decision_engine/planner/test_weight_planner.py +++ b/watcher/tests/decision_engine/planner/test_weight_planner.py @@ -339,8 +339,8 @@ class TestActionScheduling(base.DbTestCase): goal=mock.Mock(), strategy=self.strategy) parameters = { - "source_node": "server1", - "destination_node": "server2", + "source_node": "server0", + "destination_node": "server1", } solution.add_action(action_type="migrate", resource_id="DOESNOTMATTER", @@ -435,8 +435,8 @@ class TestActionScheduling(base.DbTestCase): goal=mock.Mock(), strategy=self.strategy) parameters = { - "source_node": "server1", - "destination_node": "server2", + "source_node": "server0", + "destination_node": "server1", } solution.add_action(action_type="migrate", resource_id="DOESNOTMATTER", @@ -534,8 +534,8 @@ class TestActionScheduling(base.DbTestCase): goal=mock.Mock(), strategy=self.strategy) parameters = { - "source_node": "server1", - "destination_node": "server2", + "source_node": "server0", + "destination_node": "server1", } solution.add_action(action_type="migrate", resource_id="DOESNOTMATTER", @@ -639,8 +639,8 @@ class TestActionScheduling(base.DbTestCase): goal=mock.Mock(), strategy=self.strategy) parameters = { - "source_node": "server1", - "destination_node": "server2", + "source_node": "server0", + "destination_node": "server1", } solution.add_action(action_type="migrate", resource_id="DOESNOTMATTER",