Merge "Do not let keystoneauth mask the errors"

This commit is contained in:
Zuul
2018-04-26 08:59:31 +00:00
committed by Gerrit Code Review
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: if params:
data['params'] = json.dumps(params) data['params'] = json.dumps(params)
resp = self.http_client.post( return self._create(
'/action_executions', '/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): def update(self, id, state=None, output=None):
self._ensure_not_empty(id=id) self._ensure_not_empty(id=id)

View File

@@ -14,6 +14,7 @@
import six import six
from keystoneauth1 import exceptions
from mistralclient.api import base from mistralclient.api import base
from mistralclient import utils from mistralclient import utils
@@ -34,11 +35,14 @@ class ActionManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.post( try:
'/actions?scope=%s' % scope, resp = self.http_client.post(
definition, '/actions?scope=%s' % scope,
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 201: if resp.status_code != 201:
self._raise_api_exception(resp) self._raise_api_exception(resp)
@@ -55,11 +59,14 @@ class ActionManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.put( try:
'%s?scope=%s' % (url_pre, scope), resp = self.http_client.put(
definition, '%s?scope=%s' % (url_pre, scope),
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 200: if resp.status_code != 200:
self._raise_api_exception(resp) self._raise_api_exception(resp)
@@ -111,11 +118,14 @@ class ActionManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.post( try:
'/actions/validate', resp = self.http_client.post(
definition, '/actions/validate',
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 200: if resp.status_code != 200:
self._raise_api_exception(resp) self._raise_api_exception(resp)

View File

@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from keystoneauth1 import exceptions
from mistralclient.api import base from mistralclient.api import base
from mistralclient import utils from mistralclient import utils
@@ -31,11 +32,14 @@ class WorkbookManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.post( try:
'/workbooks', resp = self.http_client.post(
definition, '/workbooks',
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 201: if resp.status_code != 201:
self._raise_api_exception(resp) self._raise_api_exception(resp)
@@ -49,11 +53,14 @@ class WorkbookManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.put( try:
'/workbooks', resp = self.http_client.put(
definition, '/workbooks',
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 200: if resp.status_code != 200:
self._raise_api_exception(resp) self._raise_api_exception(resp)
@@ -80,11 +87,14 @@ class WorkbookManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.post( try:
'/workbooks/validate', resp = self.http_client.post(
definition, '/workbooks/validate',
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 200: if resp.status_code != 200:
self._raise_api_exception(resp) self._raise_api_exception(resp)

View File

@@ -15,6 +15,7 @@
import six import six
from keystoneauth1 import exceptions
from mistralclient.api import base from mistralclient.api import base
from mistralclient import utils from mistralclient import utils
@@ -36,11 +37,14 @@ class WorkflowManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.post( try:
'/workflows?scope=%s&namespace=%s' % (scope, namespace), resp = self.http_client.post(
definition, '/workflows?scope=%s&namespace=%s' % (scope, namespace),
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 201: if resp.status_code != 201:
self._raise_api_exception(resp) self._raise_api_exception(resp)
@@ -57,11 +61,14 @@ class WorkflowManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.put( try:
'%s?namespace=%s&scope=%s' % (url_pre, namespace, scope), resp = self.http_client.put(
definition, '%s?namespace=%s&scope=%s' % (url_pre, namespace, scope),
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 200: if resp.status_code != 200:
self._raise_api_exception(resp) self._raise_api_exception(resp)
@@ -126,11 +133,14 @@ class WorkflowManager(base.ResourceManager):
# definition file # definition file
definition = utils.get_contents_if_file(definition) definition = utils.get_contents_if_file(definition)
resp = self.http_client.post( try:
'/workflows/validate', resp = self.http_client.post(
definition, '/workflows/validate',
headers={'content-type': 'text/plain'} definition,
) headers={'content-type': 'text/plain'}
)
except exceptions.HttpError as ex:
self._raise_api_exception(ex.response)
if resp.status_code != 200: if resp.status_code != 200:
self._raise_api_exception(resp) self._raise_api_exception(resp)