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:
Grzegorz Grasza 2022-11-23 15:58:22 +01:00
parent 11faa0e67d
commit 5098d45cca
2 changed files with 10 additions and 3 deletions

View File

@ -58,7 +58,7 @@ def _int_or_latest(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.
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 bool authenticated: Include a token in the discovery call.
(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.
:rtype: list(dict)
headers = {'Accept': 'application/json'}
if version_header:
headers['OpenStack-API-Version'] = version_header
resp = session.get(url, headers=headers, authenticated=authenticated)

View File

@ -1321,7 +1321,8 @@ class EndpointDataTests(utils.TestCase):
def test_run_discovery_auth(self):
url = ''
headers = {'Accept': 'application/json'}
headers = {'Accept': 'application/json',
'OpenStack-API-Version': 'version header test'}
session = mock.Mock()
session.get.side_effect = [
@ -1332,7 +1333,8 @@ class EndpointDataTests(utils.TestCase):
discover.get_version_data(session, url)
session, url, version_header='version header test')
except exceptions.BadRequest:
# Only one call with 'url'