diff options
| author | Naveed Massjouni <naveedm9@gmail.com> | 2012-02-07 17:06:13 +0000 |
|---|---|---|
| committer | Naveed Massjouni <naveedm9@gmail.com> | 2012-02-07 17:09:04 +0000 |
| commit | 7eca1aed7db7d3d60192f88aaecc43f8001106ec (patch) | |
| tree | e5b2cc41b16979afbe6e927fb45cd2a35d1861e2 | |
| parent | bedef20b4fdaa678017390afd616a4db41e6d949 (diff) | |
| download | nova-7eca1aed7db7d3d60192f88aaecc43f8001106ec.tar.gz nova-7eca1aed7db7d3d60192f88aaecc43f8001106ec.tar.xz nova-7eca1aed7db7d3d60192f88aaecc43f8001106ec.zip | |
Adding the request id to response headers. Again.
This feature used to exist in nova. A major refactor inadvertently
removed it.
Change-Id: Ie9b658bef808f3b5959b85f731483a2df59a5ede
bp: nova-request-response-id
| -rw-r--r-- | nova/api/openstack/wsgi.py | 6 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_api.py | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index af62f9b28..ecfdd1ac7 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -819,8 +819,8 @@ class Resource(wsgi.Application): action_args.update(contents) project_id = action_args.pop("project_id", None) - if ('nova.context' in request.environ and project_id - and project_id != request.environ['nova.context'].project_id): + context = request.environ.get('nova.context') + if (context and project_id and (project_id != context.project_id)): msg = _("Malformed request url") return Fault(webob.exc.HTTPBadRequest(explanation=msg)) @@ -848,6 +848,8 @@ class Resource(wsgi.Application): # Run post-processing extensions if resp_obj: + if context: + resp_obj['x-compute-request-id'] = context.request_id # Do a preserialize to set up the response object serializers = getattr(meth, 'wsgi_serializers', {}) resp_obj._bind_method_serializers(serializers) diff --git a/nova/tests/api/openstack/compute/test_api.py b/nova/tests/api/openstack/compute/test_api.py index dbb187c40..914a45af5 100644 --- a/nova/tests/api/openstack/compute/test_api.py +++ b/nova/tests/api/openstack/compute/test_api.py @@ -22,6 +22,7 @@ import webob.exc import webob.dec from webob import Request +import nova.context from nova import test from nova.api import openstack as openstack_api from nova.api.openstack import wsgi @@ -119,3 +120,13 @@ class APITest(test.TestCase): resp = Request.blank('/.xml').get_response(api) self.assertTrue('<computeFault' in resp.body, resp.body) self.assertEqual(resp.status_int, 500, resp.body) + + def test_request_id_in_response(self): + req = webob.Request.blank('/') + req.method = 'GET' + context = nova.context.RequestContext('bob', 1) + context.request_id = 'test-req-id' + req.environ['nova.context'] = context + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.headers['x-compute-request-id'], 'test-req-id') |
