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)