From 67560c9ee7400d2514c8334c14d06bc5a17c916c Mon Sep 17 00:00:00 2001 From: ali Date: Sun, 5 Apr 2020 11:32:13 +0000 Subject: [PATCH] fixed compatibility issues between mistral and client removed the namespace field from the action formatter to fix compatibility issues between the client and older versions of mistral. now the action-list command takes the namespace (with --namespace) as an argument and returns a list of the actions in that namespace. the command without --namespace would return the actions of the default namespace ''. fixed issues with execution-list command, the field "nulls" is removed if its empty Change-Id: Ibf64ff8d841ea1192b410902589b0c690b0b2fca Signed-off-by: ali --- mistralclient/api/v2/actions.py | 15 ++++++++++++--- mistralclient/api/v2/executions.py | 4 ++++ mistralclient/commands/v2/actions.py | 10 ++++++++-- mistralclient/tests/unit/v2/test_actions.py | 6 +++--- mistralclient/tests/unit/v2/test_cli_actions.py | 14 +++++++------- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/mistralclient/api/v2/actions.py b/mistralclient/api/v2/actions.py index ef3c3e0a..a5f85661 100644 --- a/mistralclient/api/v2/actions.py +++ b/mistralclient/api/v2/actions.py @@ -30,9 +30,12 @@ class ActionManager(base.ResourceManager): # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) + url = '/actions?scope=%s' % scope + if namespace: + url += '&namespace=%s' % namespace return self._create( - '/actions?scope=%s&namespace=%s' % (scope, namespace), + url, definition, response_key='actions', dump_json=False, @@ -42,7 +45,10 @@ class ActionManager(base.ResourceManager): def update(self, definition, scope='private', id=None, namespace=''): self._ensure_not_empty(definition=definition) - params = '?scope=%s&namespace=%s' % (scope, namespace) + params = '?scope=%s' % scope + if namespace: + params += '&namespace=%s' % namespace + url = ('/actions/%s' % id if id else '/actions') + params # If the specified definition is actually a file, read in the # definition file @@ -57,7 +63,10 @@ class ActionManager(base.ResourceManager): ) def list(self, marker='', limit=None, sort_keys='', sort_dirs='', - fields='', **filters): + fields='', namespace='', **filters): + if namespace: + filters['namespace'] = namespace + query_string = self._build_query_params( marker=marker, limit=limit, diff --git a/mistralclient/api/v2/executions.py b/mistralclient/api/v2/executions.py index c3e9dc1e..9836707e 100644 --- a/mistralclient/api/v2/executions.py +++ b/mistralclient/api/v2/executions.py @@ -80,6 +80,10 @@ class ExecutionManager(base.ResourceManager): if task: filters['task_execution_id'] = task + # for backwards compatibility + if 'nulls' in filters and not filters['nulls']: + filters.pop('nulls') + query_string = self._build_query_params( marker=marker, limit=limit, diff --git a/mistralclient/commands/v2/actions.py b/mistralclient/commands/v2/actions.py index 288e8349..188b6f15 100644 --- a/mistralclient/commands/v2/actions.py +++ b/mistralclient/commands/v2/actions.py @@ -27,7 +27,6 @@ class ActionFormatter(base.MistralFormatter): COLUMNS = [ ('id', 'ID'), ('name', 'Name'), - ('namespace', 'Namespace'), ('is_system', 'Is system'), ('input', 'Input'), ('description', 'Description'), @@ -47,7 +46,6 @@ class ActionFormatter(base.MistralFormatter): data = ( action.id, action.name, - action.namespace, action.is_system, input_, desc, @@ -74,6 +72,13 @@ class List(base.MistralLister): def get_parser(self, prog_name): parser = super(List, self).get_parser(prog_name) + parser.add_argument( + '--namespace', + nargs='?', + default='', + help="Namespace of the actions.", + ) + return parser def _get_resources(self, parsed_args): @@ -85,6 +90,7 @@ class List(base.MistralLister): sort_keys=parsed_args.sort_keys, sort_dirs=parsed_args.sort_dirs, fields=ActionFormatter.fields(), + namespace=parsed_args.namespace, **base.get_filters(parsed_args) ) diff --git a/mistralclient/tests/unit/v2/test_actions.py b/mistralclient/tests/unit/v2/test_actions.py index 13ccf45a..5efdfcab 100644 --- a/mistralclient/tests/unit/v2/test_actions.py +++ b/mistralclient/tests/unit/v2/test_actions.py @@ -121,7 +121,7 @@ class TestActionsV2(base.BaseClientV2Test): last_request = self.requests_mock.last_request - self.assertEqual('scope=private&namespace=', last_request.query) + self.assertEqual('scope=private', last_request.query) self.assertEqual('text/plain', last_request.headers['content-type']) self.assertEqual(ACTION_DEF, last_request.text) @@ -136,7 +136,7 @@ class TestActionsV2(base.BaseClientV2Test): last_request = self.requests_mock.last_request - self.assertEqual('scope=private&namespace=', last_request.query) + self.assertEqual('scope=private', last_request.query) self.assertEqual('text/plain', last_request.headers['content-type']) self.assertEqual(ACTION_DEF, last_request.text) @@ -175,7 +175,7 @@ class TestActionsV2(base.BaseClientV2Test): self.assertEqual(ACTION_DEF, actions[0].definition) last_request = self.requests_mock.last_request - self.assertEqual('scope=private&namespace=', last_request.query) + self.assertEqual('scope=private', last_request.query) self.assertEqual('text/plain', last_request.headers['content-type']) self.assertEqual(ACTION_DEF, last_request.text) diff --git a/mistralclient/tests/unit/v2/test_cli_actions.py b/mistralclient/tests/unit/v2/test_cli_actions.py index d9b516e8..95f04eb8 100644 --- a/mistralclient/tests/unit/v2/test_cli_actions.py +++ b/mistralclient/tests/unit/v2/test_cli_actions.py @@ -60,7 +60,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Create, app_args=['1.txt']) self.assertEqual( - [('1234-4567-7894-7895', 'a', 'test_namespace', True, "param1", + [('1234-4567-7894-7895', 'a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -75,7 +75,7 @@ class TestCLIActionsV2(base.BaseCommandTest): ) self.assertEqual( - [('1234-4567-7894-7895', 'a', 'test_namespace', True, "param1", + [('1234-4567-7894-7895', 'a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -101,7 +101,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Create, app_args=['1.txt']) self.assertEqual( - [('1234-4567-7894-7895', 'a', 'test_namespace', + [('1234-4567-7894-7895', 'a', True, cmd_base.cut(long_input), 'My cool action', 'test', '1', '1')], result[1] @@ -114,7 +114,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Update, app_args=['my_action.yaml']) self.assertEqual( - [('1234-4567-7894-7895', 'a', 'test_namespace', True, "param1", + [('1234-4567-7894-7895', 'a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -129,7 +129,7 @@ class TestCLIActionsV2(base.BaseCommandTest): ) self.assertEqual( - [('1234-4567-7894-7895', 'a', 'test_namespace', True, "param1", + [('1234-4567-7894-7895', 'a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -145,7 +145,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.List) self.assertEqual( - [('1234-4567-7894-7895', 'a', 'test_namespace', True, "param1", + [('1234-4567-7894-7895', 'a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -156,7 +156,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Get, app_args=['name']) self.assertEqual( - ('1234-4567-7894-7895', 'a', 'test_namespace', True, "param1", + ('1234-4567-7894-7895', 'a', True, "param1", 'My cool action', 'test', '1', '1'), result[1] )