Merge "Add the force parameter to delete executions"

This commit is contained in:
Zuul 2018-04-27 22:30:17 +00:00 committed by Gerrit Code Review
commit 8cc76487fd
5 changed files with 44 additions and 6 deletions

View File

@ -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))

View File

@ -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)."

View File

@ -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
)

View File

@ -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)

View File

@ -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