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
This commit is contained in:
Jamie Lennox 2015-04-17 09:16:00 +10:00
parent 85eeecbd3d
commit 0abcaff9f7
3 changed files with 22 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,