Skip to content

Commit d7ee3ad

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix issue "SDKException: Connection failure that may be retried.""
2 parents 753c95c + b003c3d commit d7ee3ad

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

openstack/session.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def _get_version_match(self, versions, profile_version, service_type,
169169
* When an exact major/minor is specified, e.g., v2.0,
170170
it will only match v2.0.
171171
"""
172-
match = None
172+
173+
match_version = None
174+
173175
for version in versions:
174176
api_version = self._parse_version(version["id"])
175177
if profile_version.major != api_version.major:
@@ -178,23 +180,22 @@ def _get_version_match(self, versions, profile_version, service_type,
178180
if profile_version.minor <= api_version.minor:
179181
for link in version["links"]:
180182
if link["rel"] == "self":
181-
match = link["href"]
183+
resp_link = link['href']
184+
match_version = parse.urlsplit(resp_link).path
182185

183186
# Only break out of the loop on an exact match,
184187
# otherwise keep trying.
185188
if profile_version.minor == api_version.minor:
186189
break
187190

188-
if match is None:
191+
if match_version is None:
189192
raise exceptions.EndpointNotFound(
190193
"Unable to determine endpoint for %s" % service_type)
191194

192-
# Some services return only the path fragment of a URI.
193-
# If we split and see that we're not given the scheme and netloc,
194-
# construct the match with the root from the service catalog.
195-
match_split = parse.urlsplit(match)
196-
if not all([match_split.scheme, match_split.netloc]):
197-
match = root_endpoint + match
195+
# Make sure "root_endpoint" has no overlap with match_version
196+
root_parts = parse.urlsplit(root_endpoint)
197+
match_version = match_version.replace(root_parts.path, "", 1)
198+
match = utils.urljoin(root_endpoint, match_version)
198199

199200
# For services that require the project id in the request URI,
200201
# add them in here.

openstack/tests/unit/test_session.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from openstack import exceptions
1919
from openstack import profile
2020
from openstack import session
21+
from openstack import utils
2122

2223

2324
class TestSession(testtools.TestCase):
@@ -166,7 +167,8 @@ def test__get_version_match_none(self):
166167
sot._get_version_match, [], None, "service", "root", False)
167168

168169
def test__get_version_match_fuzzy(self):
169-
match = "http://devstack/v2.1/"
170+
match = "http://devstack/v2.1"
171+
root_endpoint = "http://devstack"
170172
versions = [{"id": "v2.0",
171173
"links": [{"href": "http://devstack/v2/",
172174
"rel": "self"}]},
@@ -178,11 +180,12 @@ def test__get_version_match_fuzzy(self):
178180
# Look for a v2 match, which we internally denote as a minor
179181
# version of -1 so we can find the highest matching minor.
180182
rv = sot._get_version_match(versions, session.Version(2, -1),
181-
"service", "root", False)
183+
"service", root_endpoint, False)
182184
self.assertEqual(rv, match)
183185

184186
def test__get_version_match_exact(self):
185-
match = "http://devstack/v2/"
187+
match = "http://devstack/v2"
188+
root_endpoint = "http://devstack"
186189
versions = [{"id": "v2.0",
187190
"links": [{"href": match,
188191
"rel": "self"}]},
@@ -192,12 +195,12 @@ def test__get_version_match_exact(self):
192195

193196
sot = session.Session(None)
194197
rv = sot._get_version_match(versions, session.Version(2, 0),
195-
"service", "root", False)
198+
"service", root_endpoint, False)
196199
self.assertEqual(rv, match)
197200

198201
def test__get_version_match_fragment(self):
199202
root = "http://cloud.net"
200-
match = "/v2/"
203+
match = "/v2"
201204
versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}]
202205

203206
sot = session.Session(None)
@@ -206,15 +209,17 @@ def test__get_version_match_fragment(self):
206209
self.assertEqual(rv, root+match)
207210

208211
def test__get_version_match_project_id(self):
209-
match = "http://devstack/v2/"
212+
match = "http://devstack/v2"
213+
root_endpoint = "http://devstack"
210214
project_id = "asdf123"
211215
versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}]
212216

213217
sot = session.Session(None)
214218
sot.get_project_id = mock.Mock(return_value=project_id)
215219
rv = sot._get_version_match(versions, session.Version(2, 0),
216-
"service", "root", True)
217-
self.assertEqual(rv, match + project_id)
220+
"service", root_endpoint, True)
221+
match_endpoint = utils.urljoin(match, project_id)
222+
self.assertEqual(rv, match_endpoint)
218223

219224
def test_get_endpoint_cached(self):
220225
sot = session.Session(None)

0 commit comments

Comments
 (0)