From ce7b58804c7566bbe5534fe51ad36a6bc3ccfc57 Mon Sep 17 00:00:00 2001 From: Valerii Kovalchuk Date: Wed, 20 Jul 2016 18:05:07 +0300 Subject: [PATCH] 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 --- muranoclient/tests/unit/test_shell.py | 20 ++++++++++++++++--- muranoclient/v1/shell.py | 5 +++++ .../action-arguments-06a554f76783f3ed.yaml | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/action-arguments-06a554f76783f3ed.yaml diff --git a/muranoclient/tests/unit/test_shell.py b/muranoclient/tests/unit/test_shell.py index 1a70ff07..62fcf8cf 100644 --- a/muranoclient/tests/unit/test_shell.py +++ b/muranoclient/tests/unit/test_shell.py @@ -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() diff --git a/muranoclient/v1/shell.py b/muranoclient/v1/shell.py index 55d99761..ea670bb5 100644 --- a/muranoclient/v1/shell.py +++ b/muranoclient/v1/shell.py @@ -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) diff --git a/releasenotes/notes/action-arguments-06a554f76783f3ed.yaml b/releasenotes/notes/action-arguments-06a554f76783f3ed.yaml new file mode 100644 index 00000000..b47e6867 --- /dev/null +++ b/releasenotes/notes/action-arguments-06a554f76783f3ed.yaml @@ -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