From 35a1f0a657d20f2ed60913745412ec2524baa65e Mon Sep 17 00:00:00 2001 From: Jean-Emile DARTOIS Date: Mon, 7 Dec 2015 17:46:52 +0100 Subject: [PATCH] Tidy up - Rename Base 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 add missing Base in class name Partially implements: blueprint glossary-related-refactoring Change-Id: I95a3e41fbd5fcd90a99d81c9cf278940f50c7732 --- watcher/applier/base.py | 2 +- watcher/applier/default.py | 5 +++-- watcher/applier/mapping/default.py | 1 + .../primitives/change_nova_service_state.py | 1 + watcher/applier/primitives/migration.py | 1 + watcher/applier/primitives/nop.py | 1 + watcher/applier/primitives/power_state.py | 1 + watcher/db/api.py | 11 +++-------- watcher/db/sqlalchemy/api.py | 2 +- .../decision_engine/actions/hypervisor_state.py | 1 + watcher/decision_engine/actions/nop.py | 1 + watcher/decision_engine/actions/power_state.py | 5 +++-- watcher/decision_engine/planner/base.py | 2 +- watcher/decision_engine/planner/default.py | 4 ++-- watcher/decision_engine/solution/base.py | 2 +- watcher/decision_engine/solution/default.py | 4 ++-- .../solution/solution_comparator.py | 2 +- .../decision_engine/solution/solution_evaluator.py | 2 +- watcher/decision_engine/strategy/base.py | 2 +- watcher/decision_engine/strategy/selector/base.py | 2 +- .../decision_engine/strategy/selector/default.py | 4 ++-- watcher/tests/api/v1/test_actions.py | 4 ++-- watcher/tests/api/v1/test_actions_plans.py | 4 ++-- watcher/tests/api/v1/test_audit_templates.py | 6 +++--- watcher/tests/api/v1/test_audits.py | 6 +++--- .../tests/decision_engine/test_default_planner.py | 14 +++++--------- 26 files changed, 45 insertions(+), 45 deletions(-) diff --git a/watcher/applier/base.py b/watcher/applier/base.py index 34d2a6270..197cc3f05 100644 --- a/watcher/applier/base.py +++ b/watcher/applier/base.py @@ -22,7 +22,7 @@ import six @six.add_metaclass(abc.ABCMeta) -class Applier(object): +class BaseApplier(object): @abc.abstractmethod def execute(self, action_plan_uuid): raise NotImplementedError( diff --git a/watcher/applier/default.py b/watcher/applier/default.py index f49f7ef5e..0cbd7cb7b 100644 --- a/watcher/applier/default.py +++ b/watcher/applier/default.py @@ -16,13 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from watcher.applier.base import Applier + +from watcher.applier.base import BaseApplier from watcher.applier.execution.executor import ActionPlanExecutor from watcher.objects import Action from watcher.objects import ActionPlan -class DefaultApplier(Applier): +class DefaultApplier(BaseApplier): def __init__(self, manager_applier, context): super(DefaultApplier, self).__init__() self.manager_applier = manager_applier diff --git a/watcher/applier/mapping/default.py b/watcher/applier/mapping/default.py index 6747d0447..65bd7b259 100644 --- a/watcher/applier/mapping/default.py +++ b/watcher/applier/mapping/default.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from watcher.applier.mapping.base import BaseActionMapper from watcher.applier.primitives.change_nova_service_state import \ ChangeNovaServiceState diff --git a/watcher/applier/primitives/change_nova_service_state.py b/watcher/applier/primitives/change_nova_service_state.py index eff149032..61d7f65f6 100644 --- a/watcher/applier/primitives/change_nova_service_state.py +++ b/watcher/applier/primitives/change_nova_service_state.py @@ -20,6 +20,7 @@ from oslo_config import cfg + from watcher.applier.primitives.base import BasePrimitive from watcher.applier.primitives.wrapper.nova_wrapper import NovaWrapper from watcher.applier.promise import Promise diff --git a/watcher/applier/primitives/migration.py b/watcher/applier/primitives/migration.py index 461460185..12058956a 100644 --- a/watcher/applier/primitives/migration.py +++ b/watcher/applier/primitives/migration.py @@ -21,6 +21,7 @@ from keystoneclient.auth.identity import v3 from keystoneclient import session from oslo_config import cfg + from watcher.applier.primitives.base import BasePrimitive from watcher.applier.primitives.wrapper.nova_wrapper import NovaWrapper from watcher.applier.promise import Promise diff --git a/watcher/applier/primitives/nop.py b/watcher/applier/primitives/nop.py index 78ef60200..000dd2d3a 100644 --- a/watcher/applier/primitives/nop.py +++ b/watcher/applier/primitives/nop.py @@ -19,6 +19,7 @@ from oslo_log import log + from watcher.applier.primitives.base import BasePrimitive from watcher.applier.promise import Promise diff --git a/watcher/applier/primitives/power_state.py b/watcher/applier/primitives/power_state.py index 37cfd3aa1..178a7c941 100644 --- a/watcher/applier/primitives/power_state.py +++ b/watcher/applier/primitives/power_state.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from watcher.applier.primitives.base import BasePrimitive from watcher.applier.promise import Promise diff --git a/watcher/db/api.py b/watcher/db/api.py index 87688e929..356495675 100644 --- a/watcher/db/api.py +++ b/watcher/db/api.py @@ -16,12 +16,10 @@ Base classes for storage engines """ import abc - from oslo_config import cfg from oslo_db import api as db_api import six - _BACKEND_MAPPING = {'sqlalchemy': 'watcher.db.sqlalchemy.api'} IMPL = db_api.DBAPI.from_config(cfg.CONF, backend_mapping=_BACKEND_MAPPING, lazy=True) @@ -33,13 +31,9 @@ def get_instance(): @six.add_metaclass(abc.ABCMeta) -class Connection(object): +class BaseConnection(object): """Base class for storage system connections.""" - @abc.abstractmethod - def __init__(self): - """Constructor.""" - @abc.abstractmethod def get_audit_template_list(self, context, columns=None, filters=None, limit=None, marker=None, sort_key=None, @@ -130,6 +124,7 @@ class Connection(object): :raises: AuditTemplateNotFound :raises: InvalidParameterValue """ + @abc.abstractmethod def soft_delete_audit_template(self, audit_template_id): """Soft delete an audit_template. @@ -308,7 +303,7 @@ class Connection(object): @abc.abstractmethod def get_action_plan_list( - self, context, columns=None, filters=None, limit=None, + self, context, columns=None, filters=None, limit=None, marker=None, sort_key=None, sort_dir=None): """Get specific columns for matching action plans. diff --git a/watcher/db/sqlalchemy/api.py b/watcher/db/sqlalchemy/api.py index 7135fa312..546a74872 100644 --- a/watcher/db/sqlalchemy/api.py +++ b/watcher/db/sqlalchemy/api.py @@ -102,7 +102,7 @@ def _paginate_query(model, limit=None, marker=None, sort_key=None, return query.all() -class Connection(api.Connection): +class Connection(api.BaseConnection): """SqlAlchemy connection.""" def __init__(self): diff --git a/watcher/decision_engine/actions/hypervisor_state.py b/watcher/decision_engine/actions/hypervisor_state.py index da62a637b..3cc957d98 100644 --- a/watcher/decision_engine/actions/hypervisor_state.py +++ b/watcher/decision_engine/actions/hypervisor_state.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from watcher.decision_engine.actions.base import BaseAction from watcher.decision_engine.model.hypervisor_state import HypervisorState diff --git a/watcher/decision_engine/actions/nop.py b/watcher/decision_engine/actions/nop.py index 8a2881262..6a1fdc8d6 100644 --- a/watcher/decision_engine/actions/nop.py +++ b/watcher/decision_engine/actions/nop.py @@ -17,6 +17,7 @@ # limitations under the License. # + from watcher.decision_engine.actions.base import BaseAction diff --git a/watcher/decision_engine/actions/power_state.py b/watcher/decision_engine/actions/power_state.py index 29348667e..4ce1a1d3f 100644 --- a/watcher/decision_engine/actions/power_state.py +++ b/watcher/decision_engine/actions/power_state.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from watcher.decision_engine.actions.base import BaseAction from watcher.decision_engine.model.power_state import PowerState @@ -47,5 +48,5 @@ class ChangePowerState(BaseAction): self._target = t def __str__(self): - return "ChangePowerState {} => {} ".format( - self.target, self.powerstate) + return "ChangePowerState {} => {} ".format(self.target, + self.powerstate) diff --git a/watcher/decision_engine/planner/base.py b/watcher/decision_engine/planner/base.py index ac001d9dd..88e8b4d48 100644 --- a/watcher/decision_engine/planner/base.py +++ b/watcher/decision_engine/planner/base.py @@ -21,7 +21,7 @@ import six @six.add_metaclass(abc.ABCMeta) -class Planner(object): +class BasePlanner(object): @abc.abstractmethod def schedule(self, context, audit_uuid, solution): """The planner receives a solution to schedule diff --git a/watcher/decision_engine/planner/default.py b/watcher/decision_engine/planner/default.py index 760417fdd..3c7b043ee 100644 --- a/watcher/decision_engine/planner/default.py +++ b/watcher/decision_engine/planner/default.py @@ -21,7 +21,7 @@ from oslo_log import log from enum import Enum from watcher.common.exception import MetaActionNotFound from watcher.common import utils -from watcher.decision_engine.planner.base import Planner +from watcher.decision_engine.planner.base import BasePlanner from watcher import objects @@ -57,7 +57,7 @@ priority_primitives = { } -class DefaultPlanner(Planner): +class DefaultPlanner(BasePlanner): def create_action(self, action_plan_id, action_type, applies_to=None, src=None, dst=None, diff --git a/watcher/decision_engine/solution/base.py b/watcher/decision_engine/solution/base.py index 6ef15be86..2716e7966 100644 --- a/watcher/decision_engine/solution/base.py +++ b/watcher/decision_engine/solution/base.py @@ -21,7 +21,7 @@ import six @six.add_metaclass(abc.ABCMeta) -class Solution(object): +class BaseSolution(object): def __init__(self): self._origin = None self._model = None diff --git a/watcher/decision_engine/solution/default.py b/watcher/decision_engine/solution/default.py index bde4daf4d..863bd7cf7 100644 --- a/watcher/decision_engine/solution/default.py +++ b/watcher/decision_engine/solution/default.py @@ -17,12 +17,12 @@ # limitations under the License. # from oslo_log import log -from watcher.decision_engine.solution.base import Solution +from watcher.decision_engine.solution.base import BaseSolution LOG = log.getLogger(__name__) -class DefaultSolution(Solution): +class DefaultSolution(BaseSolution): def __init__(self): """The DefaultSolution class store a set of actions generated by a strategy in order to achieve the goal. diff --git a/watcher/decision_engine/solution/solution_comparator.py b/watcher/decision_engine/solution/solution_comparator.py index b6a0e2224..fa88f1853 100644 --- a/watcher/decision_engine/solution/solution_comparator.py +++ b/watcher/decision_engine/solution/solution_comparator.py @@ -21,7 +21,7 @@ import six @six.add_metaclass(abc.ABCMeta) -class Solution(object): +class BaseSolutionComparator(object): @abc.abstractmethod def compare(self, sol1, sol2): raise NotImplementedError( diff --git a/watcher/decision_engine/solution/solution_evaluator.py b/watcher/decision_engine/solution/solution_evaluator.py index 5ec711ffb..6ebcce751 100644 --- a/watcher/decision_engine/solution/solution_evaluator.py +++ b/watcher/decision_engine/solution/solution_evaluator.py @@ -21,7 +21,7 @@ import six @six.add_metaclass(abc.ABCMeta) -class SolutionEvaluator(object): +class BaseSolutionEvaluator(object): @abc.abstractmethod def evaluate(self, solution): raise NotImplementedError( diff --git a/watcher/decision_engine/strategy/base.py b/watcher/decision_engine/strategy/base.py index 37e881aeb..f31185d56 100644 --- a/watcher/decision_engine/strategy/base.py +++ b/watcher/decision_engine/strategy/base.py @@ -47,7 +47,7 @@ class BaseStrategy(object): :param model: The name of the strategy to execute (loaded dynamically) :type model: str :return: A computed solution (via a placement algorithm) - :rtype: :class:`watcher.decision_engine.solution.base.Solution` + :rtype: :class:`watcher.decision_engine.solution.base.BaseSolution` """ @property diff --git a/watcher/decision_engine/strategy/selector/base.py b/watcher/decision_engine/strategy/selector/base.py index e76fba174..6d59499c1 100644 --- a/watcher/decision_engine/strategy/selector/base.py +++ b/watcher/decision_engine/strategy/selector/base.py @@ -21,7 +21,7 @@ import six @six.add_metaclass(abc.ABCMeta) -class Selector(object): +class BaseSelector(object): @abc.abstractmethod def define_from_goal(self, goal_name): raise NotImplementedError( diff --git a/watcher/decision_engine/strategy/selector/default.py b/watcher/decision_engine/strategy/selector/default.py index 053e1bcd5..46e86d9f0 100644 --- a/watcher/decision_engine/strategy/selector/default.py +++ b/watcher/decision_engine/strategy/selector/default.py @@ -18,7 +18,7 @@ from oslo_config import cfg from oslo_log import log from watcher.common.exception import WatcherException from watcher.decision_engine.strategy.loader import StrategyLoader -from watcher.decision_engine.strategy.selector.base import Selector +from watcher.decision_engine.strategy.selector.base import BaseSelector LOG = log.getLogger(__name__) CONF = cfg.CONF @@ -38,7 +38,7 @@ CONF.register_group(goals_opt_group) CONF.register_opts(WATCHER_GOALS_OPTS, goals_opt_group) -class StrategySelector(Selector): +class StrategySelector(BaseSelector): def __init__(self): self.strategy_loader = StrategyLoader() diff --git a/watcher/tests/api/v1/test_actions.py b/watcher/tests/api/v1/test_actions.py index cd08c0657..42f5d0f01 100644 --- a/watcher/tests/api/v1/test_actions.py +++ b/watcher/tests/api/v1/test_actions.py @@ -426,7 +426,7 @@ class TestPatch(api_base.FunctionalTest): super(TestPatch, self).setUp() obj_utils.create_test_action_plan(self.context) self.action = obj_utils.create_test_action(self.context, next=None) - p = mock.patch.object(db_api.Connection, 'update_action') + p = mock.patch.object(db_api.BaseConnection, 'update_action') self.mock_action_update = p.start() self.mock_action_update.side_effect = self._simulate_rpc_action_update self.addCleanup(p.stop) @@ -552,7 +552,7 @@ class TestDelete(api_base.FunctionalTest): super(TestDelete, self).setUp() obj_utils.create_test_action_plan(self.context) self.action = obj_utils.create_test_action(self.context, next=None) - p = mock.patch.object(db_api.Connection, 'update_action') + p = mock.patch.object(db_api.BaseConnection, 'update_action') self.mock_action_update = p.start() self.mock_action_update.side_effect = self._simulate_rpc_action_update self.addCleanup(p.stop) diff --git a/watcher/tests/api/v1/test_actions_plans.py b/watcher/tests/api/v1/test_actions_plans.py index ae1b876e1..e52fadf1f 100644 --- a/watcher/tests/api/v1/test_actions_plans.py +++ b/watcher/tests/api/v1/test_actions_plans.py @@ -285,7 +285,7 @@ class TestDelete(api_base.FunctionalTest): super(TestDelete, self).setUp() self.action_plan = obj_utils.create_action_plan_without_audit( self.context) - p = mock.patch.object(db_api.Connection, 'destroy_action_plan') + p = mock.patch.object(db_api.BaseConnection, 'destroy_action_plan') self.mock_action_plan_delete = p.start() self.mock_action_plan_delete.side_effect = \ self._simulate_rpc_action_plan_delete @@ -317,7 +317,7 @@ class TestPatch(api_base.FunctionalTest): super(TestPatch, self).setUp() self.action_plan = obj_utils.create_action_plan_without_audit( self.context) - p = mock.patch.object(db_api.Connection, 'update_action_plan') + p = mock.patch.object(db_api.BaseConnection, 'update_action_plan') self.mock_action_plan_update = p.start() self.mock_action_plan_update.side_effect = \ self._simulate_rpc_action_plan_update diff --git a/watcher/tests/api/v1/test_audit_templates.py b/watcher/tests/api/v1/test_audit_templates.py index 10296aabd..a8b47d3e3 100644 --- a/watcher/tests/api/v1/test_audit_templates.py +++ b/watcher/tests/api/v1/test_audit_templates.py @@ -213,7 +213,7 @@ class TestPatch(api_base.FunctionalTest): super(TestPatch, self).setUp() self.audit_template = obj_utils.create_test_audit_template( self.context) - p = mock.patch.object(db_api.Connection, 'update_audit_template') + p = mock.patch.object(db_api.BaseConnection, 'update_audit_template') self.mock_audit_template_update = p.start() self.mock_audit_template_update.side_effect = \ self._simulate_rpc_audit_template_update @@ -340,7 +340,7 @@ class TestPost(api_base.FunctionalTest): def setUp(self): super(TestPost, self).setUp() - p = mock.patch.object(db_api.Connection, 'create_audit_template') + p = mock.patch.object(db_api.BaseConnection, 'create_audit_template') self.mock_create_audit_template = p.start() self.mock_create_audit_template.side_effect = ( self._simulate_rpc_audit_template_create) @@ -417,7 +417,7 @@ class TestDelete(api_base.FunctionalTest): super(TestDelete, self).setUp() self.audit_template = obj_utils.create_test_audit_template( self.context) - p = mock.patch.object(db_api.Connection, 'update_audit_template') + p = mock.patch.object(db_api.BaseConnection, 'update_audit_template') self.mock_audit_template_update = p.start() self.mock_audit_template_update.side_effect = \ self._simulate_rpc_audit_template_update diff --git a/watcher/tests/api/v1/test_audits.py b/watcher/tests/api/v1/test_audits.py index 4ac3c05a0..f20f9d84f 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -319,7 +319,7 @@ class TestPatch(api_base.FunctionalTest): super(TestPatch, self).setUp() obj_utils.create_test_audit_template(self.context) self.audit = obj_utils.create_test_audit(self.context) - p = mock.patch.object(db_api.Connection, 'update_audit') + p = mock.patch.object(db_api.BaseConnection, 'update_audit') self.mock_audit_update = p.start() self.mock_audit_update.side_effect = self._simulate_rpc_audit_update self.addCleanup(p.stop) @@ -414,7 +414,7 @@ class TestPost(api_base.FunctionalTest): def setUp(self): super(TestPost, self).setUp() obj_utils.create_test_audit_template(self.context) - p = mock.patch.object(db_api.Connection, 'create_audit') + p = mock.patch.object(db_api.BaseConnection, 'create_audit') self.mock_create_audit = p.start() self.mock_create_audit.side_effect = ( self._simulate_rpc_audit_create) @@ -520,7 +520,7 @@ class TestDelete(api_base.FunctionalTest): super(TestDelete, self).setUp() obj_utils.create_test_audit_template(self.context) self.audit = obj_utils.create_test_audit(self.context) - p = mock.patch.object(db_api.Connection, 'update_audit') + p = mock.patch.object(db_api.BaseConnection, 'update_audit') self.mock_audit_update = p.start() self.mock_audit_update.side_effect = self._simulate_rpc_audit_update self.addCleanup(p.stop) diff --git a/watcher/tests/decision_engine/test_default_planner.py b/watcher/tests/decision_engine/test_default_planner.py index a14785cd7..0f018040c 100644 --- a/watcher/tests/decision_engine/test_default_planner.py +++ b/watcher/tests/decision_engine/test_default_planner.py @@ -24,7 +24,6 @@ from watcher.decision_engine.planner.default import DefaultPlanner from watcher.decision_engine.solution.default import DefaultSolution from watcher.decision_engine.strategy.basic_consolidation import \ BasicConsolidation - from watcher.tests.db import base from watcher.tests.db import utils as db_utils from watcher.tests.decision_engine.faker_cluster_state import \ @@ -59,11 +58,9 @@ class SolutionFakerSingleHyp(object): class TestActionScheduling(base.DbTestCase): - scenarios = [ (str(action_cls), {"fake_action": mock.Mock(spec=action_cls)}) - for action_cls in BaseAction.__subclasses__() - ] + for action_cls in BaseAction.__subclasses__()] def test_schedule_actions(self): default_planner = DefaultPlanner() @@ -72,8 +69,8 @@ class TestActionScheduling(base.DbTestCase): dummy_solution.add_change_request(self.fake_action) with mock.patch.object( - DefaultPlanner, "create_action", - wraps=default_planner.create_action) as m_create_action: + DefaultPlanner, "create_action", + wraps=default_planner.create_action) as m_create_action: action_plan = default_planner.schedule( self.context, audit.id, dummy_solution ) @@ -83,19 +80,18 @@ class TestActionScheduling(base.DbTestCase): class TestDefaultPlanner(base.DbTestCase): - def setUp(self): super(TestDefaultPlanner, self).setUp() self.default_planner = DefaultPlanner() obj_utils.create_test_audit_template(self.context) - p = mock.patch.object(db_api.Connection, 'create_action_plan') + p = mock.patch.object(db_api.BaseConnection, 'create_action_plan') self.mock_create_action_plan = p.start() self.mock_create_action_plan.side_effect = ( self._simulate_action_plan_create) self.addCleanup(p.stop) - q = mock.patch.object(db_api.Connection, 'create_action') + q = mock.patch.object(db_api.BaseConnection, 'create_action') self.mock_create_action = q.start() self.mock_create_action.side_effect = ( self._simulate_action_create)