Make new-style single endpoint version discovery actually work for ironic

For (unclear) historical reasons the root single version endpoint also
contains "id" and "links" fields. This makes the current workaround
for old-style endpoints take priority over the correct algorithm.
This change reorders the code, so that if "version" is present, it
always take priority over the workaround.

The unit tests are updated to be closer to real output from ironic.

Change-Id: I743b954c6c5b2f986c213acb6ec6af7e08c9f5f8
This commit is contained in:
Dmitry Tantsur 2018-10-23 14:26:34 +02:00
parent 87ca0d72fa
commit 72288d3b18
2 changed files with 16 additions and 9 deletions

View File

@ -119,6 +119,13 @@ def get_version_data(session, url, authenticated=None):
except KeyError:
pass
# Otherwise if we query an endpoint like /v2.0 then we will get back
# just the one available version.
try:
return [body_resp['version']]
except KeyError:
pass
# Older Ironic does not actually return a discovery document for the
# single version discovery endpoint, which confuses the single-version
# fallback logic. While there are no known other services returning
@ -141,13 +148,6 @@ def get_version_data(session, url, authenticated=None):
body_resp.setdefault('version', resp.headers[header])
return [body_resp]
# Otherwise if we query an endpoint like /v2.0 then we will get back
# just the one available version.
try:
return [body_resp['version']]
except KeyError:
pass
err_text = resp.text[:50] + '...' if len(resp.text) > 50 else resp.text
raise exceptions.DiscoveryFailure('Invalid Response - Bad version data '
'returned: %s' % err_text)

View File

@ -590,11 +590,18 @@ class VersionDataTests(utils.TestCase):
ironic_url, status_code=200,
json={
'id': 'v1',
'version': {
'id': 'v1',
'links': [{
"href": ironic_url,
"rel": "self"}],
'version': '1.40',
'min_version': '1.10',
'status': 'CURRENT',
},
'links': [{
"href": ironic_url,
"rel": "self"}],
'version': '1.40',
'min_version': '1.10',
},
# Keep headers so we can verify that body trumps headers
headers={