From 3f0255f4162f7e049c2d67003b8c579e412ca512 Mon Sep 17 00:00:00 2001 From: Adriano Petrich Date: Mon, 16 Apr 2018 22:20:03 +0100 Subject: [PATCH] Do not let keystoneauth mask the errors Currently some mistral errors are masked in the cli with non helpful messages like: ERROR (app) Bad Request (HTTP 400) That is due to ResourceManagers not using the standard underscore methods defined in the base class. Those underscore methods have the appropriate try catch to parse the unfriendly keystoneauth errors into more cli friendly errors like: ERROR (app) Invalid input [name=std.echo, class=mistral.actions.std_actions.EchoAction, missing=['output']] This adds the try catch to the non standard methods and change the action_execution.create to use the standard method Change-Id: I2573cb093e97ce378fc1d255d8b38e2ce818c8e5 Closes-bug: #1754093 --- ...x-cli-error-messages-2f59329557a5734f.yaml | 8 ++++ mistralclient/api/v2/action_executions.py | 10 ++--- mistralclient/api/v2/actions.py | 40 ++++++++++++------- mistralclient/api/v2/workbooks.py | 40 ++++++++++++------- mistralclient/api/v2/workflows.py | 40 ++++++++++++------- 5 files changed, 86 insertions(+), 52 deletions(-) create mode 100644 mistralclient/api/releasenotes/notes/fix-cli-error-messages-2f59329557a5734f.yaml diff --git a/mistralclient/api/releasenotes/notes/fix-cli-error-messages-2f59329557a5734f.yaml b/mistralclient/api/releasenotes/notes/fix-cli-error-messages-2f59329557a5734f.yaml new file mode 100644 index 00000000..530ef979 --- /dev/null +++ b/mistralclient/api/releasenotes/notes/fix-cli-error-messages-2f59329557a5734f.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Some cli mistral calls when failed would return unhelpful messages like + error(400) that is not what the mistral api is returning. This changes + those messages to the useful messages sent by the api. + The affected are the run-action, the crud for actions, workflows, and + workbooks. diff --git a/mistralclient/api/v2/action_executions.py b/mistralclient/api/v2/action_executions.py index becb316c..7115925e 100644 --- a/mistralclient/api/v2/action_executions.py +++ b/mistralclient/api/v2/action_executions.py @@ -38,16 +38,12 @@ class ActionExecutionManager(base.ResourceManager): if params: data['params'] = json.dumps(params) - resp = self.http_client.post( + return self._create( '/action_executions', - json.dumps(data) + data, + dump_json=True ) - if resp.status_code != 201: - self._raise_api_exception(resp) - - return self.resource_class(self, base.get_json(resp)) - def update(self, id, state=None, output=None): self._ensure_not_empty(id=id) diff --git a/mistralclient/api/v2/actions.py b/mistralclient/api/v2/actions.py index 20866f7d..c5acc347 100644 --- a/mistralclient/api/v2/actions.py +++ b/mistralclient/api/v2/actions.py @@ -14,6 +14,7 @@ import six +from keystoneauth1 import exceptions from mistralclient.api import base from mistralclient import utils @@ -34,11 +35,14 @@ class ActionManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.post( - '/actions?scope=%s' % scope, - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.post( + '/actions?scope=%s' % scope, + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 201: self._raise_api_exception(resp) @@ -55,11 +59,14 @@ class ActionManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.put( - '%s?scope=%s' % (url_pre, scope), - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.put( + '%s?scope=%s' % (url_pre, scope), + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) @@ -111,11 +118,14 @@ class ActionManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.post( - '/actions/validate', - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.post( + '/actions/validate', + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) diff --git a/mistralclient/api/v2/workbooks.py b/mistralclient/api/v2/workbooks.py index 88a51128..957aca70 100644 --- a/mistralclient/api/v2/workbooks.py +++ b/mistralclient/api/v2/workbooks.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keystoneauth1 import exceptions from mistralclient.api import base from mistralclient import utils @@ -31,11 +32,14 @@ class WorkbookManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.post( - '/workbooks', - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.post( + '/workbooks', + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 201: self._raise_api_exception(resp) @@ -49,11 +53,14 @@ class WorkbookManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.put( - '/workbooks', - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.put( + '/workbooks', + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) @@ -80,11 +87,14 @@ class WorkbookManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.post( - '/workbooks/validate', - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.post( + '/workbooks/validate', + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) diff --git a/mistralclient/api/v2/workflows.py b/mistralclient/api/v2/workflows.py index 04479591..b72e1e92 100644 --- a/mistralclient/api/v2/workflows.py +++ b/mistralclient/api/v2/workflows.py @@ -15,6 +15,7 @@ import six +from keystoneauth1 import exceptions from mistralclient.api import base from mistralclient import utils @@ -36,11 +37,14 @@ class WorkflowManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.post( - '/workflows?scope=%s&namespace=%s' % (scope, namespace), - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.post( + '/workflows?scope=%s&namespace=%s' % (scope, namespace), + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 201: self._raise_api_exception(resp) @@ -57,11 +61,14 @@ class WorkflowManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.put( - '%s?namespace=%s&scope=%s' % (url_pre, namespace, scope), - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.put( + '%s?namespace=%s&scope=%s' % (url_pre, namespace, scope), + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) @@ -126,11 +133,14 @@ class WorkflowManager(base.ResourceManager): # definition file definition = utils.get_contents_if_file(definition) - resp = self.http_client.post( - '/workflows/validate', - definition, - headers={'content-type': 'text/plain'} - ) + try: + resp = self.http_client.post( + '/workflows/validate', + definition, + headers={'content-type': 'text/plain'} + ) + except exceptions.HttpError as ex: + self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp)