authenticate and tenants working

This commit is contained in:
termie 2011-11-02 15:04:01 -07:00
parent 2f2465eafa
commit 0d4e11c48a
5 changed files with 40 additions and 7 deletions

View File

@ -1,3 +1,6 @@
from keystonelight import logging
class TemplatedCatalog(object):
"""A backend that generates endpoints for the Catalog based on templates.
@ -29,6 +32,7 @@ class TemplatedCatalog(object):
def __init__(self, options, templates=None):
self.options = options
logging.debug('CATALOG PUBLIC PORT BEFORE: %s', options['public_port'])
if templates:
self.templates = templates

View File

@ -5,6 +5,7 @@ import sys
from paste import deploy
from keystonelight import logging
from keystonelight import utils
from keystonelight import wsgi
@ -67,6 +68,7 @@ class TestCase(unittest.TestCase):
def __init__(self, *args, **kw):
super(TestCase, self).__init__(*args, **kw)
self._paths = []
self._memo = {}
def setUp(self):
super(TestCase, self).setUp()
@ -93,11 +95,26 @@ class TestCase(unittest.TestCase):
server.start(app, 0, key='socket')
# Service catalog tests need to know the port we ran on.
options = self.appconfig(config)
port = server.socket_info['socket'][1]
options['public_port'] = port
self._update_server_options(server, 'public_port', port)
logging.debug('PUBLIC PORT: %s', app.options['public_port'])
return server
def _update_server_options(self, server, key, value):
"""Hack to allow us to make changes to the options used by backends.
A possible better solution would be to have a global config registry.
"""
last = server
while hasattr(last, 'application') or hasattr(last, 'options'):
logging.debug('UPDATE %s', last.__class__)
if hasattr(last, 'options'):
last.options[key] = value
if not hasattr(last, 'application'):
break
last = last.application
def client(self, app, *args, **kw):
return TestClient(app, *args, **kw)

View File

@ -58,6 +58,7 @@ class Server(object):
def start(self, application, port, host='0.0.0.0', key=None, backlog=128):
"""Run a WSGI server with the given application."""
self.application = application
arg0 = sys.argv[0]
logging.debug('Starting %(arg0)s on %(host)s:%(port)s' % locals())
socket = eventlet.listen((host, port), backlog=backlog)

View File

@ -6,9 +6,9 @@ public_port = 5000
# config for TemplatedCatalog, using camelCase because I don't want to do
# translations for keystone compat
catalog.RegionOne.identity.publicURL = http://localhost:$(public_port)s/v2.0/$(tenant_id)s
catalog.RegionOne.identity.adminURL = http://localhost:$(public_port)s/v2.0/$(tenant_id)s
catalog.RegionOne.identity.internalURL = http://localhost:$(public_port)s/v2.0/$(tenant_id)s
catalog.RegionOne.identity.publicURL = http://localhost:$(public_port)s/v2.0
catalog.RegionOne.identity.adminURL = http://localhost:$(public_port)s/v2.0
catalog.RegionOne.identity.internalURL = http://localhost:$(public_port)s/v2.0
catalog.RegionOne.identity.name = 'Identity Service'

View File

@ -55,14 +55,25 @@ class MasterCompatTestCase(CompatTestCase):
dict(roles=[],
roles_links=[]))
#def test_authenticate(self):
# from keystoneclient.v2_0 import client as ks_client
def test_authenticate(self):
# port = self.server.socket_info['socket'][1]
# client = ks_client.Client(auth_url="http://localhost:%s/v2.0" % port,
# username='foo',
# password='foo',
# project_id='bar')
# client.authenticate()
def test_authenticate_and_tenants(self):
from keystoneclient.v2_0 import client as ks_client
port = self.server.socket_info['socket'][1]
self.options['public_port'] = port
client = ks_client.Client(auth_url="http://localhost:%s/v2.0" % port,
username='foo',
password='foo',
project_id='bar')
client.authenticate()
pass
tenants = client.tenants.list()
self.assertEquals(tenants[0].id, self.tenant_bar['id'])