From d5ba40530f964959d1e7def41b9e9caed4afa9ca Mon Sep 17 00:00:00 2001 From: Jean-Emile DARTOIS Date: Mon, 7 Dec 2015 15:52:53 +0100 Subject: [PATCH] Rename Mapper to Mapping Some Python class and packages need to be renamed for a better compliance with the shared terminology which provides a better understanding of Watcher objects and components by every contributor. This patchset is there to change mapper to mapping Partially implements: blueprint glossary-related-refactoring Change-Id: Ieaca42431322ce40d87de147ac0b46a1f446f390 --- watcher/applier/execution/executor.py | 4 +- .../applier/{mapper => mapping}/__init__.py | 0 watcher/applier/{mapper => mapping}/base.py | 0 .../applier/{mapper => mapping}/default.py | 5 +- .../applier/{mapper => mapping}/__init__.py | 0 .../{mapper => mapping}/test_action_mapper.py | 7 ++- .../mapping/test_default_action_mapper.py | 59 +++++++++++++++++++ 7 files changed, 65 insertions(+), 10 deletions(-) rename watcher/applier/{mapper => mapping}/__init__.py (100%) rename watcher/applier/{mapper => mapping}/base.py (100%) rename watcher/applier/{mapper => mapping}/default.py (97%) rename watcher/tests/applier/{mapper => mapping}/__init__.py (100%) rename watcher/tests/applier/{mapper => mapping}/test_action_mapper.py (92%) create mode 100644 watcher/tests/applier/mapping/test_default_action_mapper.py diff --git a/watcher/applier/execution/executor.py b/watcher/applier/execution/executor.py index aaf7c679d..4de26d58e 100644 --- a/watcher/applier/execution/executor.py +++ b/watcher/applier/execution/executor.py @@ -17,10 +17,8 @@ # limitations under the License. # from oslo_log import log - -from watcher.applier.mapper.default import DefaultActionMapper - from watcher.applier.execution.deploy_phase import DeployPhase +from watcher.applier.mapping.default import DefaultActionMapper from watcher.applier.messaging.events import Events from watcher.common.messaging.events.event import Event from watcher.objects import Action diff --git a/watcher/applier/mapper/__init__.py b/watcher/applier/mapping/__init__.py similarity index 100% rename from watcher/applier/mapper/__init__.py rename to watcher/applier/mapping/__init__.py diff --git a/watcher/applier/mapper/base.py b/watcher/applier/mapping/base.py similarity index 100% rename from watcher/applier/mapper/base.py rename to watcher/applier/mapping/base.py diff --git a/watcher/applier/mapper/default.py b/watcher/applier/mapping/default.py similarity index 97% rename from watcher/applier/mapper/default.py rename to watcher/applier/mapping/default.py index 0d45eb336..6747d0447 100644 --- a/watcher/applier/mapper/default.py +++ b/watcher/applier/mapping/default.py @@ -16,15 +16,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # - - -from watcher.applier.mapper.base import BaseActionMapper +from watcher.applier.mapping.base import BaseActionMapper from watcher.applier.primitives.change_nova_service_state import \ ChangeNovaServiceState from watcher.applier.primitives.migration import Migrate from watcher.applier.primitives.nop import Nop from watcher.applier.primitives.power_state import ChangePowerState - from watcher.common.exception import ActionNotFound from watcher.decision_engine.planner.default import Primitives diff --git a/watcher/tests/applier/mapper/__init__.py b/watcher/tests/applier/mapping/__init__.py similarity index 100% rename from watcher/tests/applier/mapper/__init__.py rename to watcher/tests/applier/mapping/__init__.py diff --git a/watcher/tests/applier/mapper/test_action_mapper.py b/watcher/tests/applier/mapping/test_action_mapper.py similarity index 92% rename from watcher/tests/applier/mapper/test_action_mapper.py rename to watcher/tests/applier/mapping/test_action_mapper.py index 55df4599c..4f97c2947 100644 --- a/watcher/tests/applier/mapper/test_action_mapper.py +++ b/watcher/tests/applier/mapping/test_action_mapper.py @@ -17,14 +17,15 @@ # limitations under the License. # import mock -from watcher.applier.mapper.default import DefaultActionMapper + +from watcher.applier.mapping.default import DefaultActionMapper from watcher.decision_engine.planner.default import Primitives from watcher.tests import base -class TestCommandMapper(base.TestCase): +class TestDefaultActionMapper(base.TestCase): def setUp(self): - super(TestCommandMapper, self).setUp() + super(TestDefaultActionMapper, self).setUp() self.mapper = DefaultActionMapper() def test_build_command_cold(self): diff --git a/watcher/tests/applier/mapping/test_default_action_mapper.py b/watcher/tests/applier/mapping/test_default_action_mapper.py new file mode 100644 index 000000000..4f97c2947 --- /dev/null +++ b/watcher/tests/applier/mapping/test_default_action_mapper.py @@ -0,0 +1,59 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2015 b<>com +# +# Authors: Jean-Emile DARTOIS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import mock + +from watcher.applier.mapping.default import DefaultActionMapper +from watcher.decision_engine.planner.default import Primitives +from watcher.tests import base + + +class TestDefaultActionMapper(base.TestCase): + def setUp(self): + super(TestDefaultActionMapper, self).setUp() + self.mapper = DefaultActionMapper() + + def test_build_command_cold(self): + action = mock.MagicMock() + action.action_type = Primitives.COLD_MIGRATE.value + 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_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_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_from_action(action) + self.assertIsNotNone(cmd) + + def test_build_command_exception_attribute(self): + action = mock.MagicMock + self.assertRaises(AttributeError, + self.mapper.build_primitive_from_action, + action)