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
This commit is contained in:
Adriano Petrich 2018-04-16 22:20:03 +01:00
parent 72a6cd9b91
commit 3f0255f416
5 changed files with 86 additions and 52 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)