From 832d89681cd1c2470375a10d87018be7bf8d0ed9 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 4 Jun 2014 10:56:56 +1000 Subject: [PATCH] Add service_name to URL discovery The catalog was recently enhanced to allow filtering based on the service_name so this should be passed on to endpoint filtering. Change-Id: If08fcdba9719f6aacdcbbb6b951117f4f544f9ca --- keystoneclient/auth/base.py | 1 + keystoneclient/auth/identity/base.py | 7 +++++-- keystoneclient/tests/auth/test_identity_v2.py | 4 +++- keystoneclient/tests/auth/test_identity_v3.py | 7 +++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/keystoneclient/auth/base.py b/keystoneclient/auth/base.py index 4e2b58576..23299055b 100644 --- a/keystoneclient/auth/base.py +++ b/keystoneclient/auth/base.py @@ -44,6 +44,7 @@ class BaseAuthPlugin(object): will be generated by the clients and should be used by plugins: - ``service_type``: what sort of service is required. + - ``service_name``: the name of the service in the catalog. - ``interface``: what visibility the endpoint should have. - ``region_name``: the region the endpoint exists in. diff --git a/keystoneclient/auth/identity/base.py b/keystoneclient/auth/identity/base.py index 834afc39e..df41bd317 100644 --- a/keystoneclient/auth/identity/base.py +++ b/keystoneclient/auth/identity/base.py @@ -92,7 +92,7 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): return self.auth_ref def get_endpoint(self, session, service_type=None, interface=None, - region_name=None, **kwargs): + region_name=None, service_name=None, **kwargs): """Return a valid endpoint for a service. If a valid token is not present then a new one will be fetched using @@ -106,6 +106,8 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): Defaults to `public`. :param string region_name: The region the endpoint should exist in. (optional) + :param string service_name: The name of the service in the catalog. + (optional) :raises HttpError: An error from an invalid HTTP response. @@ -123,7 +125,8 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): service_catalog = self.get_access(session).service_catalog return service_catalog.url_for(service_type=service_type, endpoint_type=interface, - region_name=region_name) + region_name=region_name, + service_name=service_name) def invalidate(self): self.auth_ref = None diff --git a/keystoneclient/tests/auth/test_identity_v2.py b/keystoneclient/tests/auth/test_identity_v2.py index f5578beac..a264edd1f 100644 --- a/keystoneclient/tests/auth/test_identity_v2.py +++ b/keystoneclient/tests/auth/test_identity_v2.py @@ -175,7 +175,9 @@ class V2IdentityPlugin(utils.TestCase): self.assertEqual(httpretty.last_request().path, path) def test_service_url(self): - endpoint_filter = {'service_type': 'compute', 'interface': 'admin'} + endpoint_filter = {'service_type': 'compute', + 'interface': 'admin', + 'service_name': 'nova'} self._do_service_url_test('http://nova/novapi/admin', endpoint_filter) def test_service_url_defaults_to_public(self): diff --git a/keystoneclient/tests/auth/test_identity_v3.py b/keystoneclient/tests/auth/test_identity_v3.py index e17dc00fe..d44c8e7dc 100644 --- a/keystoneclient/tests/auth/test_identity_v3.py +++ b/keystoneclient/tests/auth/test_identity_v3.py @@ -61,7 +61,8 @@ class V3IdentityPlugin(utils.TestCase): "region": "RegionOne", "interface": "admin" }], - "type": "compute" + "type": "compute", + "name": "nova", }, { "endpoints": [{ "url": "http://glance/glanceapi/public", @@ -328,7 +329,9 @@ class V3IdentityPlugin(utils.TestCase): self.assertEqual(httpretty.last_request().path, path) def test_service_url(self): - endpoint_filter = {'service_type': 'compute', 'interface': 'admin'} + endpoint_filter = {'service_type': 'compute', + 'interface': 'admin', + 'service_name': 'nova'} self._do_service_url_test('http://nova/novapi/admin', endpoint_filter) def test_service_url_defaults_to_public(self):