Neutron namespace proxy handler and metadata agent were not setting the
Content-Type in its response. Both of them were returning only the response
data which is obtained from the nova-metadata-service. Since they were returning
only the response data, the Content-Type returned to the clients has the default
one which is - "text/html". Ideally this should be set to the data type which is
present in the HTTP Response. The fix now includes the Content-Type which is
returned by nova-metadata-service
Closes-Bug: #
1243878
Change-Id: If68f0b508fbea4ecd1eb0e58d602b5ba6ccbe263
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 '
import httplib
import socket
-
import eventlet
import httplib2
from oslo.config import cfg
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:
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',
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),
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',
)]
)
- 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',
)]
)
- 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'