Skip to content

Commit

Permalink
Check if action flow has been failed during specific function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sandakov committed Aug 3, 2024
1 parent df198f0 commit 86cebd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pleskdistup/common/src/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def __enter__(self):
def __exit__(self, *kwargs):
# Do not remove the actions data if an error occurs because
# customer will likely want to retry after correcting the error on their end
if self.error is not None and os.path.exists(self.path_to_actions_data):
if not self.is_failed() and os.path.exists(self.path_to_actions_data):
os.remove(self.path_to_actions_data)

def _get_flow(self) -> typing.Dict[str, typing.List[ActiveAction]]:
Expand Down
20 changes: 20 additions & 0 deletions pleskdistup/common/tests/actionstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,26 @@ def test_finish_skip_based_on_skip_saved_state(self):
def test_finish_skip_based_on_failed_saved_state(self):
check_saved_state("finish", "test_finish_skip_based_on_failed_saved_state", "failed", False)

def test_actions_json_removed(self):
simple_action = SimpleAction()
simple_action._post_action = mock.Mock(return_value=action.ActionResult())
with FinishActionsFlowForTests({"test_one_simple_action": [simple_action]}) as flow:
flow.validate_actions()
flow.pass_actions()

simple_action._post_action.assert_called_once()
self.assertFalse(os.path.exists("actions.json"))

def test_actions_json_not_removed_on_fail(self):
simple_action = SimpleAction()
simple_action._post_action = mock.Mock(return_value=action.ActionResult(action.ActionState.FAILED))
with FinishActionsFlowForTests({"test_one_simple_action": [simple_action]}) as flow:
flow.validate_actions()
flow.pass_actions()

simple_action._post_action.assert_called_once()
self.assertTrue(os.path.exists("actions.json"))


class RevertActionsFlowForTests(action.RevertActionsFlow):
def __init__(self, stages):
Expand Down

0 comments on commit 86cebd4

Please sign in to comment.