Browse Source

Fix version discovery for clouds with int project_ids

On a cloud that has inaccessible version discovery documents AND uses
integer project ids, the discovery fallback logic can fail because the
project id parses as a (very large) version.

Check to see that the url segment in the fallback code begins with a v,
so that we're only attempting to parse versions from actual candidate
segments.

Closes-Bug: #1806109
Change-Id: Id90b3b9e4852494a4678b0a9bb67362babdc971c
tags/3.11.2^0
Monty Taylor 5 months ago
parent
commit
4960c48aec
No account linked to committer's email address
2 changed files with 11 additions and 0 deletions
  1. 6
    0
      keystoneauth1/discover.py
  2. 5
    0
      keystoneauth1/tests/unit/test_discovery.py

+ 6
- 0
keystoneauth1/discover.py View File

@@ -473,6 +473,12 @@ def _version_from_url(url):
473 473
     url = urllib.parse.urlparse(url)
474 474
     for part in reversed(url.path.split('/')):
475 475
         try:
476
+            # All integer project ids can parse as valid versions. In URLs
477
+            # all known instances of versions start with a v. So check to make
478
+            # sure the url part starts with 'v', then check that it parses
479
+            # as a valid version.
480
+            if part[0] != 'v':
481
+                continue
476 482
             return normalize_version_number(part)
477 483
         except Exception:
478 484
             pass

+ 5
- 0
keystoneauth1/tests/unit/test_discovery.py View File

@@ -1257,3 +1257,8 @@ class EndpointDataTests(utils.TestCase):
1257 1257
         self.assertEqual(exp, str(epd))
1258 1258
         # Works with implicit stringification
1259 1259
         self.assertEqual(exp, "%s" % epd)
1260
+
1261
+    def test_project_id_int_fallback(self):
1262
+        bad_url = "https://compute.example.com/v2/123456"
1263
+        epd = discover.EndpointData(catalog_url=bad_url)
1264
+        self.assertEqual((2, 0), epd.api_version)

Loading…
Cancel
Save