Add cancelled state to action executions

Allow action executions to be cancelled, specifically for async actions.

Change-Id: Iaf27356cb754ed323aabc3ff64c603caa45fe099
Implements: blueprint mistral-cancel-state
Depends-On: Iafc2263735f75fe06ae5f03a885cda8f965a7cc4
This commit is contained in:
Winson Chan 2016-10-10 20:04:08 +00:00
parent b5bb4a1460
commit 190a0931da
2 changed files with 42 additions and 14 deletions

View File

@ -1,5 +1,5 @@
# Copyright 2014 - Mirantis, Inc. # Copyright 2014 - Mirantis, Inc.
# All Rights Reserved # Copyright 2016 - Brocade Communications Systems, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain # not use this file except in compliance with the License. You may obtain
@ -228,7 +228,7 @@ class Update(command.ShowOne):
parser.add_argument( parser.add_argument(
'--state', '--state',
dest='state', dest='state',
choices=['IDLE', 'RUNNING', 'SUCCESS', 'ERROR'], choices=['IDLE', 'RUNNING', 'SUCCESS', 'ERROR', 'CANCELLED'],
help='Action execution state') help='Action execution state')
parser.add_argument( parser.add_argument(
'--output', '--output',

View File

@ -1,5 +1,5 @@
# Copyright 2014 Mirantis, Inc. # Copyright 2014 - Mirantis, Inc.
# All Rights Reserved # Copyright 2016 - Brocade Communications Systems, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain # not use this file except in compliance with the License. You may obtain
@ -14,6 +14,7 @@
# under the License. # under the License.
# #
import copy
import json import json
import mock import mock
@ -120,17 +121,44 @@ class TestCLIActionExecutions(base.BaseCommandTest):
) )
def test_update(self): def test_update(self):
self.client.action_executions.update.return_value = ACTION_EX states = ['IDLE', 'RUNNING', 'SUCCESS', 'ERROR', 'CANCELLED']
for state in states:
action_ex_dict = copy.deepcopy(ACTION_EX_DICT)
action_ex_dict['state'] = state
action_ex_dict['state_info'] = 'testing update'
action_ex_obj = action_ex.ActionExecution(mock, action_ex_dict)
self.client.action_executions.update.return_value = action_ex_obj
result = self.call( result = self.call(
action_ex_cmd.Update, action_ex_cmd.Update,
app_args=['id', '--state', 'ERROR'] app_args=['id', '--state', state]
) )
self.assertEqual( expected_result = (
('123', 'some', 'thing', 'task1', '1-2-3-4', 'RUNNING', action_ex_dict['id'],
'RUNNING somehow.', True, '1', '1'), action_ex_dict['name'],
result[1] action_ex_dict['workflow_name'],
action_ex_dict['task_name'],
action_ex_dict['task_execution_id'],
action_ex_dict['state'],
action_ex_dict['state_info'],
action_ex_dict['accepted'],
action_ex_dict['created_at'],
action_ex_dict['updated_at']
)
self.assertEqual(expected_result, result[1])
def test_update_invalid_state(self):
states = ['PAUSED', 'WAITING', 'DELAYED']
for state in states:
self.assertRaises(
SystemExit,
self.call,
action_ex_cmd.Update,
app_args=['id', '--state', state]
) )
def test_list(self): def test_list(self):