diff --git a/watcher/applier/workflow_engine/base.py b/watcher/applier/workflow_engine/base.py index 5f0bcf746..427165fbd 100644 --- a/watcher/applier/workflow_engine/base.py +++ b/watcher/applier/workflow_engine/base.py @@ -36,9 +36,6 @@ from watcher.objects import fields LOG = log.getLogger(__name__) -CANCEL_STATE = [objects.action_plan.State.CANCELLING, - objects.action_plan.State.CANCELLED] - class BaseWorkFlowEngine(loadable.Loadable, metaclass=abc.ABCMeta): @@ -162,7 +159,7 @@ class BaseTaskFlowActionContainer(flow_task.Task): # so that taskflow does not schedule further actions. action_plan = objects.ActionPlan.get_by_id( self.engine.context, self._db_action.action_plan_id) - if action_plan.state in CANCEL_STATE: + if action_plan.state in objects.action_plan.State.CANCEL_STATES: raise exception.ActionPlanCancelled(uuid=action_plan.uuid) if self._db_action.state == objects.action.State.SKIPPED: LOG.debug("Action %s is skipped manually", @@ -245,7 +242,8 @@ class BaseTaskFlowActionContainer(flow_task.Task): result = True if (action_object.state in [objects.action.State.SUCCEEDED, objects.action.State.FAILED] or - action_plan_object.state in CANCEL_STATE): + action_plan_object.state in + objects.action_plan.State.CANCEL_STATES): break time.sleep(1) try: @@ -255,7 +253,9 @@ class BaseTaskFlowActionContainer(flow_task.Task): # Not all actions support abort operations, kill only those action # which support abort operations abort = self.action.check_abort() - if (action_plan_object.state in CANCEL_STATE and abort): + if (action_plan_object.state in + objects.action_plan.State.CANCEL_STATES and + abort): et.kill() et.wait() return result @@ -300,7 +300,7 @@ class BaseTaskFlowActionContainer(flow_task.Task): # NOTE: check if revert cause by cancel action plan or # some other exception occurred during action plan execution # if due to some other exception keep the flow intact. - if action_plan.state not in CANCEL_STATE: + if action_plan.state not in objects.action_plan.State.CANCEL_STATES: self.do_revert() return diff --git a/watcher/objects/action_plan.py b/watcher/objects/action_plan.py index 8426532f4..91eac9623 100644 --- a/watcher/objects/action_plan.py +++ b/watcher/objects/action_plan.py @@ -98,6 +98,8 @@ class State(object): SUPERSEDED = 'SUPERSEDED' CANCELLING = 'CANCELLING' + CANCEL_STATES = [CANCELLING, CANCELLED] + @base.WatcherObjectRegistry.register class ActionPlan(base.WatcherPersistentObject, base.WatcherObject,