From 0abcaff9f77dd80d782d1a56d766740633ed8ec0 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Fri, 17 Apr 2015 09:16:00 +1000 Subject: [PATCH] Add endpoint and service ids to fixtures The service catalog should contain an endpoint id and service id in the v3 token and an endpoint id in the v2 token. Change-Id: I8835bcb7c68ae8d0175b6f58a4750cd6e25fd84c --- keystoneclient/fixture/v2.py | 5 +++-- keystoneclient/fixture/v3.py | 9 +++++---- keystoneclient/tests/unit/test_fixtures.py | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/keystoneclient/fixture/v2.py b/keystoneclient/fixture/v2.py index bbac2dcb3..3022f2c89 100644 --- a/keystoneclient/fixture/v2.py +++ b/keystoneclient/fixture/v2.py @@ -21,12 +21,13 @@ from keystoneclient.fixture import exception class _Service(dict): def add_endpoint(self, public, admin=None, internal=None, - tenant_id=None, region=None): + tenant_id=None, region=None, id=None): data = {'tenantId': tenant_id or uuid.uuid4().hex, 'publicURL': public, 'adminURL': admin or public, 'internalURL': internal or public, - 'region': region} + 'region': region, + 'id': id or uuid.uuid4().hex} self.setdefault('endpoints', []).append(data) return data diff --git a/keystoneclient/fixture/v3.py b/keystoneclient/fixture/v3.py index 646e46dbf..a1781dd6e 100644 --- a/keystoneclient/fixture/v3.py +++ b/keystoneclient/fixture/v3.py @@ -25,8 +25,9 @@ class _Service(dict): this object and then you can add_endpoints to the service. """ - def add_endpoint(self, interface, url, region=None): - data = {'interface': interface, + def add_endpoint(self, interface, url, region=None, id=None): + data = {'id': id or uuid.uuid4().hex, + 'interface': interface, 'url': url, 'region': region, 'region_id': region} @@ -354,8 +355,8 @@ class Token(dict): roles.append(data) return data - def add_service(self, type, name=None): - service = _Service(type=type) + def add_service(self, type, name=None, id=None): + service = _Service(type=type, id=id or uuid.uuid4().hex) if name: service['name'] = name self.root.setdefault('catalog', []).append(service) diff --git a/keystoneclient/tests/unit/test_fixtures.py b/keystoneclient/tests/unit/test_fixtures.py index 3e41b4045..345ae457c 100644 --- a/keystoneclient/tests/unit/test_fixtures.py +++ b/keystoneclient/tests/unit/test_fixtures.py @@ -84,6 +84,7 @@ class V2TokenTests(utils.TestCase): def test_services(self): service_type = uuid.uuid4().hex service_name = uuid.uuid4().hex + endpoint_id = uuid.uuid4().hex region = uuid.uuid4().hex public = uuid.uuid4().hex @@ -96,7 +97,8 @@ class V2TokenTests(utils.TestCase): svc.add_endpoint(public=public, admin=admin, internal=internal, - region=region) + region=region, + id=endpoint_id) self.assertEqual(1, len(token['access']['serviceCatalog'])) service = token['access']['serviceCatalog'][0]['endpoints'][0] @@ -105,6 +107,7 @@ class V2TokenTests(utils.TestCase): self.assertEqual(internal, service['internalURL']) self.assertEqual(admin, service['adminURL']) self.assertEqual(region, service['region']) + self.assertEqual(endpoint_id, service['id']) class V3TokenTests(utils.TestCase): @@ -218,13 +221,16 @@ class V3TokenTests(utils.TestCase): def test_catalog(self): service_type = uuid.uuid4().hex service_name = uuid.uuid4().hex + service_id = uuid.uuid4().hex region = uuid.uuid4().hex endpoints = {'public': uuid.uuid4().hex, 'internal': uuid.uuid4().hex, 'admin': uuid.uuid4().hex} token = fixture.V3Token() - svc = token.add_service(type=service_type, name=service_name) + svc = token.add_service(type=service_type, + name=service_name, + id=service_id) svc.add_standard_endpoints(region=region, **endpoints) self.assertEqual(1, len(token['token']['catalog'])) @@ -233,6 +239,12 @@ class V3TokenTests(utils.TestCase): self.assertEqual(service_name, service['name']) self.assertEqual(service_type, service['type']) + self.assertEqual(service_id, service['id']) + + for endpoint in service['endpoints']: + # assert an id exists for each endpoint, remove it to make testing + # the endpoint content below easier. + self.assertTrue(endpoint.pop('id')) for interface, url in six.iteritems(endpoints): endpoint = {'interface': interface, 'url': url,