Files
nova/nova/api/openstack/placement/wsgi_wrapper.py
T
Pushkar Umaranikar 8cef55c53c Placement api: set custom json_error_formatter in allocations
Any time placement API (v1.0) code wants to raise a webob.exc of some kind it
needs to add a json_formatter attribute to the call. This is easy to forget.

This change adds wrapper for webob.dec.wsgify which will set default custom
json error formatter. Resource based actions from placement need to use this
wrapper as decorater instead of webob.dec.wsgify.

In this change, decorator updated for allocations related actions.
Change in other resource handlers can be addressed in subsequent patches.

Change-Id: I3b81c5bd00a013f1659b9e6e80c71b373d965862
Partial-Bug: #1635182
2017-02-09 16:19:18 +00:00

34 lines
1.2 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Extend functionality from webob.dec.wsgify for Placement API."""
import webob
from oslo_log import log as logging
from webob.dec import wsgify
from nova.api.openstack.placement import util
LOG = logging.getLogger(__name__)
class PlacementWsgify(wsgify):
def call_func(self, req, *args, **kwargs):
"""Add json_error_formatter to any webob HTTPExceptions."""
try:
super(PlacementWsgify, self).call_func(req, *args, **kwargs)
except webob.exc.HTTPException as exc:
LOG.debug("Placement API returning an error response: %s", exc)
exc.json_formatter = util.json_error_formatter
raise