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.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import abc
@ -28,7 +26,7 @@ from watcher.common.loader import loadable
@six.add_metaclass(abc.ABCMeta)
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
# the resource to which the Action applies to allow us to use it in the
# watcher dashboard and will be nested in input_parameters
@ -99,7 +97,7 @@ class BaseAction(loadable.Loadable):
raise NotImplementedError()
@abc.abstractmethod
def precondition(self):
def pre_condition(self):
"""Hook: called before the execution of an action
This method can be used to perform some initializations or to make
@ -110,7 +108,7 @@ class BaseAction(loadable.Loadable):
raise NotImplementedError()
@abc.abstractmethod
def postcondition(self):
def post_condition(self):
"""Hook: called after the execution of an action
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
# limitations under the License.
#
import six
import voluptuous
@ -95,8 +96,8 @@ class ChangeNovaServiceState(base.BaseAction):
else:
return nova.disable_service_nova_compute(self.host)
def precondition(self):
def pre_condition(self):
pass
def postcondition(self):
def post_condition(self):
pass

View File

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

View File

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

View File

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

View File

@ -109,8 +109,8 @@ class TaskFlowActionContainer(task.Task):
try:
self.engine.notify(self._db_action,
obj_action.State.ONGOING)
LOG.debug("Precondition action %s", self.name)
self.action.precondition()
LOG.debug("Pre-condition action: %s", self.name)
self.action.pre_condition()
except Exception as e:
LOG.exception(e)
self.engine.notify(self._db_action,
@ -119,15 +119,15 @@ class TaskFlowActionContainer(task.Task):
def execute(self, *args, **kwargs):
try:
LOG.debug("Running action %s", self.name)
LOG.debug("Running action: %s", self.name)
self.action.execute()
self.engine.notify(self._db_action,
obj_action.State.SUCCEEDED)
except Exception as e:
LOG.exception(e)
LOG.error(_LE('The WorkFlow Engine has failed '
'to execute the action %s'), self.name)
LOG.error(_LE('The workflow engine has failed '
'to execute the action: %s'), self.name)
self.engine.notify(self._db_action,
obj_action.State.FAILED)
@ -135,8 +135,8 @@ class TaskFlowActionContainer(task.Task):
def post_execute(self):
try:
LOG.debug("postcondition action %s", self.name)
self.action.postcondition()
LOG.debug("Post-condition action: %s", self.name)
self.action.post_condition()
except Exception as e:
LOG.exception(e)
self.engine.notify(self._db_action,
@ -144,19 +144,19 @@ class TaskFlowActionContainer(task.Task):
raise
def revert(self, *args, **kwargs):
LOG.warning(_LW("Revert action %s"), self.name)
LOG.warning(_LW("Revert action: %s"), self.name)
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()
except Exception as 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):
"""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):
pass

View File

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

View File

@ -67,10 +67,11 @@ class DefaultPlanner(base.BasePlanner):
'state': objects.action.State.PENDING,
'next': None,
}
return action
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
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):
try:
LOG.debug("Creating the %s in watcher db",
LOG.debug("Creating the %s in the Watcher database",
_action.get("action_type"))
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],
key=lambda x: str(x[0])))
def test_change_service_state_precondition(self):
def test_change_service_state_pre_condition(self):
try:
self.action.precondition()
self.action.pre_condition()
except Exception as exc:
self.fail(exc)
def test_change_service_state_postcondition(self):
def test_change_service_state_post_condition(self):
try:
self.action.postcondition()
self.action.post_condition()
except Exception as exc:
self.fail(exc)

View File

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

View File

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