From 72288d3b18e66da3e04c35f60ab43c916b92c59a Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 23 Oct 2018 14:26:34 +0200 Subject: [PATCH] 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 --- keystoneauth1/discover.py | 14 +++++++------- keystoneauth1/tests/unit/test_discovery.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/keystoneauth1/discover.py b/keystoneauth1/discover.py index f03ffbfd..5040a6b3 100644 --- a/keystoneauth1/discover.py +++ b/keystoneauth1/discover.py @@ -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) diff --git a/keystoneauth1/tests/unit/test_discovery.py b/keystoneauth1/tests/unit/test_discovery.py index 241afe55..024efc62 100644 --- a/keystoneauth1/tests/unit/test_discovery.py +++ b/keystoneauth1/tests/unit/test_discovery.py @@ -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={