summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2018-10-23 14:26:34 +0200
committerDmitry Tantsur <divius.inside@gmail.com>2018-10-23 14:26:34 +0200
commit72288d3b18e66da3e04c35f60ab43c916b92c59a (patch)
treec172f7cc96e42df908106ad565cc4308906d9732
parent87ca0d72fa7de93089f77974f26e497533a46be5 (diff)
Make new-style single endpoint version discovery actually work for ironic3.11.1
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
Notes
Notes (review): Code-Review+1: Julia Kreger <juliaashleykreger@gmail.com> Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+2: Morgan Fainberg <morgan.fainberg@gmail.com> Workflow+1: Morgan Fainberg <morgan.fainberg@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 23 Oct 2018 17:06:14 +0000 Reviewed-on: https://review.openstack.org/612680 Project: openstack/keystoneauth Branch: refs/heads/master
-rw-r--r--keystoneauth1/discover.py14
-rw-r--r--keystoneauth1/tests/unit/test_discovery.py11
2 files changed, 16 insertions, 9 deletions
diff --git a/keystoneauth1/discover.py b/keystoneauth1/discover.py
index f03ffbf..5040a6b 100644
--- a/keystoneauth1/discover.py
+++ b/keystoneauth1/discover.py
@@ -119,6 +119,13 @@ def get_version_data(session, url, authenticated=None):
119 except KeyError: 119 except KeyError:
120 pass 120 pass
121 121
122 # Otherwise if we query an endpoint like /v2.0 then we will get back
123 # just the one available version.
124 try:
125 return [body_resp['version']]
126 except KeyError:
127 pass
128
122 # Older Ironic does not actually return a discovery document for the 129 # Older Ironic does not actually return a discovery document for the
123 # single version discovery endpoint, which confuses the single-version 130 # single version discovery endpoint, which confuses the single-version
124 # fallback logic. While there are no known other services returning 131 # fallback logic. While there are no known other services returning
@@ -141,13 +148,6 @@ def get_version_data(session, url, authenticated=None):
141 body_resp.setdefault('version', resp.headers[header]) 148 body_resp.setdefault('version', resp.headers[header])
142 return [body_resp] 149 return [body_resp]
143 150
144 # Otherwise if we query an endpoint like /v2.0 then we will get back
145 # just the one available version.
146 try:
147 return [body_resp['version']]
148 except KeyError:
149 pass
150
151 err_text = resp.text[:50] + '...' if len(resp.text) > 50 else resp.text 151 err_text = resp.text[:50] + '...' if len(resp.text) > 50 else resp.text
152 raise exceptions.DiscoveryFailure('Invalid Response - Bad version data ' 152 raise exceptions.DiscoveryFailure('Invalid Response - Bad version data '
153 'returned: %s' % err_text) 153 'returned: %s' % err_text)
diff --git a/keystoneauth1/tests/unit/test_discovery.py b/keystoneauth1/tests/unit/test_discovery.py
index 241afe5..024efc6 100644
--- a/keystoneauth1/tests/unit/test_discovery.py
+++ b/keystoneauth1/tests/unit/test_discovery.py
@@ -590,11 +590,18 @@ class VersionDataTests(utils.TestCase):
590 ironic_url, status_code=200, 590 ironic_url, status_code=200,
591 json={ 591 json={
592 'id': 'v1', 592 'id': 'v1',
593 'version': {
594 'id': 'v1',
595 'links': [{
596 "href": ironic_url,
597 "rel": "self"}],
598 'version': '1.40',
599 'min_version': '1.10',
600 'status': 'CURRENT',
601 },
593 'links': [{ 602 'links': [{
594 "href": ironic_url, 603 "href": ironic_url,
595 "rel": "self"}], 604 "rel": "self"}],
596 'version': '1.40',
597 'min_version': '1.10',
598 }, 605 },
599 # Keep headers so we can verify that body trumps headers 606 # Keep headers so we can verify that body trumps headers
600 headers={ 607 headers={