From a7f35beb1dd87ef34b29459571634471d0dabeca Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 9 Nov 2018 10:25:03 -0600 Subject: [PATCH] Fix neutron endpoint mangling If the endpoint has a v2.0 on it, we were double mangling it. Fix the issue and add a test. Change-Id: Ia73ea9ae15038a1aba3b46528d0c21f2ac028ec0 Story: 2004310 Task: 27877 --- openstack/config/cloud_region.py | 2 +- .../unit/fixtures/catalog-v3-suffix.json | 211 ++++++++++++++++++ openstack/tests/unit/test_connection.py | 14 ++ ...on-endpoint-mangling-a9dd89dd09bc71ec.yaml | 5 + 4 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 openstack/tests/unit/fixtures/catalog-v3-suffix.json create mode 100644 releasenotes/notes/fix-neutron-endpoint-mangling-a9dd89dd09bc71ec.yaml diff --git a/openstack/config/cloud_region.py b/openstack/config/cloud_region.py index 7568673bf..e12b91628 100644 --- a/openstack/config/cloud_region.py +++ b/openstack/config/cloud_region.py @@ -492,7 +492,7 @@ class CloudRegion(object): region_name=self.region_name, ) network_endpoint = network_adapter.get_endpoint() - if not network_endpoint.rstrip().rsplit('/')[1] == 'v2.0': + if not network_endpoint.rstrip().rsplit('/')[-1] == 'v2.0': if not network_endpoint.endswith('/'): network_endpoint += '/' network_endpoint = urllib.parse.urljoin( diff --git a/openstack/tests/unit/fixtures/catalog-v3-suffix.json b/openstack/tests/unit/fixtures/catalog-v3-suffix.json new file mode 100644 index 000000000..a2a2633bc --- /dev/null +++ b/openstack/tests/unit/fixtures/catalog-v3-suffix.json @@ -0,0 +1,211 @@ +{ + "token": { + "audit_ids": [ + "Rvn7eHkiSeOwucBIPaKdYA" + ], + "catalog": [ + { + "endpoints": [ + { + "id": "32466f357f3545248c47471ca51b0d3a", + "interface": "public", + "region": "RegionOne", + "url": "https://compute.example.com/v2.1/" + } + ], + "name": "nova", + "type": "compute" + }, + { + "endpoints": [ + { + "id": "1e875ca2225b408bbf3520a1b8e1a537", + "interface": "public", + "region": "RegionOne", + "url": "https://volume.example.com/v2/1c36b64c840a42cd9e9b931a369337f0" + } + ], + "name": "cinderv2", + "type": "volumev2" + }, + { + "endpoints": [ + { + "id": "5a64de3c4a614d8d8f8d1ba3dee5f45f", + "interface": "public", + "region": "RegionOne", + "url": "https://image.example.com" + } + ], + "name": "glance", + "type": "image" + }, + { + "endpoints": [ + { + "id": "3d15fdfc7d424f3c8923324417e1a3d1", + "interface": "public", + "region": "RegionOne", + "url": "https://volume.example.com/v1/1c36b64c840a42cd9e9b931a369337f0" + } + ], + "name": "cinder", + "type": "volume" + }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba628c", + "interface": "public", + "region": "RegionOne", + "url": "https://identity.example.com" + }, + { + "id": "012322eeedcd459edabb4933021112bc", + "interface": "admin", + "region": "RegionOne", + "url": "https://identity.example.com" + } + ], + "endpoints_links": [], + "name": "keystone", + "type": "identity" + }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba628d", + "interface": "public", + "region": "RegionOne", + "url": "https://network.example.com/v2.0" + } + ], + "endpoints_links": [], + "name": "neutron", + "type": "network" + }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba628e", + "interface": "public", + "region": "RegionOne", + "url": "https://container-infra.example.com/v1" + } + ], + "endpoints_links": [], + "name": "magnum", + "type": "container-infra" + }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba628c", + "interface": "public", + "region": "RegionOne", + "url": "https://object-store.example.com/v1/1c36b64c840a42cd9e9b931a369337f0" + } + ], + "endpoints_links": [], + "name": "swift", + "type": "object-store" + }, + { + "endpoints": [ + { + "id": "652f0612744042bfbb8a8bb2c777a16d", + "interface": "public", + "region": "RegionOne", + "url": "https://bare-metal.example.com/" + } + ], + "endpoints_links": [], + "name": "ironic", + "type": "baremetal" + }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba628c", + "interface": "public", + "region": "RegionOne", + "url": "https://orchestration.example.com/v1/1c36b64c840a42cd9e9b931a369337f0" + } + ], + "endpoints_links": [], + "name": "heat", + "type": "orchestration" + }, + { + "endpoints": [ + { + "id": "10c76ffd2b744a67950ed1365190d353", + "interface": "public", + "region": "RegionOne", + "url": "https://placement.example.com" + } + ], + "endpoints_links": [], + "name": "placement", + "type": "placement" + }, + { + "endpoints": [ + { + "id": "10c76ffd2b744a67950ed1365190d352", + "interface": "public", + "region": "RegionOne", + "url": "https://dns.example.com" + } + ], + "endpoints_links": [], + "name": "designate", + "type": "dns" + }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba624z", + "interface": "public", + "region": "RegionOne", + "url": "https://clustering.example.com" + } + ], + "endpoints_links": [], + "name": "senlin", + "type": "clustering" + } + ], + "expires_at": "9999-12-31T23:59:59Z", + "issued_at": "2016-12-17T14:25:05.000000Z", + "methods": [ + "password" + ], + "project": { + "domain": { + "id": "default", + "name": "default" + }, + "id": "1c36b64c840a42cd9e9b931a369337f0", + "name": "Default Project" + }, + "roles": [ + { + "id": "9fe2ff9ee4384b1894a90878d3e92bab", + "name": "_member_" + }, + { + "id": "37071fc082e14c2284c32a2761f71c63", + "name": "swiftoperator" + } + ], + "user": { + "domain": { + "id": "default", + "name": "default" + }, + "id": "c17534835f8f42bf98fc367e0bf35e09", + "name": "mordred" + } + } +} diff --git a/openstack/tests/unit/test_connection.py b/openstack/tests/unit/test_connection.py index 936b11b01..10904a5a1 100644 --- a/openstack/tests/unit/test_connection.py +++ b/openstack/tests/unit/test_connection.py @@ -229,6 +229,20 @@ class TestConnection(base.TestCase): class TestNetworkConnection(base.TestCase): + + # Verify that if the catalog has the suffix we don't mess things up. + def test_network_proxy(self): + self.use_keystone_v3(catalog='catalog-v3-suffix.json') + self.assertEqual( + 'openstack.network.v2._proxy', + self.conn.network.__class__.__module__) + self.assert_calls() + self.assertEqual( + "https://network.example.com/v2.0", + self.conn.network.get_endpoint()) + + +class TestNetworkConnectionSuffix(base.TestCase): # We need to do the neutron adapter test differently because it needs # to actually get a catalog. diff --git a/releasenotes/notes/fix-neutron-endpoint-mangling-a9dd89dd09bc71ec.yaml b/releasenotes/notes/fix-neutron-endpoint-mangling-a9dd89dd09bc71ec.yaml new file mode 100644 index 000000000..0f4a2d1c7 --- /dev/null +++ b/releasenotes/notes/fix-neutron-endpoint-mangling-a9dd89dd09bc71ec.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed incorrect neutron endpoint mangling for the cases when the catalog + contains a versioned neutron endpoint.