placement: Fix HTTP error generation

The traits and the inventories wsgi handler inserted the detailed error
message to the webob.exc.HTTPXXX exceptions via the 'explanation' kwarg.
This caused that the generated error messages does not contain the generic
explanation of the HTTP error code just the passed in explanation text.
The rest of the placement API uses first positional arg of the exception
classes to pass in the extra details. Having this inconsistency makes
really hard to print proper error messages from the osc-placement
plugin.

This patch removes the incosistency by changing the code to use the
positional arg.

The change does not affect nova.scheduler.client.report._RE_INV_IN_USE
regex usage as that regex applied via re.search() and this change only
adds a new sentece to the message.

Change-Id: I196c2e3dabcbf0564c1ca0bd4870dc2df3efc836
Close-Bug: #1771325
(cherry picked from commit 90d2dbedef)
This commit is contained in:
Balazs Gibizer 2018-05-15 13:44:59 +02:00
parent 365a1d2a13
commit dddee4189c
2 changed files with 8 additions and 12 deletions

View File

@ -358,7 +358,7 @@ def delete_inventories(req):
except exception.InventoryInUse as ex:
# NOTE(mriedem): This message cannot change without impacting the
# nova.scheduler.client.report._RE_INV_IN_USE regex.
raise webob.exc.HTTPConflict(explanation=ex.format_message())
raise webob.exc.HTTPConflict(ex.format_message())
response = req.response
response.status = 204

View File

@ -105,8 +105,7 @@ def get_trait(req):
try:
trait = rp_obj.Trait.get_by_name(context, name)
except exception.TraitNotFound as ex:
raise webob.exc.HTTPNotFound(
explanation=ex.format_message())
raise webob.exc.HTTPNotFound(ex.format_message())
req.response.status = 204
req.response.content_type = None
@ -126,14 +125,11 @@ def delete_trait(req):
trait = rp_obj.Trait.get_by_name(context, name)
trait.destroy()
except exception.TraitNotFound as ex:
raise webob.exc.HTTPNotFound(
explanation=ex.format_message())
raise webob.exc.HTTPNotFound(ex.format_message())
except exception.TraitCannotDeleteStandard as ex:
raise webob.exc.HTTPBadRequest(
explanation=ex.format_message())
raise webob.exc.HTTPBadRequest(ex.format_message())
except exception.TraitInUse as ex:
raise webob.exc.HTTPConflict(
explanation=ex.format_message())
raise webob.exc.HTTPConflict(ex.format_message())
req.response.status = 204
req.response.content_type = None
@ -155,8 +151,8 @@ def list_traits(req):
if 'associated' in req.GET:
if req.GET['associated'].lower() not in ['true', 'false']:
raise webob.exc.HTTPBadRequest(
explanation=_('The query parameter "associated" only accepts '
'"true" or "false"'))
_('The query parameter "associated" only accepts '
'"true" or "false"'))
filters['associated'] = (
True if req.GET['associated'].lower() == 'true' else False)
@ -256,7 +252,7 @@ def delete_traits_for_resource_provider(req):
try:
resource_provider.set_traits(rp_obj.TraitList(objects=[]))
except exception.ConcurrentUpdateDetected as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
raise webob.exc.HTTPConflict(e.format_message())
req.response.status = 204
req.response.content_type = None