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 b36ba8399e)
Signed-off-by: Alfredo Moralejo <amoralej@redhat.com>
This commit is contained in:
Alfredo Moralejo
2025-05-16 09:52:28 +02:00
parent 3a923dbf16
commit c7fde92411

View File

@@ -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)