Fix broken version discovery endpoints

In the version discovery spec, it is noted that both schema and netloc
on endpoints reported by version discovery documents are known to be
able to be broken, but shade was only fixing scheme. Update the code to
do the right thing. Also, add a test to ensure that this behavior occurs
correctly. While we're in the tests for this, have the discovery call
return a 300, which is what it returns. There are no bugs in this area,
but 300 is correct so we should test it that way.

Story: 2001027
Change-Id: Id04f6f033c9277e791b602f193d1eaf6ac73047f
This commit is contained in:
Monty Taylor 2017-05-15 10:46:21 -05:00
parent e1dfc7228d
commit 40f66c70c3
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
4 changed files with 89 additions and 1 deletions

View File

@ -469,7 +469,7 @@ class OpenStackCloud(
return urllib.parse.ParseResult(
catalog_endpoint.scheme,
discovered_endpoint.netloc,
catalog_endpoint.netloc,
discovered_endpoint.path,
discovered_endpoint.params,
discovered_endpoint.query,

View File

@ -474,6 +474,7 @@ class RequestsMockTestCase(BaseTestCase):
discovery_fixture = os.path.join(
self.fixtures_directory, image_version_json)
return dict(method='GET', uri='https://image.example.com/',
status_code=300,
text=open(discovery_fixture, 'r').read())
def get_designate_discovery_mock_dict(self):

View File

@ -0,0 +1,64 @@
{
"versions": [
{
"status": "CURRENT",
"id": "v2.3",
"links": [
{
"href": "http://localhost/v2/",
"rel": "self"
}
]
},
{
"status": "SUPPORTED",
"id": "v2.2",
"links": [
{
"href": "http://localhost/v2/",
"rel": "self"
}
]
},
{
"status": "SUPPORTED",
"id": "v2.1",
"links": [
{
"href": "http://localhost/v2/",
"rel": "self"
}
]
},
{
"status": "SUPPORTED",
"id": "v2.0",
"links": [
{
"href": "http://localhost/v2/",
"rel": "self"
}
]
},
{
"status": "SUPPORTED",
"id": "v1.1",
"links": [
{
"href": "http://localhost/v1/",
"rel": "self"
}
]
},
{
"status": "SUPPORTED",
"id": "v1.0",
"links": [
{
"href": "http://localhost/v1/",
"rel": "self"
}
]
}
]
}

View File

@ -738,3 +738,26 @@ class TestImageVolume(BaseTestImage):
volume={'id': volume_id}, allow_duplicates=True)
self.assert_calls()
class TestImageBrokenDiscovery(base.RequestsMockTestCase):
def setUp(self):
super(TestImageBrokenDiscovery, self).setUp()
self.use_glance(image_version_json='image-version-broken.json')
def test_url_fix(self):
# image-version-broken.json has both http urls and localhost as the
# host. This is testing that what is discovered is https, because
# that's what's in the catalog, and image.example.com for the same
# reason.
self.register_uris([
dict(method='GET',
uri='https://image.example.com/v2/images',
json={'images': []})
])
self.assertEqual([], self.cloud.list_images())
self.assertEqual(
self.cloud._image_client.endpoint_override,
'https://image.example.com/v2/')
self.assert_calls()