Merge "Include OData-Version header in Redfish requests"
This commit is contained in:
commit
c209cb805a
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Improve interoperability by including the recommended OData-Version
|
||||||
|
header in outgoing Redfish requests.
|
|
@ -71,6 +71,9 @@ class Connector(object):
|
||||||
:raises: HTTPError
|
:raises: HTTPError
|
||||||
"""
|
"""
|
||||||
url = parse.urljoin(self._url, path)
|
url = parse.urljoin(self._url, path)
|
||||||
|
headers = headers or {}
|
||||||
|
if not any(k.lower() == 'odata-version' for k in headers):
|
||||||
|
headers['OData-Version'] = '4.0'
|
||||||
# TODO(lucasagomes): We should mask the data to remove sensitive
|
# TODO(lucasagomes): We should mask the data to remove sensitive
|
||||||
# information
|
# information
|
||||||
LOG.debug('HTTP request: %(method)s %(url)s; headers: %(headers)s; '
|
LOG.debug('HTTP request: %(method)s %(url)s; headers: %(headers)s; '
|
||||||
|
|
|
@ -146,15 +146,18 @@ class ConnectorOpTestCase(base.TestCase):
|
||||||
json=self.data, headers=self.headers)
|
json=self.data, headers=self.headers)
|
||||||
|
|
||||||
def test_ok_delete(self):
|
def test_ok_delete(self):
|
||||||
|
expected_headers = self.headers.copy()
|
||||||
|
expected_headers['OData-Version'] = '4.0'
|
||||||
self.conn._op('DELETE', path='fake/path', headers=self.headers.copy())
|
self.conn._op('DELETE', path='fake/path', headers=self.headers.copy())
|
||||||
self.request.assert_called_once_with(
|
self.request.assert_called_once_with(
|
||||||
'DELETE', 'http://foo.bar:1234/fake/path',
|
'DELETE', 'http://foo.bar:1234/fake/path',
|
||||||
headers=self.headers, json=None)
|
headers=expected_headers, json=None)
|
||||||
|
|
||||||
def test_ok_post_with_session(self):
|
def test_ok_post_with_session(self):
|
||||||
self.conn._session.headers = {}
|
self.conn._session.headers = {}
|
||||||
self.conn._session.headers['X-Auth-Token'] = 'asdf1234'
|
self.conn._session.headers['X-Auth-Token'] = 'asdf1234'
|
||||||
expected_headers = self.headers.copy()
|
expected_headers = self.headers.copy()
|
||||||
|
expected_headers['OData-Version'] = '4.0'
|
||||||
self.conn._op('POST', path='fake/path', headers=self.headers,
|
self.conn._op('POST', path='fake/path', headers=self.headers,
|
||||||
data=self.data)
|
data=self.data)
|
||||||
self.request.assert_called_once_with(
|
self.request.assert_called_once_with(
|
||||||
|
@ -163,6 +166,34 @@ class ConnectorOpTestCase(base.TestCase):
|
||||||
self.assertEqual(self.conn._session.headers,
|
self.assertEqual(self.conn._session.headers,
|
||||||
{'X-Auth-Token': 'asdf1234'})
|
{'X-Auth-Token': 'asdf1234'})
|
||||||
|
|
||||||
|
def test_odata_version_header_redfish(self):
|
||||||
|
path = '/redfish/v1/path'
|
||||||
|
headers = dict(self.headers)
|
||||||
|
expected_headers = dict(self.headers)
|
||||||
|
expected_headers['OData-Version'] = '4.0'
|
||||||
|
self.request.reset_mock()
|
||||||
|
self.conn._op('GET', path=path, headers=headers)
|
||||||
|
self.request.assert_called_once_with(
|
||||||
|
'GET', 'http://foo.bar:1234' + path,
|
||||||
|
headers=expected_headers, json=None)
|
||||||
|
|
||||||
|
def test_odata_version_header_redfish_no_headers(self):
|
||||||
|
path = '/redfish/v1/bar'
|
||||||
|
expected_headers = {'OData-Version': '4.0'}
|
||||||
|
self.conn._op('GET', path=path)
|
||||||
|
self.request.assert_called_once_with(
|
||||||
|
'GET', 'http://foo.bar:1234' + path,
|
||||||
|
headers=expected_headers, json=None)
|
||||||
|
|
||||||
|
def test_odata_version_header_redfish_existing_header(self):
|
||||||
|
path = '/redfish/v1/foo'
|
||||||
|
headers = {'OData-Version': '3.0'}
|
||||||
|
expected_headers = dict(headers)
|
||||||
|
self.conn._op('GET', path=path, headers=headers)
|
||||||
|
self.request.assert_called_once_with(
|
||||||
|
'GET', 'http://foo.bar:1234' + path,
|
||||||
|
headers=expected_headers, json=None)
|
||||||
|
|
||||||
def test_timed_out_session_unable_to_create_session(self):
|
def test_timed_out_session_unable_to_create_session(self):
|
||||||
self.conn._auth.can_refresh_session.return_value = False
|
self.conn._auth.can_refresh_session.return_value = False
|
||||||
self.conn._session = self.session
|
self.conn._session = self.session
|
||||||
|
|
Loading…
Reference in New Issue