Rename (pre/post)condition to (pre/post)_condition

This patch updates the applier's abstract methods to be consistent
with other abstract methods of similar nature.

Also included are a few other miscellaneous changes.

Change-Id: Ia1527c00332011412aba2ab326ec986f1e773001
Closes-bug: 1606634
This commit is contained in:
Joe Cropper
2016-08-06 16:21:30 -05:00
parent 27b3c5254d
commit ea01031268
11 changed files with 65 additions and 65 deletions

View File

@@ -15,8 +15,6 @@
# implied. # implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
#
import abc import abc
@@ -28,7 +26,7 @@ from watcher.common.loader import loadable
@six.add_metaclass(abc.ABCMeta) @six.add_metaclass(abc.ABCMeta)
class BaseAction(loadable.Loadable): class BaseAction(loadable.Loadable):
# NOTE(jed) by convention we decided # NOTE(jed): by convention we decided
# that the attribute "resource_id" is the unique id of # that the attribute "resource_id" is the unique id of
# the resource to which the Action applies to allow us to use it in the # the resource to which the Action applies to allow us to use it in the
# watcher dashboard and will be nested in input_parameters # watcher dashboard and will be nested in input_parameters
@@ -99,7 +97,7 @@ class BaseAction(loadable.Loadable):
raise NotImplementedError() raise NotImplementedError()
@abc.abstractmethod @abc.abstractmethod
def precondition(self): def pre_condition(self):
"""Hook: called before the execution of an action """Hook: called before the execution of an action
This method can be used to perform some initializations or to make This method can be used to perform some initializations or to make
@@ -110,7 +108,7 @@ class BaseAction(loadable.Loadable):
raise NotImplementedError() raise NotImplementedError()
@abc.abstractmethod @abc.abstractmethod
def postcondition(self): def post_condition(self):
"""Hook: called after the execution of an action """Hook: called after the execution of an action
This function is called regardless of whether an action succeded or This function is called regardless of whether an action succeded or

View File

@@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import six import six
import voluptuous import voluptuous
@@ -95,8 +96,8 @@ class ChangeNovaServiceState(base.BaseAction):
else: else:
return nova.disable_service_nova_compute(self.host) return nova.disable_service_nova_compute(self.host)
def precondition(self): def pre_condition(self):
pass pass
def postcondition(self): def post_condition(self):
pass pass

View File

@@ -66,8 +66,8 @@ class Migrate(base.BaseAction):
if (value is not None and if (value is not None and
len(value) > 0 and not len(value) > 0 and not
utils.is_uuid_like(value)): utils.is_uuid_like(value)):
raise voluptuous.Invalid(_("The parameter" raise voluptuous.Invalid(_("The parameter "
" resource_id is invalid.")) "resource_id is invalid."))
@property @property
def schema(self): def schema(self):
@@ -116,11 +116,11 @@ class Migrate(base.BaseAction):
dest_hostname=destination, dest_hostname=destination,
block_migration=True) block_migration=True)
else: else:
LOG.debug("Nova client exception occured while live migrating " LOG.debug("Nova client exception occurred while live "
"instance %s.Exception: %s" % "migrating instance %s.Exception: %s" %
(self.instance_uuid, e)) (self.instance_uuid, e))
except Exception: except Exception:
LOG.critical(_LC("Unexpected error occured. Migration failed for" LOG.critical(_LC("Unexpected error occurred. Migration failed for "
"instance %s. Leaving instance on previous " "instance %s. Leaving instance on previous "
"host."), self.instance_uuid) "host."), self.instance_uuid)
@@ -134,7 +134,7 @@ class Migrate(base.BaseAction):
dest_hostname=destination) dest_hostname=destination)
except Exception as exc: except Exception as exc:
LOG.exception(exc) LOG.exception(exc)
LOG.critical(_LC("Unexpected error occured. Migration failed for" LOG.critical(_LC("Unexpected error occurred. Migration failed for "
"instance %s. Leaving instance on previous " "instance %s. Leaving instance on previous "
"host."), self.instance_uuid) "host."), self.instance_uuid)
@@ -152,8 +152,8 @@ class Migrate(base.BaseAction):
return self._cold_migrate_instance(nova, destination) return self._cold_migrate_instance(nova, destination)
else: else:
raise exception.Invalid( raise exception.Invalid(
message=(_('Migration of type %(migration_type)s is not ' message=(_("Migration of type '%(migration_type)s' is not "
'supported.') % "supported.") %
{'migration_type': self.migration_type})) {'migration_type': self.migration_type}))
else: else:
raise exception.InstanceNotFound(name=self.instance_uuid) raise exception.InstanceNotFound(name=self.instance_uuid)
@@ -164,11 +164,11 @@ class Migrate(base.BaseAction):
def revert(self): def revert(self):
return self.migrate(destination=self.source_node) return self.migrate(destination=self.source_node)
def precondition(self): def pre_condition(self):
# todo(jed) check if the instance exist/ check if the instance is on # TODO(jed): check if the instance exists / check if the instance is on
# the source_node # the source_node
pass pass
def postcondition(self): def post_condition(self):
# todo(jed) we can image to check extra parameters (nework reponse,ect) # TODO(jed): check extra parameters (network response, etc.)
pass pass

