Use status_code instead of status in requests

It fixes raising exception for response with not recognized
status code.

Co-Authored-By: Brian Haley <haleyb.dev@gmail.com>
Change-Id: I174ff62cb6599e4c7bdc86cb2d0786f9f2499b00
Related-Bug: 1790598
(cherry picked from commit 1685982a97)
This commit is contained in:
Pawel Suder 2019-01-17 07:30:45 +01:00 committed by Paweł Suder
parent 886782c177
commit 9f003cf497
2 changed files with 3 additions and 1 deletions

View File

@ -231,7 +231,8 @@ class MetadataProxyHandler(object):
explanation = six.text_type(msg)
return webob.exc.HTTPInternalServerError(explanation=explanation)
else:
raise Exception(_('Unexpected response code: %s') % resp.status)
raise Exception(_('Unexpected response code: %s') %
resp.status_code)
def _sign_instance_id(self, instance_id):
secret = self.conf.metadata_proxy_shared_secret

View File

@ -340,6 +340,7 @@ class _TestMetadataProxyHandlerCacheMixin(object):
req = mock.Mock(path_info='/the_path', query_string='', headers=hdrs,
method=method, body=body)
resp = mock.MagicMock(status_code=response_code)
resp.status.__str__.side_effect = AttributeError
resp.content = 'content'
req.response = resp
with mock.patch.object(self.handler, '_sign_instance_id') as sign: