Add the force parameter to delete executions
On a related mistral change the force parameter was included to delete non finished executions, this change add that option to the cli Change-Id: I3408d758bd94038acf2bb9601d4bf2895040f931 Depends-On: I19d822800a1ee056682daeaa7ddf0f400392525d Related-Bug: #1598135
This commit is contained in:
parent
72a6cd9b91
commit
e400bed6b0
@ -113,7 +113,13 @@ class ExecutionManager(base.ResourceManager):
|
||||
|
||||
return self._get('/executions/%s' % id)
|
||||
|
||||
def delete(self, id):
|
||||
def delete(self, id, force=None):
|
||||
self._ensure_not_empty(id=id)
|
||||
qparams = {}
|
||||
|
||||
self._delete('/executions/%s' % id)
|
||||
qparams['force'] = bool(force)
|
||||
|
||||
query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))
|
||||
if qparams else "")
|
||||
|
||||
self._delete('/executions/%s%s' % (id, query_string))
|
||||
|
@ -248,13 +248,21 @@ class Delete(command.Command):
|
||||
help='Id of execution identifier(s).'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--force',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Force the deletion of an execution. Might cause a cascade '
|
||||
' of errors if used for running executions.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
mistral_client = self.app.client_manager.workflow_engine
|
||||
|
||||
force = parsed_args.force
|
||||
utils.do_action_on_many(
|
||||
lambda s: mistral_client.executions.delete(s),
|
||||
lambda s: mistral_client.executions.delete(s, force=force),
|
||||
parsed_args.execution,
|
||||
"Request to delete execution %s has been accepted.",
|
||||
"Unable to delete the specified execution(s)."
|
||||
|
@ -282,13 +282,24 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
||||
def test_delete(self):
|
||||
self.call(execution_cmd.Delete, app_args=['id'])
|
||||
|
||||
self.client.executions.delete.assert_called_once_with('id')
|
||||
self.client.executions.delete.assert_called_once_with(
|
||||
'id',
|
||||
force=False
|
||||
)
|
||||
|
||||
def test_delete_with_force(self):
|
||||
self.call(execution_cmd.Delete, app_args=['id', '--force'])
|
||||
|
||||
self.client.executions.delete.assert_called_once_with(
|
||||
'id',
|
||||
force=True
|
||||
)
|
||||
|
||||
def test_delete_with_multi_names(self):
|
||||
self.call(execution_cmd.Delete, app_args=['id1', 'id2'])
|
||||
|
||||
self.assertEqual(2, self.client.executions.delete.call_count)
|
||||
self.assertEqual(
|
||||
[mock.call('id1'), mock.call('id2')],
|
||||
[mock.call('id1', force=False), mock.call('id2', force=False)],
|
||||
self.client.executions.delete.call_args_list
|
||||
)
|
||||
|
@ -254,6 +254,12 @@ class TestExecutionsV2(base.BaseClientV2Test):
|
||||
ex.to_dict()
|
||||
)
|
||||
|
||||
def test_delete_with_force(self):
|
||||
url = self.TEST_URL + URL_TEMPLATE_ID % EXEC['id']
|
||||
self.requests_mock.delete(url, status_code=204)
|
||||
|
||||
self.executions.delete(EXEC['id'], force=True)
|
||||
|
||||
def test_delete(self):
|
||||
url = self.TEST_URL + URL_TEMPLATE_ID % EXEC['id']
|
||||
self.requests_mock.delete(url, status_code=204)
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adding a --force optional parameter to delete excetutions. Without it only
|
||||
finished executions can be deleted. If --force is passed the execution
|
||||
will be deleted but mistral will generate some errors as expected objects
|
||||
in memory no longer exist
|
Loading…
x
Reference in New Issue
Block a user