Adding the request id to response headers.
bp:nova-request-response-id Change-Id: Ie2d49337010f6e7a540018f9c8d542b6c8ebbce2
This commit is contained in:
parent
52cd737df4
commit
5165320257
@ -438,6 +438,9 @@ class ResponseHeadersSerializer(ActionDispatcher):
|
||||
|
||||
def serialize(self, response, data, action):
|
||||
self.dispatch(response, data, action=action)
|
||||
context = response.request.environ.get('nova.context')
|
||||
if context:
|
||||
response.headers['X-Compute-Request-Id'] = context.request_id
|
||||
|
||||
def default(self, response, data):
|
||||
response.status_int = 200
|
||||
@ -464,7 +467,7 @@ class ResponseSerializer(object):
|
||||
:param content_type: expected mimetype of serialized response body
|
||||
|
||||
"""
|
||||
response = webob.Response()
|
||||
response = webob.Response(request=request)
|
||||
self.serialize_headers(response, response_data, action)
|
||||
self.serialize_body(request, response, response_data, content_type,
|
||||
action)
|
||||
|
@ -5,7 +5,9 @@ import webob
|
||||
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from nova import utils
|
||||
from nova.api.openstack import wsgi
|
||||
import nova.context
|
||||
|
||||
|
||||
class RequestTest(test.TestCase):
|
||||
@ -97,7 +99,9 @@ class ActionDispatcherTest(test.TestCase):
|
||||
class ResponseHeadersSerializerTest(test.TestCase):
|
||||
def test_default(self):
|
||||
serializer = wsgi.ResponseHeadersSerializer()
|
||||
response = webob.Response()
|
||||
context = nova.context.get_admin_context()
|
||||
req = webob.Request.blank('/', environ={'nova.context': context})
|
||||
response = webob.Response(request=req)
|
||||
serializer.serialize(response, {'v': '123'}, 'asdf')
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
@ -107,7 +111,9 @@ class ResponseHeadersSerializerTest(test.TestCase):
|
||||
response.status_int = 404
|
||||
response.headers['X-Custom-Header'] = data['v']
|
||||
serializer = Serializer()
|
||||
response = webob.Response()
|
||||
context = nova.context.get_admin_context()
|
||||
req = webob.Request.blank('/', environ={'nova.context': context})
|
||||
response = webob.Response(request=req)
|
||||
serializer.serialize(response, {'v': '123'}, 'update')
|
||||
self.assertEqual(response.status_int, 404)
|
||||
self.assertEqual(response.headers['X-Custom-Header'], '123')
|
||||
@ -215,6 +221,17 @@ class RequestHeadersDeserializerTest(test.TestCase):
|
||||
self.assertEqual(deserializer.deserialize(req, 'update'), {'a': 'b'})
|
||||
|
||||
|
||||
class ResponseHeadersSerializerTest(test.TestCase):
|
||||
def test_request_id(self):
|
||||
serializer = wsgi.ResponseHeadersSerializer()
|
||||
context = nova.context.get_admin_context()
|
||||
req = webob.Request.blank('/', environ={'nova.context': context})
|
||||
res = webob.Response(request=req)
|
||||
serializer.serialize(res, {}, 'foo')
|
||||
self.assertTrue(
|
||||
utils.is_uuid_like(res.headers['X-Compute-Request-Id']))
|
||||
|
||||
|
||||
class JSONSerializer(object):
|
||||
def serialize(self, data, action='default'):
|
||||
return 'pew_json'
|
||||
|
Loading…
Reference in New Issue
Block a user