Browse Source

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
tags/3.11.1^0
Dmitry Tantsur 7 months ago
parent
commit
72288d3b18
2 changed files with 16 additions and 9 deletions
  1. 7
    7
      keystoneauth1/discover.py
  2. 9
    2
      keystoneauth1/tests/unit/test_discovery.py

+ 7
- 7
keystoneauth1/discover.py View File

@@ -119,6 +119,13 @@ def get_version_data(session, url, authenticated=None):
119 119
         except KeyError:
120 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 129
         # Older Ironic does not actually return a discovery document for the
123 130
         # single version discovery endpoint, which confuses the single-version
124 131
         # fallback logic. While there are no known other services returning
@@ -141,13 +148,6 @@ def get_version_data(session, url, authenticated=None):
141 148
                     body_resp.setdefault('version', resp.headers[header])
142 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 151
     err_text = resp.text[:50] + '...' if len(resp.text) > 50 else resp.text
152 152
     raise exceptions.DiscoveryFailure('Invalid Response - Bad version data '
153 153
                                       'returned: %s' % err_text)

+ 9
- 2
keystoneauth1/tests/unit/test_discovery.py View File

@@ -590,11 +590,18 @@ class VersionDataTests(utils.TestCase):
590 590
             ironic_url, status_code=200,
591 591
             json={
592 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 602
                 'links': [{
594 603
                     "href": ironic_url,
595 604
                     "rel": "self"}],
596
-                'version': '1.40',
597
-                'min_version': '1.10',
598 605
             },
599 606
             # Keep headers so we can verify that body trumps headers
600 607
             headers={

Loading…
Cancel
Save