Skip to content

Commit

Permalink
Add re-run options to the context in the LiveActionDB object
Browse files Browse the repository at this point in the history
  • Loading branch information
m4dcoder committed Jan 14, 2016
1 parent 6928e7b commit 277182c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
18 changes: 15 additions & 3 deletions st2api/st2api/controllers/v1/actionexecutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,22 @@ def post(self, spec, execution_id):

# Create object for the new execution
action_ref = existing_execution.action['ref']
new_liveaction = LiveActionDB(action=action_ref, parameters=new_parameters)

result = self._handle_schedule_execution(liveaction=new_liveaction)
return result
# Include additional option(s) for the execution
context = {
're-run': {
'ref': execution_id,
}
}

if spec.tasks:
context['re-run']['tasks'] = spec.tasks

new_liveaction = LiveActionDB(action=action_ref,
context=context,
parameters=new_parameters)

return self._handle_schedule_execution(liveaction=new_liveaction)


class ActionExecutionsController(ActionExecutionsControllerMixin, ResourceController):
Expand Down
29 changes: 29 additions & 0 deletions st2api/tests/unit/controllers/v1/test_executions_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ def test_re_run_workflow_success(self):

self.assertEqual(re_run_resp.status_int, 201)

expected_context = {
'user': 'stanley',
're-run': {
'ref': execution_id
}
}

self.assertDictEqual(re_run_resp.json['context'], expected_context)

def test_re_run_workflow_task_success(self):
# Create a new execution
post_resp = self._do_post(LIVE_ACTION_4)
Expand All @@ -433,6 +442,16 @@ def test_re_run_workflow_task_success(self):

self.assertEqual(re_run_resp.status_int, 201)

expected_context = {
'user': 'stanley',
're-run': {
'ref': execution_id,
'tasks': data['tasks']
}
}

self.assertDictEqual(re_run_resp.json['context'], expected_context)

def test_re_run_workflow_tasks_success(self):
# Create a new execution
post_resp = self._do_post(LIVE_ACTION_4)
Expand All @@ -446,6 +465,16 @@ def test_re_run_workflow_tasks_success(self):

self.assertEqual(re_run_resp.status_int, 201)

expected_context = {
'user': 'stanley',
're-run': {
'ref': execution_id,
'tasks': data['tasks']
}
}

self.assertDictEqual(re_run_resp.json['context'], expected_context)

def test_re_run_failure_tasks_option_for_non_workflow(self):
# Create a new execution
post_resp = self._do_post(LIVE_ACTION_1)
Expand Down

0 comments on commit 277182c

Please sign in to comment.