From c7fde924117abf0092776ed82f5ddcc6284cf1a1 Mon Sep 17 00:00:00 2001 From: Alfredo Moralejo Date: Fri, 16 May 2025 09:52:28 +0200 Subject: [PATCH] Add unit test to check action plan state when a nested action fails This patch is adding a new unit test to check the behavior of the action plan when one of the actions in it fails during execution. Note this is to show a bug, and the expected state will be changed in the fixing patch. Related-Bug: #2106407 Change-Id: I2f3fe8f4da772a96db098066d253e5dee330101a (cherry picked from commit b36ba8399e4be1362ce41f8809c4f43df05a4dc6) Signed-off-by: Alfredo Moralejo --- .../test_default_action_handler.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/watcher/tests/applier/action_plan/test_default_action_handler.py b/watcher/tests/applier/action_plan/test_default_action_handler.py index d3f25583b..99c61ecaf 100644 --- a/watcher/tests/applier/action_plan/test_default_action_handler.py +++ b/watcher/tests/applier/action_plan/test_default_action_handler.py @@ -124,3 +124,30 @@ class TestDefaultActionPlanHandler(base.DbTestCase): self.context, mock.MagicMock(), self.action_plan.uuid) command.execute() self.assertEqual(ap_objects.State.CANCELLED, self.action_plan.state) + + @mock.patch.object(objects.ActionPlan, "get_by_uuid") + @mock.patch.object(objects.Action, "list") + def test_launch_action_plan_failed_actions(self, m_action_list, + m_get_action_plan): + m_get_action_plan.return_value = self.action_plan + failed_action = self.action + failed_action.state = objects.action.State.FAILED + m_action_list.return_value = [failed_action] + 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)] + # (amoralej) the actual action_plan.state should beh FAILED. I am + # setting it to SUCCEEDDED and will change it in the fixing change. + self.assertEqual(ap_objects.State.SUCCEEDED, self.action_plan.state) + self.assertEqual( + expected_calls, + self.m_action_plan_notifications + .send_action_notification + .call_args_list)