Skip actions automatically based on pre_condition results
This patch is implementing skipping automatically actions based on the result of action pre_condition method. This will allow to manage properly situations as migration actions for vms which does not longer exist. This patch includes: - Adding a new state SKIPPED to the Action objects. - Add a new Exception ActionSkipped. An action which raises it from the pre_condition execution is moved to SKIPPED state. - pre_condition will not be executed for any action in SKIPPED state. - execute will not be executed for any action in SKIPPED or FAILED state. - post_condition will not be executed for any action in SKIPPED state. - moving transition to ONGOING from pre_condition to execute. That means that actions raising ActionSkipped will move from PENDING to SKIPPED while actions raising any other Exception will move from PENDING to FAILED. - Adding information on action failed or skipped state to the `status_message` field. - Adding a new option to the testing action nop to simulate skipping on pre_condition, so that we can easily test it. Implements: blueprint add-skip-actions Assisted-By: Cursor (claude-4-sonnet) Change-Id: I59cb4c7006c7c3bcc5ff2071886d3e2929800f9e Signed-off-by: Alfredo Moralejo <amoralej@redhat.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from unittest import mock
|
||||
from watcher.applier.action_plan import default
|
||||
from watcher.applier import default as ap_applier
|
||||
from watcher.common import exception
|
||||
from watcher.common import utils
|
||||
from watcher import notifications
|
||||
from watcher import objects
|
||||
from watcher.objects import action_plan as ap_objects
|
||||
@@ -151,3 +152,70 @@ class TestDefaultActionPlanHandler(base.DbTestCase):
|
||||
self.m_action_plan_notifications
|
||||
.send_action_notification
|
||||
.call_args_list)
|
||||
|
||||
@mock.patch.object(objects.ActionPlan, "get_by_uuid")
|
||||
def test_launch_action_plan_skipped_actions(self,
|
||||
m_get_action_plan):
|
||||
m_get_action_plan.return_value = self.action_plan
|
||||
skipped_action = obj_utils.create_test_action(
|
||||
self.context, action_plan_id=self.action_plan.id,
|
||||
action_type='nop',
|
||||
uuid=utils.generate_uuid(),
|
||||
input_parameters={'message': 'hello World',
|
||||
'skip_pre_condition': True})
|
||||
command = default.DefaultActionPlanHandler(
|
||||
self.context, mock.MagicMock(), self.action_plan.uuid)
|
||||
command.execute()
|
||||
expected_calls = [
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.START),
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.END)
|
||||
]
|
||||
|
||||
self.assertEqual(
|
||||
self.action.get_by_uuid(self.context, skipped_action.uuid).state,
|
||||
objects.action.State.SKIPPED)
|
||||
self.assertEqual(ap_objects.State.SUCCEEDED, self.action_plan.state)
|
||||
self.assertEqual(self.action_plan.status_message,
|
||||
"One or more actions were skipped.")
|
||||
self.assertEqual(
|
||||
expected_calls,
|
||||
self.m_action_plan_notifications
|
||||
.send_action_notification
|
||||
.call_args_list)
|
||||
|
||||
@mock.patch.object(objects.ActionPlan, "get_by_uuid")
|
||||
def test_launch_action_plan_manual_skipped_actions(self,
|
||||
m_get_action_plan):
|
||||
m_get_action_plan.return_value = self.action_plan
|
||||
skipped_action = obj_utils.create_test_action(
|
||||
self.context, action_plan_id=self.action_plan.id,
|
||||
action_type='nop',
|
||||
uuid=utils.generate_uuid(),
|
||||
state=objects.action.State.SKIPPED,
|
||||
input_parameters={'message': 'hello World'})
|
||||
command = default.DefaultActionPlanHandler(
|
||||
self.context, mock.MagicMock(), self.action_plan.uuid)
|
||||
command.execute()
|
||||
expected_calls = [
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.START),
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.END)
|
||||
]
|
||||
self.assertEqual(
|
||||
self.action.get_by_uuid(self.context, skipped_action.uuid).state,
|
||||
objects.action.State.SKIPPED)
|
||||
self.assertEqual(ap_objects.State.SUCCEEDED, self.action_plan.state)
|
||||
self.assertEqual(self.action_plan.status_message,
|
||||
"One or more actions were skipped.")
|
||||
self.assertEqual(
|
||||
expected_calls,
|
||||
self.m_action_plan_notifications
|
||||
.send_action_notification
|
||||
.call_args_list)
|
||||
|
||||
Reference in New Issue
Block a user