return request_id in case of 500 error

Request-id is not getting returned if glance throws 500 error
because context middleware 'process_response' method is not
getting called.

Catching generic exception in wsgi Resource class, and returning
'webob.exc.HTTPInternalServerError' object as response.
Context middleware adds request-id header to this response object.

Closes-Bug: #1480196

Change-Id: I5ed9f64e07c5624f816088113ff67cb03cc8e3f2
This commit is contained in:
Abhijeet Malawade 2015-07-28 02:37:16 -07:00
parent 419a9bb440
commit f660846f7a
2 changed files with 23 additions and 0 deletions

View File

@ -882,6 +882,10 @@ class Resource(object):
except webob.exc.WSGIHTTPException as e:
exc_info = sys.exc_info()
six.reraise(translate_exception(request, e), None, exc_info[2])
except Exception as e:
LOG.exception(_LE("Caught error: %s"), six.text_type(e))
response = webob.exc.HTTPInternalServerError()
return response
try:
response = webob.Response(request=request)

View File

@ -317,6 +317,25 @@ class ResourceTest(test_utils.BaseTestCase):
self.assertIsInstance(response, webob.exc.HTTPForbidden)
self.assertEqual(403, response.status_code)
def test_call_raises_exception(self):
class FakeController(object):
def index(self, shirt, pants=None):
return (shirt, pants)
resource = wsgi.Resource(FakeController(), None, None)
def dispatch(self, obj, action, *args, **kwargs):
raise Exception("test exception")
self.stubs.Set(wsgi.Resource, 'dispatch', dispatch)
request = wsgi.Request.blank('/')
response = resource.__call__(request)
self.assertIsInstance(response, webob.exc.HTTPInternalServerError)
self.assertEqual(500, response.status_code)
@mock.patch.object(wsgi, 'translate_exception')
def test_resource_call_error_handle_localized(self,
mock_translate_exception):