From edcf4eca66c91db032bdb56572eba4437947948d Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Fri, 31 May 2013 11:55:30 -0400 Subject: Add x-compute-request-id header when no response body The x-compute-request-id header was only being added for requests which generated a response body, like an index or show. This adds it to requests which generate no response body, like create/update/delete, or actions on servers like resize. Bug 1183712 Change-Id: Ia0e9d75e4b84280caab060fae58036ed818e00c3 --- nova/tests/api/openstack/test_wsgi.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py index 4c10ec6b6..41a80a65c 100644 --- a/nova/tests/api/openstack/test_wsgi.py +++ b/nova/tests/api/openstack/test_wsgi.py @@ -449,6 +449,49 @@ class ResourceTest(test.TestCase): self.assertEqual(content_type, 'application/json') self.assertEqual(body, 'foo') + def test_get_request_id_with_dict_response_body(self): + class Controller(wsgi.Controller): + def index(self, req): + return {'foo': 'bar'} + + req = fakes.HTTPRequest.blank('/tests') + context = req.environ['nova.context'] + app = fakes.TestRouter(Controller()) + response = req.get_response(app) + self.assertEqual(response.headers['x-compute-request-id'], + context.request_id) + self.assertEqual(response.body, '{"foo": "bar"}') + self.assertEqual(response.status_int, 200) + + def test_no_request_id_with_str_response_body(self): + class Controller(wsgi.Controller): + def index(self, req): + return 'foo' + + req = fakes.HTTPRequest.blank('/tests') + app = fakes.TestRouter(Controller()) + response = req.get_response(app) + # NOTE(alaski): This test is really to ensure that a str response + # doesn't error. Not having a request_id header is a side effect of + # our wsgi setup, ideally it would be there. + self.assertFalse(hasattr(response.headers, 'x-compute-request-id')) + self.assertEqual(response.body, 'foo') + self.assertEqual(response.status_int, 200) + + def test_get_request_id_no_response_body(self): + class Controller(object): + def index(self, req): + pass + + req = fakes.HTTPRequest.blank('/tests') + context = req.environ['nova.context'] + app = fakes.TestRouter(Controller()) + response = req.get_response(app) + self.assertEqual(response.headers['x-compute-request-id'], + context.request_id) + self.assertEqual(response.body, '') + self.assertEqual(response.status_int, 200) + def test_deserialize_badtype(self): class Controller(object): def index(self, req, pants=None): -- cgit