Support action_execution deletion on client side
$ mistral action-execution-delete <action_execution_id> NOTE: * By default, users can't perform such operation, unless the 'allow_action_execution_deletion' is set to True on server side. * Only ad-hoc action-execution can be deleted. Change-Id: Iad0bfb0c2f688928d1e1bd8c41fcf90acd94cd66 Implements: blueprint mistralclient-action-execution-deletion
This commit is contained in:
@@ -75,3 +75,8 @@ class ActionExecutionManager(base.ResourceManager):
|
|||||||
self._ensure_not_empty(id=id)
|
self._ensure_not_empty(id=id)
|
||||||
|
|
||||||
return self._get('/action_executions/%s' % id)
|
return self._get('/action_executions/%s' % id)
|
||||||
|
|
||||||
|
def delete(self, id):
|
||||||
|
self._ensure_not_empty(id=id)
|
||||||
|
|
||||||
|
self._delete('/action_executions/%s' % id)
|
||||||
|
@@ -22,6 +22,7 @@ from cliff import show
|
|||||||
|
|
||||||
from mistralclient.api.v2 import action_executions
|
from mistralclient.api.v2 import action_executions
|
||||||
from mistralclient.commands.v2 import base
|
from mistralclient.commands.v2 import base
|
||||||
|
from mistralclient import utils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -268,3 +269,30 @@ class GetInput(command.Command):
|
|||||||
LOG.debug("Task result is not JSON.")
|
LOG.debug("Task result is not JSON.")
|
||||||
|
|
||||||
self.app.stdout.write(result or "\n")
|
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)."
|
||||||
|
)
|
||||||
|
@@ -339,6 +339,8 @@ class MistralShell(app.App):
|
|||||||
mistralclient.commands.v2.action_executions.GetOutput,
|
mistralclient.commands.v2.action_executions.GetOutput,
|
||||||
'action-execution-update':
|
'action-execution-update':
|
||||||
mistralclient.commands.v2.action_executions.Update,
|
mistralclient.commands.v2.action_executions.Update,
|
||||||
|
'action-execution-delete':
|
||||||
|
mistralclient.commands.v2.action_executions.Delete,
|
||||||
'execution-create': mistralclient.commands.v2.executions.Create,
|
'execution-create': mistralclient.commands.v2.executions.Create,
|
||||||
'execution-delete': mistralclient.commands.v2.executions.Delete,
|
'execution-delete': mistralclient.commands.v2.executions.Delete,
|
||||||
'execution-update': mistralclient.commands.v2.executions.Update,
|
'execution-update': mistralclient.commands.v2.executions.Update,
|
||||||
|
@@ -97,3 +97,10 @@ class TestActionExecutions(base.BaseClientV2Test):
|
|||||||
|
|
||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
URL_TEMPLATE_ID % ACTION_EXEC['id'])
|
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'])
|
||||||
|
@@ -144,3 +144,23 @@ class TestCLIActionExecutions(base.BaseCommandTest):
|
|||||||
self.app.stdout.write.assert_called_with(
|
self.app.stdout.write.assert_called_with(
|
||||||
json.dumps(ACTION_EX_INPUT, indent=4) + "\n"
|
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
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user