From 190a0931da3e072c829d9572b8d4ca179120983d Mon Sep 17 00:00:00 2001 From: Winson Chan Date: Mon, 10 Oct 2016 20:04:08 +0000 Subject: [PATCH] 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 --- .../commands/v2/action_executions.py | 4 +- .../tests/unit/v2/test_cli_action_execs.py | 52 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/mistralclient/commands/v2/action_executions.py b/mistralclient/commands/v2/action_executions.py index 849d1ebd..8dc72b9e 100644 --- a/mistralclient/commands/v2/action_executions.py +++ b/mistralclient/commands/v2/action_executions.py @@ -1,5 +1,5 @@ # 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 # not use this file except in compliance with the License. You may obtain @@ -228,7 +228,7 @@ class Update(command.ShowOne): parser.add_argument( '--state', dest='state', - choices=['IDLE', 'RUNNING', 'SUCCESS', 'ERROR'], + choices=['IDLE', 'RUNNING', 'SUCCESS', 'ERROR', 'CANCELLED'], help='Action execution state') parser.add_argument( '--output', diff --git a/mistralclient/tests/unit/v2/test_cli_action_execs.py b/mistralclient/tests/unit/v2/test_cli_action_execs.py index ea529eb5..9f6e5257 100644 --- a/mistralclient/tests/unit/v2/test_cli_action_execs.py +++ b/mistralclient/tests/unit/v2/test_cli_action_execs.py @@ -1,5 +1,5 @@ -# Copyright 2014 Mirantis, Inc. -# All Rights Reserved +# Copyright 2014 - Mirantis, Inc. +# Copyright 2016 - Brocade Communications Systems, Inc. # # 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 @@ -14,6 +14,7 @@ # under the License. # +import copy import json import mock @@ -120,18 +121,45 @@ class TestCLIActionExecutions(base.BaseCommandTest): ) def test_update(self): - self.client.action_executions.update.return_value = ACTION_EX + states = ['IDLE', 'RUNNING', 'SUCCESS', 'ERROR', 'CANCELLED'] - result = self.call( - action_ex_cmd.Update, - app_args=['id', '--state', 'ERROR'] - ) + 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 - self.assertEqual( - ('123', 'some', 'thing', 'task1', '1-2-3-4', 'RUNNING', - 'RUNNING somehow.', True, '1', '1'), - result[1] - ) + result = self.call( + action_ex_cmd.Update, + app_args=['id', '--state', state] + ) + + expected_result = ( + action_ex_dict['id'], + action_ex_dict['name'], + 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): self.client.action_executions.list.return_value = [ACTION_EX]