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

Closes-Bug: #1806109
Change-Id: Id90b3b9e4852494a4678b0a9bb67362babdc971c
changes/57/621257/3 3.11.2
Monty Taylor 5 years ago
parent d8cee933fe
commit 4960c48aec
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594

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

@ -1257,3 +1257,8 @@ class EndpointDataTests(utils.TestCase):
self.assertEqual(exp, str(epd))
# Works with implicit stringification
self.assertEqual(exp, "%s" % epd)
def test_project_id_int_fallback(self):
bad_url = ""
epd = discover.EndpointData(catalog_url=bad_url)
self.assertEqual((2, 0), epd.api_version)