Make environment-action-call command accept JSON arguments

Actions can accept different data types as arguments (strings,
numbers, dicts, lists). Previously only strings could be passed
to action through command line. Now CLI accepts arguments in
JSON format additionally to the simple old format.

Change-Id: Ic71d825fca4d9791055b4f82c6574d385e23f8ff
Closes-bug: #1604852
This commit is contained in:
Valerii Kovalchuk 2016-07-20 18:05:07 +03:00
parent 0dafc3d0c9
commit ce7b58804c
3 changed files with 29 additions and 3 deletions

View File

@ -501,10 +501,24 @@ class ShellCommandTest(ShellTest):
self.make_env()
self.register_keystone_discovery_fixture(m_requests)
self.register_keystone_token_fixture(m_requests)
self.shell('environment-action-call 12345 --action-id 54321 '
'--arguments foo=bar')
self.shell("""environment-action-call 12345 --action-id 54321
--arguments foo=bar
dictArg={"key1":"value1","key2":"value2"}
listArg=["item1","item2","item3"]
nullArg=null
stringArg="null"
intArg=5
compoundArg=["foo",14,{"key1":null,"key2":8}]""")
self.client.actions.call.assert_called_once_with(
'12345', '54321', arguments={'foo': 'bar'})
'12345', '54321', arguments={
'foo': 'bar',
'dictArg': {u'key1': u'value1', u'key2': u'value2'},
'listArg': [u'item1', u'item2', u'item3'],
'nullArg': None,
'stringArg': u'null',
'intArg': 5,
'compoundArg': [u'foo', 14, {u'key1': None, u'key2': 8}]
})
@mock.patch('muranoclient.v1.actions.ActionManager')
@requests_mock.mock()

View File

@ -193,6 +193,11 @@ def do_environment_action_call(mc, args):
"Argument should be in form of KEY=VALUE. Found: {0}".format(
argument))
k, v = argument.split('=', 1)
try:
v = json.loads(v)
except ValueError:
# treat value as a string if it doesn't load as json
pass
arguments[k] = v
task_id = mc.actions.call(
args.id, args.action_id, arguments=arguments)

View File

@ -0,0 +1,7 @@
---
upgrade:
- environment-action-call command now accepts action argument values of any
type in JSON format, for example
environment-action-call $ENV_ID --action-id $ACT_ID --arguments
foo=bar listArg='["item1", "item2", "item3"]' nullArg=null
stringArg='"null"' intArg=5