View File

@@ -53,15 +53,15 @@ class Nop(base.BaseAction):
return self.input_parameters.get(self.MESSAGE) return self.input_parameters.get(self.MESSAGE)
def execute(self): def execute(self):
LOG.debug("executing action NOP message:%s ", self.message) LOG.debug("Executing action NOP message: %s ", self.message)
return True return True
def revert(self): def revert(self):
LOG.debug("revert action NOP") LOG.debug("Revert action NOP")
return True return True
def precondition(self): def pre_condition(self):
pass pass
def postcondition(self): def post_condition(self):
pass pass

View File

@@ -16,8 +16,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import time
import time
from oslo_log import log from oslo_log import log
import voluptuous import voluptuous
@@ -53,16 +53,16 @@ class Sleep(base.BaseAction):
return int(self.input_parameters.get(self.DURATION)) return int(self.input_parameters.get(self.DURATION))
def execute(self): def execute(self):
LOG.debug("Starting action Sleep duration:%s ", self.duration) LOG.debug("Starting action sleep with duration: %s ", self.duration)
time.sleep(self.duration) time.sleep(self.duration)
return True return True
def revert(self): def revert(self):
LOG.debug("revert action Sleep") LOG.debug("Revert action sleep")
return True return True
def precondition(self): def pre_condition(self):
pass pass
def postcondition(self): def post_condition(self):
pass pass

View File

@@ -109,8 +109,8 @@ class TaskFlowActionContainer(task.Task):
try: try:
self.engine.notify(self._db_action, self.engine.notify(self._db_action,
obj_action.State.ONGOING) obj_action.State.ONGOING)
LOG.debug("Precondition action %s", self.name) LOG.debug("Pre-condition action: %s", self.name)
self.action.precondition() self.action.pre_condition()
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)
self.engine.notify(self._db_action, self.engine.notify(self._db_action,
@@ -119,15 +119,15 @@ class TaskFlowActionContainer(task.Task):
def execute(self, *args, **kwargs): def execute(self, *args, **kwargs):
try: try:
LOG.debug("Running action %s", self.name) LOG.debug("Running action: %s", self.name)
self.action.execute() self.action.execute()
self.engine.notify(self._db_action, self.engine.notify(self._db_action,
obj_action.State.SUCCEEDED) obj_action.State.SUCCEEDED)
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)
LOG.error(_LE('The WorkFlow Engine has failed ' LOG.error(_LE('The workflow engine has failed '
'to execute the action %s'), self.name) 'to execute the action: %s'), self.name)
self.engine.notify(self._db_action, self.engine.notify(self._db_action,
obj_action.State.FAILED) obj_action.State.FAILED)
@@ -135,8 +135,8 @@ class TaskFlowActionContainer(task.Task):
def post_execute(self): def post_execute(self):
try: try:
LOG.debug("postcondition action %s", self.name) LOG.debug("Post-condition action: %s", self.name)
self.action.postcondition() self.action.post_condition()
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)
self.engine.notify(self._db_action, self.engine.notify(self._db_action,
@@ -144,19 +144,19 @@ class TaskFlowActionContainer(task.Task):
raise raise
def revert(self, *args, **kwargs): def revert(self, *args, **kwargs):
LOG.warning(_LW("Revert action %s"), self.name) LOG.warning(_LW("Revert action: %s"), self.name)
try: try:
# todo(jed) do we need to update the states in case of failure ? # TODO(jed): do we need to update the states in case of failure?
self.action.revert() self.action.revert()
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)
LOG.critical(_LC("Oops! We need disaster recover plan")) LOG.critical(_LC("Oops! We need a disaster recover plan."))
class TaskFlowNop(task.Task): class TaskFlowNop(task.Task):
"""This class is use in case of the workflow have only one Action. """This class is used in case of the workflow have only one Action.
We need at least two atoms to create a link We need at least two atoms to create a link.
""" """
def execute(self): def execute(self):
pass pass

View File

@@ -72,7 +72,7 @@ class Unclassified(base.Goal):
class ServerConsolidation(base.Goal): class ServerConsolidation(base.Goal):
"""Server Consolidation """ServerConsolidation
This goal is for efficient usage of compute server resources in order to This goal is for efficient usage of compute server resources in order to
reduce the total number of servers. reduce the total number of servers.
@@ -84,11 +84,11 @@ class ServerConsolidation(base.Goal):
@classmethod @classmethod
def get_display_name(cls): def get_display_name(cls):
return _("Server consolidation") return _("Server Consolidation")
@classmethod @classmethod
def get_translatable_display_name(cls): def get_translatable_display_name(cls):
return "Server consolidation" return "Server Consolidation"
@classmethod @classmethod
def get_efficacy_specification(cls): def get_efficacy_specification(cls):
@@ -97,7 +97,7 @@ class ServerConsolidation(base.Goal):
class ThermalOptimization(base.Goal): class ThermalOptimization(base.Goal):
"""Thermal Optimization """ThermalOptimization
This goal is used to balance the temperature across different servers. This goal is used to balance the temperature across different servers.
""" """
@@ -108,11 +108,11 @@ class ThermalOptimization(base.Goal):
@classmethod @classmethod
def get_display_name(cls): def get_display_name(cls):
return _("Thermal optimization") return _("Thermal Optimization")
@classmethod @classmethod
def get_translatable_display_name(cls): def get_translatable_display_name(cls):
return "Thermal optimization" return "Thermal Optimization"
@classmethod @classmethod
def get_efficacy_specification(cls): def get_efficacy_specification(cls):
@@ -121,7 +121,7 @@ class ThermalOptimization(base.Goal):
class WorkloadBalancing(base.Goal): class WorkloadBalancing(base.Goal):
"""Workload Balancing """WorkloadBalancing
This goal is used to evenly distribute workloads across different servers. This goal is used to evenly distribute workloads across different servers.
""" """
@@ -132,11 +132,11 @@ class WorkloadBalancing(base.Goal):
@classmethod @classmethod
def get_display_name(cls): def get_display_name(cls):
return _("Workload balancing") return _("Workload Balancing")
@classmethod @classmethod
def get_translatable_display_name(cls): def get_translatable_display_name(cls):
return "Workload balancing" return "Workload Balancing"
@classmethod @classmethod
def get_efficacy_specification(cls): def get_efficacy_specification(cls):
@@ -145,9 +145,9 @@ class WorkloadBalancing(base.Goal):
class AirflowOptimization(base.Goal): class AirflowOptimization(base.Goal):
"""Workload Balancing """AirflowOptimization
This goal is used to optimize the air flow within a cloud infrastructure. This goal is used to optimize the airflow within a cloud infrastructure.
""" """
@classmethod @classmethod
@@ -156,11 +156,11 @@ class AirflowOptimization(base.Goal):
@classmethod @classmethod
def get_display_name(cls): def get_display_name(cls):
return _("Airflow optimization") return _("Airflow Optimization")
@classmethod @classmethod
def get_translatable_display_name(cls): def get_translatable_display_name(cls):
return "Airflow optimization" return "Airflow Optimization"
@classmethod @classmethod
def get_efficacy_specification(cls): def get_efficacy_specification(cls):

View File

@@ -67,10 +67,11 @@ class DefaultPlanner(base.BasePlanner):
'state': objects.action.State.PENDING, 'state': objects.action.State.PENDING,
'next': None, 'next': None,
} }
return action return action
def schedule(self, context, audit_id, solution): def schedule(self, context, audit_id, solution):
LOG.debug('Create an action plan for the audit uuid: %s ', audit_id) LOG.debug('Creating an action plan for the audit uuid: %s', audit_id)
priorities = self.config.weights priorities = self.config.weights
action_plan = self._create_action_plan(context, audit_id, solution) action_plan = self._create_action_plan(context, audit_id, solution)
@@ -145,7 +146,7 @@ class DefaultPlanner(base.BasePlanner):
def _create_action(self, context, _action, parent_action): def _create_action(self, context, _action, parent_action):
try: try:
LOG.debug("Creating the %s in watcher db", LOG.debug("Creating the %s in the Watcher database",
_action.get("action_type")) _action.get("action_type"))
new_action = objects.Action(context, **_action) new_action = objects.Action(context, **_action)

