Add CLI for rerunning failed task execution
Add task-rerun operation to the CLI that allows a failed task execution to be re-run. Change-Id: I38d745d3fca24aa2e3a3f035dd6afb573aa9141b Partial-Implements: blueprint mistral-workflow-pause-resume-with-intervention
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# Copyright 2014 - Mirantis, Inc.
|
||||
# Copyright 2015 - StackStorm, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -34,3 +35,14 @@ class TaskManager(base.ResourceManager):
|
||||
self._ensure_not_empty(id=id)
|
||||
|
||||
return self._get('/tasks/%s' % id)
|
||||
|
||||
def rerun(self, task_ex_id, reset=True):
|
||||
url = '/tasks/%s' % task_ex_id
|
||||
|
||||
body = {
|
||||
'id': task_ex_id,
|
||||
'state': 'RUNNING',
|
||||
'reset': reset
|
||||
}
|
||||
|
||||
return self._update(url, body)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
# Copyright 2014 - Mirantis, Inc.
|
||||
# Copyright 2015 - StackStorm, Inc.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@@ -134,3 +135,34 @@ class GetPublished(command.Command):
|
||||
LOG.debug("Task result is not JSON.")
|
||||
|
||||
self.app.stdout.write(result or "\n")
|
||||
|
||||
|
||||
class Rerun(show.ShowOne):
|
||||
"""Rerun an existing task."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(Rerun, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'id',
|
||||
help='Task identifier'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--resume',
|
||||
action='store_true',
|
||||
dest='resume',
|
||||
default=False,
|
||||
help=('rerun only failed or unstarted action '
|
||||
'executions for with-items task')
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
execution = tasks.TaskManager(self.app.client).rerun(
|
||||
parsed_args.id,
|
||||
reset=(not parsed_args.resume)
|
||||
)
|
||||
|
||||
return format(execution)
|
||||
|
@@ -351,6 +351,7 @@ class MistralShell(app.App):
|
||||
'task-get': mistralclient.commands.v2.tasks.Get,
|
||||
'task-get-published': mistralclient.commands.v2.tasks.GetPublished,
|
||||
'task-get-result': mistralclient.commands.v2.tasks.GetResult,
|
||||
'task-rerun': mistralclient.commands.v2.tasks.Rerun,
|
||||
'action-list': mistralclient.commands.v2.actions.List,
|
||||
'action-get': mistralclient.commands.v2.actions.Get,
|
||||
'action-create': mistralclient.commands.v2.actions.Create,
|
||||
|
@@ -89,3 +89,21 @@ class TestCLITasksV2(base.BaseCommandTest):
|
||||
self.app.stdout.write.assert_called_with(
|
||||
json.dumps(TASK_PUBLISHED, indent=4) + "\n"
|
||||
)
|
||||
|
||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.rerun')
|
||||
def test_rerun(self, mock):
|
||||
mock.return_value = TASK
|
||||
|
||||
result = self.call(task_cmd.Rerun, app_args=['id'])
|
||||
|
||||
self.assertEqual(('123', 'some', 'thing', '321', 'RUNNING'),
|
||||
result[1])
|
||||
|
||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.rerun')
|
||||
def test_rerun_no_reset(self, mock):
|
||||
mock.return_value = TASK
|
||||
|
||||
result = self.call(task_cmd.Rerun, app_args=['id', '--resume'])
|
||||
|
||||
self.assertEqual(('123', 'some', 'thing', '321', 'RUNNING'),
|
||||
result[1])
|
||||
|
@@ -12,6 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
|
||||
from mistralclient.api.v2 import tasks
|
||||
from mistralclient.tests.unit.v2 import base
|
||||
|
||||
@@ -58,3 +60,33 @@ class TestTasksV2(base.BaseClientV2Test):
|
||||
)
|
||||
mock.assert_called_once_with(
|
||||
URL_TEMPLATE_ID % TASK['id'])
|
||||
|
||||
def test_rerun(self):
|
||||
mock = self.mock_http_put(content=TASK)
|
||||
|
||||
task = self.tasks.rerun(TASK['id'])
|
||||
|
||||
self.assertDictEqual(
|
||||
tasks.Task(self.tasks, TASK).to_dict(),
|
||||
task.to_dict()
|
||||
)
|
||||
|
||||
mock.assert_called_once_with(
|
||||
URL_TEMPLATE_ID % TASK['id'],
|
||||
json.dumps({'reset': True, 'state': 'RUNNING', 'id': TASK['id']})
|
||||
)
|
||||
|
||||
def test_rerun_no_reset(self):
|
||||
mock = self.mock_http_put(content=TASK)
|
||||
|
||||
task = self.tasks.rerun(TASK['id'], reset=False)
|
||||
|
||||
self.assertDictEqual(
|
||||
tasks.Task(self.tasks, TASK).to_dict(),
|
||||
task.to_dict()
|
||||
)
|
||||
|
||||
mock.assert_called_once_with(
|
||||
URL_TEMPLATE_ID % TASK['id'],
|
||||
json.dumps({'reset': False, 'state': 'RUNNING', 'id': TASK['id']})
|
||||
)
|
||||
|
Reference in New Issue
Block a user