Allow passing of version header
Add keyword option to get_version_data() to allow passing of the version header so that we can get the microversions. Specifically, this is so that we can re-use this function in barbican, which recently implemented microversions, but doesn't return them by default, for backward compatibility with old clients. Change-Id: I909750381a559f9dc61650c9f98c88d4481012b7
This commit is contained in:
parent
11faa0e67d
commit
5098d45cca
@ -58,7 +58,7 @@ def _int_or_latest(val):
|
|||||||
return LATEST if val == 'latest' or val == LATEST else int(val)
|
return LATEST if val == 'latest' or val == LATEST else int(val)
|
||||||
|
|
||||||
|
|
||||||
def get_version_data(session, url, authenticated=None):
|
def get_version_data(session, url, authenticated=None, version_header=None):
|
||||||
"""Retrieve raw version data from a url.
|
"""Retrieve raw version data from a url.
|
||||||
|
|
||||||
The return is a list of dicts of the form::
|
The return is a list of dicts of the form::
|
||||||
@ -93,10 +93,15 @@ def get_version_data(session, url, authenticated=None):
|
|||||||
:param string url: Endpoint or discovery URL from which to retrieve data.
|
:param string url: Endpoint or discovery URL from which to retrieve data.
|
||||||
:param bool authenticated: Include a token in the discovery call.
|
:param bool authenticated: Include a token in the discovery call.
|
||||||
(optional) Defaults to None.
|
(optional) Defaults to None.
|
||||||
|
:param string version_header: provide the OpenStack-API-Version header
|
||||||
|
for services which don't return version information without it, for
|
||||||
|
backward compatibility.
|
||||||
:return: A list of dicts containing version information.
|
:return: A list of dicts containing version information.
|
||||||
:rtype: list(dict)
|
:rtype: list(dict)
|
||||||
"""
|
"""
|
||||||
headers = {'Accept': 'application/json'}
|
headers = {'Accept': 'application/json'}
|
||||||
|
if version_header:
|
||||||
|
headers['OpenStack-API-Version'] = version_header
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = session.get(url, headers=headers, authenticated=authenticated)
|
resp = session.get(url, headers=headers, authenticated=authenticated)
|
||||||
|
@ -1321,7 +1321,8 @@ class EndpointDataTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_run_discovery_auth(self):
|
def test_run_discovery_auth(self):
|
||||||
url = 'https://example.com'
|
url = 'https://example.com'
|
||||||
headers = {'Accept': 'application/json'}
|
headers = {'Accept': 'application/json',
|
||||||
|
'OpenStack-API-Version': 'version header test'}
|
||||||
|
|
||||||
session = mock.Mock()
|
session = mock.Mock()
|
||||||
session.get.side_effect = [
|
session.get.side_effect = [
|
||||||
@ -1332,7 +1333,8 @@ class EndpointDataTests(utils.TestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
discover.get_version_data(session, url)
|
discover.get_version_data(
|
||||||
|
session, url, version_header='version header test')
|
||||||
except exceptions.BadRequest:
|
except exceptions.BadRequest:
|
||||||
pass
|
pass
|
||||||
# Only one call with 'url'
|
# Only one call with 'url'
|
||||||
|
Loading…
Reference in New Issue
Block a user