diff --git a/watcher/applier/default.py b/watcher/applier/default.py index 1dde22904..f49f7ef5e 100644 --- a/watcher/applier/default.py +++ b/watcher/applier/default.py @@ -17,7 +17,7 @@ # limitations under the License. # from watcher.applier.base import Applier -from watcher.applier.execution.executor import CommandExecutor +from watcher.applier.execution.executor import ActionPlanExecutor from watcher.objects import Action from watcher.objects import ActionPlan @@ -27,7 +27,7 @@ class DefaultApplier(Applier): super(DefaultApplier, self).__init__() self.manager_applier = manager_applier self.context = context - self.executor = CommandExecutor(manager_applier, context) + self.executor = ActionPlanExecutor(manager_applier, context) def execute(self, action_plan_uuid): action_plan = ActionPlan.get_by_uuid(self.context, action_plan_uuid) diff --git a/watcher/applier/execution/deploy_phase.py b/watcher/applier/execution/deploy_phase.py index 5946fbc24..a7985d7d7 100644 --- a/watcher/applier/execution/deploy_phase.py +++ b/watcher/applier/execution/deploy_phase.py @@ -24,19 +24,31 @@ LOG = log.getLogger(__name__) class DeployPhase(object): def __init__(self, executor): # todo(jed) oslo_conf 10 secondes - self.max_timeout = 100000 - self.commands = [] - self.executor = executor + self._max_timeout = 100000 + self._actions = [] + self._executor = executor + + @property + def actions(self): + return self._actions + + @property + def max_timeout(self): + return self._max_timeout + + @max_timeout.setter + def max_timeout(self, m): + self._max_timeout = m def populate(self, action): - self.commands.append(action) + self._actions.append(action) def execute_primitive(self, primitive): future = primitive.execute(primitive) return future.result(self.max_timeout) def rollback(self): - reverted = sorted(self.commands, reverse=True) + reverted = sorted(self.actions, reverse=True) for primitive in reverted: try: self.execute_primitive(primitive) diff --git a/watcher/applier/execution/executor.py b/watcher/applier/execution/executor.py index ff0650b16..aaf7c679d 100644 --- a/watcher/applier/execution/executor.py +++ b/watcher/applier/execution/executor.py @@ -18,7 +18,7 @@ # from oslo_log import log -from watcher.applier.mapper.default import DefaultCommandMapper +from watcher.applier.mapper.default import DefaultActionMapper from watcher.applier.execution.deploy_phase import DeployPhase from watcher.applier.messaging.events import Events @@ -29,15 +29,15 @@ from watcher.objects.action_plan import Status LOG = log.getLogger(__name__) -class CommandExecutor(object): +class ActionPlanExecutor(object): def __init__(self, manager_applier, context): self.manager_applier = manager_applier self.context = context self.deploy = DeployPhase(self) - self.mapper = DefaultCommandMapper() + self.mapper = DefaultActionMapper() def get_primitive(self, action): - return self.mapper.build_primitive_command(action) + return self.mapper.build_primitive_from_action(action) def notify(self, action, state): db_action = Action.get_by_uuid(self.context, action.uuid) diff --git a/watcher/applier/mapper/base.py b/watcher/applier/mapper/base.py index 4b6a21bb3..4019c8f81 100644 --- a/watcher/applier/mapper/base.py +++ b/watcher/applier/mapper/base.py @@ -22,8 +22,13 @@ import six @six.add_metaclass(abc.ABCMeta) -class CommandMapper(object): +class BaseActionMapper(object): @abc.abstractmethod - def build_primitive_command(self, action): + def build_primitive_from_action(self, action): + """Transform an action to a primitive + + :type action: watcher.decision_engine.action.BaseAction + :return: the associated Primitive + """ raise NotImplementedError( "Should have implemented this") # pragma:no cover diff --git a/watcher/applier/mapper/default.py b/watcher/applier/mapper/default.py index f70bf17b5..1dac0dbf1 100644 --- a/watcher/applier/mapper/default.py +++ b/watcher/applier/mapper/default.py @@ -18,7 +18,7 @@ # -from watcher.applier.mapper.base import CommandMapper +from watcher.applier.mapper.base import BaseActionMapper from watcher.applier.primitive.hypervisor_state import HypervisorStateCommand from watcher.applier.primitive.migration import MigrateCommand from watcher.applier.primitive.nop import NopCommand @@ -27,8 +27,8 @@ from watcher.common.exception import ActionNotFound from watcher.decision_engine.planner.default import Primitives -class DefaultCommandMapper(CommandMapper): - def build_primitive_command(self, action): +class DefaultActionMapper(BaseActionMapper): + def build_primitive_from_action(self, action): if action.action_type == Primitives.COLD_MIGRATE.value: return MigrateCommand(action.applies_to, Primitives.COLD_MIGRATE, action.src, diff --git a/watcher/tests/applier/execution/test_command_executor.py b/watcher/tests/applier/execution/test_action_plan_executor.py similarity index 93% rename from watcher/tests/applier/execution/test_command_executor.py rename to watcher/tests/applier/execution/test_action_plan_executor.py index 162c87cb4..b503dd7ce 100644 --- a/watcher/tests/applier/execution/test_command_executor.py +++ b/watcher/tests/applier/execution/test_action_plan_executor.py @@ -18,7 +18,7 @@ # import mock -from watcher.applier.execution.executor import CommandExecutor +from watcher.applier.execution.executor import ActionPlanExecutor from watcher import objects from watcher.common import utils @@ -32,7 +32,7 @@ class TestCommandExecutor(DbTestCase): def setUp(self): super(TestCommandExecutor, self).setUp() self.applier = mock.MagicMock() - self.executor = CommandExecutor(self.applier, self.context) + self.executor = ActionPlanExecutor(self.applier, self.context) def test_execute(self): actions = mock.MagicMock() diff --git a/watcher/tests/applier/mapper/test_command_mapper.py b/watcher/tests/applier/mapper/test_action_mapper.py similarity index 78% rename from watcher/tests/applier/mapper/test_command_mapper.py rename to watcher/tests/applier/mapper/test_action_mapper.py index 8d3e9f328..55df4599c 100644 --- a/watcher/tests/applier/mapper/test_command_mapper.py +++ b/watcher/tests/applier/mapper/test_action_mapper.py @@ -17,7 +17,7 @@ # limitations under the License. # import mock -from watcher.applier.mapper.default import DefaultCommandMapper +from watcher.applier.mapper.default import DefaultActionMapper from watcher.decision_engine.planner.default import Primitives from watcher.tests import base @@ -25,33 +25,34 @@ from watcher.tests import base class TestCommandMapper(base.TestCase): def setUp(self): super(TestCommandMapper, self).setUp() - self.mapper = DefaultCommandMapper() + self.mapper = DefaultActionMapper() def test_build_command_cold(self): action = mock.MagicMock() action.action_type = Primitives.COLD_MIGRATE.value - cmd = self.mapper.build_primitive_command(action) + cmd = self.mapper.build_primitive_from_action(action) self.assertIsNotNone(cmd) def test_build_command_live(self): action = mock.MagicMock() action.action_type = Primitives.LIVE_MIGRATE.value - cmd = self.mapper.build_primitive_command(action) + cmd = self.mapper.build_primitive_from_action(action) self.assertIsNotNone(cmd) def test_build_command_h_s(self): action = mock.MagicMock() action.action_type = Primitives.HYPERVISOR_STATE.value - cmd = self.mapper.build_primitive_command(action) + cmd = self.mapper.build_primitive_from_action(action) self.assertIsNotNone(cmd) def test_build_command_p_s(self): action = mock.MagicMock() action.action_type = Primitives.POWER_STATE.value - cmd = self.mapper.build_primitive_command(action) + cmd = self.mapper.build_primitive_from_action(action) self.assertIsNotNone(cmd) def test_build_command_exception_attribute(self): action = mock.MagicMock - self.assertRaises(AttributeError, self.mapper.build_primitive_command, + self.assertRaises(AttributeError, + self.mapper.build_primitive_from_action, action)