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
This commit is contained in:
Dougal Matthews
2016-09-22 10:03:40 +01:00
parent b74b04671d
commit b9554a8151
2 changed files with 42 additions and 1 deletions

View File

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

View File

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