From b9554a8151dbe45c879c7f7f6eab791771bb4954 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 22 Sep 2016 10:03:40 +0100 Subject: [PATCH] Expose the --run-sync Action Execution parameter on the CLI This allows for actions to be saved and ran synchronously. See the dependant review for more details. Depends-On: I4417750fd5ff47016357655370410e9e7348cc25 Change-Id: I00c6301394512e123436ca6c5650827c2475308e --- .../commands/v2/action_executions.py | 11 ++++++- .../tests/unit/v2/test_cli_action_execs.py | 32 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mistralclient/commands/v2/action_executions.py b/mistralclient/commands/v2/action_executions.py index 35660f4e..849d1ebd 100644 --- a/mistralclient/commands/v2/action_executions.py +++ b/mistralclient/commands/v2/action_executions.py @@ -121,6 +121,12 @@ class Create(command.ShowOne): action='store_true', help='Save the result into DB.' ) + parser.add_argument( + '--run-sync', + dest='run_sync', + action='store_true', + help='Run the action synchronously.' + ) parser.add_argument( '-t', '--target', @@ -136,6 +142,9 @@ class Create(command.ShowOne): if parsed_args.save_result: params['save_result'] = parsed_args.save_result + if parsed_args.run_sync: + params['run_sync'] = parsed_args.run_sync + if parsed_args.target: params['target'] = parsed_args.target @@ -154,7 +163,7 @@ class Create(command.ShowOne): **params ) - if parsed_args.save_result: + if not parsed_args.run_sync and parsed_args.save_result: return format(action_ex) else: self.app.stdout.write("%s\n" % action_ex.output) diff --git a/mistralclient/tests/unit/v2/test_cli_action_execs.py b/mistralclient/tests/unit/v2/test_cli_action_execs.py index e04d891b..ea529eb5 100644 --- a/mistralclient/tests/unit/v2/test_cli_action_execs.py +++ b/mistralclient/tests/unit/v2/test_cli_action_execs.py @@ -87,6 +87,38 @@ class TestCLIActionExecutions(base.BaseCommandTest): result[1] ) + def test_create_run_sync(self): + (self.client.action_executions.create. + return_value) = ACTION_EX_WITH_OUTPUT + + self.call( + action_ex_cmd.Create, + app_args=[ + 'some', '{"output": "Hello!"}', '--run-sync' + ] + ) + + self.assertDictEqual( + ACTION_EX_RESULT, + json.loads(self.app.stdout.write.call_args[0][0]) + ) + + def test_create_run_sync_and_save_result(self): + (self.client.action_executions.create. + return_value) = ACTION_EX_WITH_OUTPUT + + self.call( + action_ex_cmd.Create, + app_args=[ + 'some', '{"output": "Hello!"}', '--save-result', '--run-sync' + ] + ) + + self.assertDictEqual( + ACTION_EX_RESULT, + json.loads(self.app.stdout.write.call_args[0][0]) + ) + def test_update(self): self.client.action_executions.update.return_value = ACTION_EX