diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index 06e88be73a..f7a1c982c9 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -168,7 +168,9 @@ class MetadataProxyHandler(object): if resp.status == 200: LOG.debug(str(resp)) - return content + req.response.content_type = resp['content-type'] + req.response.body = content + return req.response elif resp.status == 403: msg = _( 'The remote metadata server responded with Forbidden. This ' diff --git a/neutron/agent/metadata/namespace_proxy.py b/neutron/agent/metadata/namespace_proxy.py index c6addb8fee..ed9be8f0e9 100644 --- a/neutron/agent/metadata/namespace_proxy.py +++ b/neutron/agent/metadata/namespace_proxy.py @@ -19,7 +19,6 @@ import httplib import socket - import eventlet import httplib2 from oslo.config import cfg @@ -108,7 +107,11 @@ class NetworkMetadataProxyHandler(object): if resp.status == 200: LOG.debug(resp) LOG.debug(content) - return content + response = webob.Response() + response.status = resp.status + response.headers['Content-Type'] = resp['content-type'] + response.body = content + return response elif resp.status == 404: return webob.exc.HTTPNotFound() elif resp.status == 409: diff --git a/neutron/tests/unit/test_metadata_agent.py b/neutron/tests/unit/test_metadata_agent.py index 8a56b62a93..68cb2b9a28 100644 --- a/neutron/tests/unit/test_metadata_agent.py +++ b/neutron/tests/unit/test_metadata_agent.py @@ -200,10 +200,12 @@ class TestMetadataProxyHandler(base.BaseTestCase): req = mock.Mock(path_info='/the_path', query_string='', headers=hdrs, method=method, body=body) - resp = mock.Mock(status=response_code) + resp = mock.MagicMock(status=response_code) + req.response = resp with mock.patch.object(self.handler, '_sign_instance_id') as sign: sign.return_value = 'signed' with mock.patch('httplib2.Http') as mock_http: + resp.__getitem__.return_value = "text/plain" mock_http.return_value.request.return_value = (resp, 'content') retval = self.handler._proxy_request('the_id', 'tenant_id', @@ -225,11 +227,14 @@ class TestMetadataProxyHandler(base.BaseTestCase): return retval def test_proxy_request_post(self): - self.assertEqual('content', - self._proxy_request_test_helper(method='POST')) + response = self._proxy_request_test_helper(method='POST') + self.assertEqual(response.content_type, "text/plain") + self.assertEqual(response.body, 'content') def test_proxy_request_200(self): - self.assertEqual('content', self._proxy_request_test_helper(200)) + response = self._proxy_request_test_helper(200) + self.assertEqual(response.content_type, "text/plain") + self.assertEqual(response.body, 'content') def test_proxy_request_403(self): self.assertIsInstance(self._proxy_request_test_helper(403), diff --git a/neutron/tests/unit/test_metadata_namespace_proxy.py b/neutron/tests/unit/test_metadata_namespace_proxy.py index ad992d4dc0..26d7ba9df8 100644 --- a/neutron/tests/unit/test_metadata_namespace_proxy.py +++ b/neutron/tests/unit/test_metadata_namespace_proxy.py @@ -95,8 +95,9 @@ class TestNetworkMetadataProxyHandler(base.BaseTestCase): def test_proxy_request_router_200(self): self.handler.router_id = 'router_id' - resp = mock.Mock(status=200) + resp = mock.MagicMock(status=200) with mock.patch('httplib2.Http') as mock_http: + resp.__getitem__.return_value = "text/plain" mock_http.return_value.request.return_value = (resp, 'content') retval = self.handler._proxy_request('192.168.1.1', @@ -118,14 +119,16 @@ class TestNetworkMetadataProxyHandler(base.BaseTestCase): )] ) - self.assertEqual(retval, 'content') + self.assertEqual(retval.headers['Content-Type'], 'text/plain') + self.assertEqual(retval.body, 'content') def test_proxy_request_network_200(self): self.handler.network_id = 'network_id' - resp = mock.Mock(status=200) + resp = mock.MagicMock(status=200) with mock.patch('httplib2.Http') as mock_http: - mock_http.return_value.request.return_value = (resp, 'content') + resp.__getitem__.return_value = "application/json" + mock_http.return_value.request.return_value = (resp, '{}') retval = self.handler._proxy_request('192.168.1.1', 'GET', @@ -146,7 +149,9 @@ class TestNetworkMetadataProxyHandler(base.BaseTestCase): )] ) - self.assertEqual(retval, 'content') + self.assertEqual(retval.headers['Content-Type'], + 'application/json') + self.assertEqual(retval.body, '{}') def test_proxy_request_network_404(self): self.handler.network_id = 'network_id'