Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Added
Changed
~~~~~~~

* Added cancel/pause/resume requester information to execution context. #5459

Contributed by @khushboobhatia01

* Modified action delete API to delete action files from disk along with backward compatibility.

From CLI ``st2 action delete <pack>.<action>`` will delete only action database entry.
Expand Down
1 change: 1 addition & 0 deletions contrib/runners/orquesta_runner/tests/unit/test_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_cancel(self):
lv_ac_db, ac_ex_db = ac_svc.request_cancellation(lv_ac_db, requester)
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_CANCELING)
self.assertEqual(lv_ac_db.context["cancelled_by"], requester)

def test_cancel_workflow_cascade_down_to_subworkflow(self):
wf_meta = base.get_wf_fixture_meta_data(TEST_PACK_PATH, "subworkflow.yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_pause(self):
lv_ac_db, ac_ex_db = ac_svc.request_pause(lv_ac_db, cfg.CONF.system_user.user)
lv_ac_db = lv_db_access.LiveAction.get_by_id(str(lv_ac_db.id))
self.assertEqual(lv_ac_db.status, ac_const.LIVEACTION_STATUS_PAUSING)
self.assertEqual(lv_ac_db.context["paused_by"], cfg.CONF.system_user.user)

@mock.patch.object(ac_svc, "is_children_active", mock.MagicMock(return_value=True))
def test_pause_with_active_children(self):
Expand Down Expand Up @@ -525,6 +526,7 @@ def test_resume(self):
workflow_execution=str(wf_ex_dbs[0].id)
)
self.assertEqual(len(tk_ex_dbs), 2)
self.assertEqual(lv_ac_db.context["resumed_by"], cfg.CONF.system_user.user)

def test_resume_cascade_to_subworkflow(self):
wf_meta = base.get_wf_fixture_meta_data(TEST_PACK_PATH, "subworkflow.yaml")
Expand Down
27 changes: 23 additions & 4 deletions st2common/st2common/services/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ def request(liveaction):


def update_status(
liveaction, new_status, result=None, publish=True, set_result_size=False
liveaction,
new_status,
result=None,
publish=True,
set_result_size=False,
context=None,
):
if liveaction.status == new_status:
return liveaction
Expand All @@ -226,6 +231,7 @@ def update_status(
"status": new_status,
"result": result,
"publish": False,
"context": context,
}

if new_status in action_constants.LIVEACTION_COMPLETED_STATES:
Expand Down Expand Up @@ -304,7 +310,10 @@ def request_cancellation(liveaction, requester):
else:
status = action_constants.LIVEACTION_STATUS_CANCELED

liveaction = update_status(liveaction, status, result=result)
liveaction.context["cancelled_by"] = requester
liveaction = update_status(
liveaction, status, result=result, context=liveaction.context
)

execution = ActionExecution.get(liveaction__id=str(liveaction.id))

Expand Down Expand Up @@ -346,7 +355,12 @@ def request_pause(liveaction, requester):
% liveaction.id
)

liveaction = update_status(liveaction, action_constants.LIVEACTION_STATUS_PAUSING)
liveaction.context["paused_by"] = requester
liveaction = update_status(
liveaction,
action_constants.LIVEACTION_STATUS_PAUSING,
context=liveaction.context,
)

execution = ActionExecution.get(liveaction__id=str(liveaction.id))

Expand Down Expand Up @@ -390,7 +404,12 @@ def request_resume(liveaction, requester):
'not in "paused" state.' % (liveaction.id, liveaction.status)
)

liveaction = update_status(liveaction, action_constants.LIVEACTION_STATUS_RESUMING)
liveaction.context["resumed_by"] = requester
liveaction = update_status(
liveaction,
action_constants.LIVEACTION_STATUS_RESUMING,
context=liveaction.context,
)

execution = ActionExecution.get(liveaction__id=str(liveaction.id))

Expand Down