View File

@@ -102,15 +102,15 @@ class TestChangeNovaServiceState(base.TestCase):
sorted([([str(p) for p in e.path], type(e)) for e in exc.errors], sorted([([str(p) for p in e.path], type(e)) for e in exc.errors],
key=lambda x: str(x[0]))) key=lambda x: str(x[0])))
def test_change_service_state_precondition(self): def test_change_service_state_pre_condition(self):
try: try:
self.action.precondition() self.action.pre_condition()
except Exception as exc: except Exception as exc:
self.fail(exc) self.fail(exc)
def test_change_service_state_postcondition(self): def test_change_service_state_post_condition(self):
try: try:
self.action.postcondition() self.action.post_condition()
except Exception as exc: except Exception as exc:
self.fail(exc) self.fail(exc)

View File

@@ -153,15 +153,15 @@ class TestMigration(base.TestCase):
[(['resource_id'], voluptuous.Invalid)], [(['resource_id'], voluptuous.Invalid)],
[(e.path, type(e)) for e in exc.errors]) [(e.path, type(e)) for e in exc.errors])
def test_migration_precondition(self): def test_migration_pre_condition(self):
try: try:
self.action.precondition() self.action.pre_condition()
except Exception as exc: except Exception as exc:
self.fail(exc) self.fail(exc)
def test_migration_postcondition(self): def test_migration_post_condition(self):
try: try:
self.action.postcondition() self.action.post_condition()
except Exception as exc: except Exception as exc:
self.fail(exc) self.fail(exc)

View File

@@ -39,10 +39,10 @@ class FakeAction(abase.BaseAction):
def schema(self): def schema(self):
pass pass
def postcondition(self): def post_condition(self):
pass pass
def precondition(self): def pre_condition(self):
pass pass
def revert(self): def revert(self):