diff --git a/mistralclient/api/v2/action_executions.py b/mistralclient/api/v2/action_executions.py index c35fa7bd..727f3f84 100644 --- a/mistralclient/api/v2/action_executions.py +++ b/mistralclient/api/v2/action_executions.py @@ -75,3 +75,8 @@ class ActionExecutionManager(base.ResourceManager): self._ensure_not_empty(id=id) return self._get('/action_executions/%s' % id) + + def delete(self, id): + self._ensure_not_empty(id=id) + + self._delete('/action_executions/%s' % id) diff --git a/mistralclient/commands/v2/action_executions.py b/mistralclient/commands/v2/action_executions.py index 64feb3ab..0e8f6235 100644 --- a/mistralclient/commands/v2/action_executions.py +++ b/mistralclient/commands/v2/action_executions.py @@ -22,6 +22,7 @@ from cliff import show from mistralclient.api.v2 import action_executions from mistralclient.commands.v2 import base +from mistralclient import utils LOG = logging.getLogger(__name__) @@ -268,3 +269,30 @@ class GetInput(command.Command): LOG.debug("Task result is not JSON.") self.app.stdout.write(result or "\n") + + +class Delete(command.Command): + """Delete action execution.""" + + def get_parser(self, prog_name): + parser = super(Delete, self).get_parser(prog_name) + + parser.add_argument( + 'id', + nargs='+', + help='Id of action execution identifier(s).' + ) + + return parser + + def take_action(self, parsed_args): + action_ex_mgr = action_executions.ActionExecutionManager( + self.app.client + ) + + utils.do_action_on_many( + lambda s: action_ex_mgr.delete(s), + parsed_args.id, + "Request to delete action execution %s has been accepted.", + "Unable to delete the specified action execution(s)." + ) diff --git a/mistralclient/shell.py b/mistralclient/shell.py index a760f3bd..0836b24d 100644 --- a/mistralclient/shell.py +++ b/mistralclient/shell.py @@ -339,6 +339,8 @@ class MistralShell(app.App): mistralclient.commands.v2.action_executions.GetOutput, 'action-execution-update': mistralclient.commands.v2.action_executions.Update, + 'action-execution-delete': + mistralclient.commands.v2.action_executions.Delete, 'execution-create': mistralclient.commands.v2.executions.Create, 'execution-delete': mistralclient.commands.v2.executions.Delete, 'execution-update': mistralclient.commands.v2.executions.Update, diff --git a/mistralclient/tests/unit/v2/test_action_executions.py b/mistralclient/tests/unit/v2/test_action_executions.py index 009eb085..f7c75095 100644 --- a/mistralclient/tests/unit/v2/test_action_executions.py +++ b/mistralclient/tests/unit/v2/test_action_executions.py @@ -97,3 +97,10 @@ class TestActionExecutions(base.BaseClientV2Test): mock.assert_called_once_with( URL_TEMPLATE_ID % ACTION_EXEC['id']) + + def test_delete(self): + mock = self.mock_http_delete(status_code=204) + + self.action_executions.delete(ACTION_EXEC['id']) + + mock.assert_called_once_with(URL_TEMPLATE_ID % ACTION_EXEC['id']) diff --git a/mistralclient/tests/unit/v2/test_cli_action_execs.py b/mistralclient/tests/unit/v2/test_cli_action_execs.py index 93f3af2f..7ffdb2e2 100644 --- a/mistralclient/tests/unit/v2/test_cli_action_execs.py +++ b/mistralclient/tests/unit/v2/test_cli_action_execs.py @@ -144,3 +144,23 @@ class TestCLIActionExecutions(base.BaseCommandTest): self.app.stdout.write.assert_called_with( json.dumps(ACTION_EX_INPUT, indent=4) + "\n" ) + + @mock.patch( + 'mistralclient.api.v2.action_executions.ActionExecutionManager.delete' + ) + def test_delete(self, del_mock): + self.call(action_ex_cmd.Delete, app_args=['id']) + + del_mock.assert_called_once_with('id') + + @mock.patch( + 'mistralclient.api.v2.action_executions.ActionExecutionManager.delete' + ) + def test_delete_with_multi_names(self, del_mock): + self.call(action_ex_cmd.Delete, app_args=['id1', 'id2']) + + self.assertEqual(2, del_mock.call_count) + self.assertEqual( + [mock.call('id1'), mock.call('id2')], + del_mock.call_args_list + )