From dddee4189c0789565d1bb0328ef03fab3fb6a45a Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Tue, 15 May 2018 13:44:59 +0200 Subject: [PATCH] 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 90d2dbedefbcc99a20a6a86888ef1d316d5d119f) --- .../openstack/placement/handlers/inventory.py | 2 +- nova/api/openstack/placement/handlers/trait.py | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/nova/api/openstack/placement/handlers/inventory.py b/nova/api/openstack/placement/handlers/inventory.py index 93637f1d22b8..a2afc1fe94de 100644 --- a/nova/api/openstack/placement/handlers/inventory.py +++ b/nova/api/openstack/placement/handlers/inventory.py @@ -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 diff --git a/nova/api/openstack/placement/handlers/trait.py b/nova/api/openstack/placement/handlers/trait.py index 558020100c63..d105c5ced4f3 100644 --- a/nova/api/openstack/placement/handlers/trait.py +++ b/nova/api/openstack/placement/handlers/trait.py @@ -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