summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2018-11-30 12:39:58 -0600
committerMonty Taylor <mordred@inaugust.com>2018-11-30 13:09:32 -0600
commit4960c48aec24e7d1b0f436a704d63b9ec9b6b805 (patch)
tree7b97c08202157ee44708843f4cba20c1b8ec5d93
parentd8cee933fe4febbd58474e3be17e29e9ada5c56c (diff)
Fix version discovery for clouds with int project_ids3.11.2
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
Notes
Notes (review): Code-Review+2: Colleen Murphy <colleen@gazlene.net> 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: Sat, 01 Dec 2018 16:25:41 +0000 Reviewed-on: https://review.openstack.org/621257 Project: openstack/keystoneauth Branch: refs/heads/master
-rw-r--r--keystoneauth1/discover.py6
-rw-r--r--keystoneauth1/tests/unit/test_discovery.py5
2 files changed, 11 insertions, 0 deletions
diff --git a/keystoneauth1/discover.py b/keystoneauth1/discover.py
index eb7ebf9..97321a1 100644
--- a/keystoneauth1/discover.py
+++ b/keystoneauth1/discover.py
@@ -473,6 +473,12 @@ def _version_from_url(url):
473 url = urllib.parse.urlparse(url) 473 url = urllib.parse.urlparse(url)
474 for part in reversed(url.path.split('/')): 474 for part in reversed(url.path.split('/')):
475 try: 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 return normalize_version_number(part) 482 return normalize_version_number(part)
477 except Exception: 483 except Exception:
478 pass 484 pass
diff --git a/keystoneauth1/tests/unit/test_discovery.py b/keystoneauth1/tests/unit/test_discovery.py
index 024efc6..9972eb3 100644
--- a/keystoneauth1/tests/unit/test_discovery.py
+++ b/keystoneauth1/tests/unit/test_discovery.py
@@ -1257,3 +1257,8 @@ class EndpointDataTests(utils.TestCase):
1257 self.assertEqual(exp, str(epd)) 1257 self.assertEqual(exp, str(epd))
1258 # Works with implicit stringification 1258 # Works with implicit stringification
1259 self.assertEqual(exp, "%s" % epd) 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)