summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--keystone/backends/ldap/api/tenant.py6
-rwxr-xr-xkeystone/backends/sqlalchemy/__init__.py5
-rwxr-xr-xkeystone/backends/sqlalchemy/api/tenant.py12
-rw-r--r--keystone/test/unit/test_backends.py58
4 files changed, 60 insertions, 21 deletions
diff --git a/keystone/backends/ldap/api/tenant.py b/keystone/backends/ldap/api/tenant.py
index 82cfeb8b..6fd6fb5d 100644
--- a/keystone/backends/ldap/api/tenant.py
+++ b/keystone/backends/ldap/api/tenant.py
@@ -26,8 +26,10 @@ class TenantAPI(BaseLdapAPI, BaseTenantAPI): # pylint: disable=W0223
return None
def create(self, values):
- values['id'] = str(uuid.uuid4())
- return super(TenantAPI, self).create(values)
+ data = values.copy()
+ if 'id' not in data or data['id'] is None:
+ data['id'] = str(uuid.uuid4())
+ return super(TenantAPI, self).create(data)
def get_user_tenants(self, user_id, include_roles=True):
"""Returns list of tenants a user has access to
diff --git a/keystone/backends/sqlalchemy/__init__.py b/keystone/backends/sqlalchemy/__init__.py
index 41fd0b3f..c4bd45c3 100755
--- a/keystone/backends/sqlalchemy/__init__.py
+++ b/keystone/backends/sqlalchemy/__init__.py
@@ -54,6 +54,8 @@ class Driver():
self._init_session_maker()
def _init_engine(self, model_list):
+ logger.info("Initializing sqlalchemy backend: %s" % \
+ self.connection_str)
if self.connection_str == "sqlite://":
# initialize in-memory sqlite (i.e. for testing)
self._engine = create_engine(
@@ -71,6 +73,7 @@ class Driver():
self.connection_str,
pool_recycle=3600)
self._init_version_control()
+ self._init_tables(model_list)
def _init_version_control(self):
"""Verify the state of the database"""
@@ -118,6 +121,8 @@ class Driver():
if table in tables:
tables_to_create.append(table)
+ logger.debug('Creating tables: %s' % \
+ ','.join([table.name for table in tables_to_create]))
models.Base.metadata.create_all(self._engine, tables=tables_to_create,
checkfirst=True)
diff --git a/keystone/backends/sqlalchemy/api/tenant.py b/keystone/backends/sqlalchemy/api/tenant.py
index 5ec09c36..f7a3ada2 100755
--- a/keystone/backends/sqlalchemy/api/tenant.py
+++ b/keystone/backends/sqlalchemy/api/tenant.py
@@ -61,10 +61,10 @@ class TenantAPI(api.BaseTenantAPI):
return [TenantAPI.to_model(ref) for ref in refs]
def create(self, values):
- values = values.copy()
- TenantAPI.transpose(values)
+ data = values.copy()
+ TenantAPI.transpose(data)
tenant_ref = models.Tenant()
- tenant_ref.update(values)
+ tenant_ref.update(data)
if tenant_ref.uid is None:
tenant_ref.uid = uuid.uuid4().hex
tenant_ref.save()
@@ -282,13 +282,15 @@ class TenantAPI(api.BaseTenantAPI):
session = get_session()
if hasattr(api.TENANT, 'uid_to_id'):
- id = self.uid_to_id(id)
+ pkid = self.uid_to_id(id)
+ else:
+ pkid = id
data = values.copy()
TenantAPI.transpose(data)
with session.begin():
- tenant_ref = self._get_by_id(id, session)
+ tenant_ref = self._get_by_id(pkid, session)
tenant_ref.update(data)
tenant_ref.save(session=session)
return self.get(id, session)
diff --git a/keystone/test/unit/test_backends.py b/keystone/test/unit/test_backends.py
index aa6242d7..6e85b8ee 100644
--- a/keystone/test/unit/test_backends.py
+++ b/keystone/test/unit/test_backends.py
@@ -1,3 +1,4 @@
+import os
import unittest2 as unittest
import uuid
@@ -12,7 +13,7 @@ class BackendTestCase(unittest.TestCase):
Base class to run tests for Keystone backends (and backend configs)
"""
- def setUp(self, options=None):
+ def setUp(self, options=None): # pylint: disable=W0221
super(BackendTestCase, self).setUp()
# Set up root options if missing
if options is None:
@@ -39,6 +40,7 @@ class BackendTestCase(unittest.TestCase):
# Init backends module constants (without initializing backends)
no_backend_init = options.copy()
no_backend_init['backends'] = None
+ reload(backends)
backends.configure_backends(no_backend_init)
backend_list = options['backends']
@@ -66,24 +68,24 @@ class BackendTestCase(unittest.TestCase):
for k, v in original_tenant.items():
if k not in ['id'] and k in new_tenant:
self.assertEquals(new_tenant[k], v)
- self.assertEqual(original_tenant, tenant, "Backend modified provided \
-tenant")
def test_tenant_create_with_id(self):
- tenant = models.Tenant(id="T2", name="Tee Two", description="This is \
-T2", enabled=True)
+ tenant = models.Tenant(id="T2%s" % uuid.uuid4().hex, name="Tee Two",
+ description="This is T2", enabled=True)
- original_tenant = tenant.copy()
+ original_tenant = tenant.to_dict()
new_tenant = api.TENANT.create(tenant)
self.assertIsInstance(new_tenant, models.Tenant)
for k, v in original_tenant.items():
if k in new_tenant:
- self.assertEquals(new_tenant[k], v)
- self.assertEqual(original_tenant, tenant, "Backend modified provided \
-tenant")
+ self.assertEquals(new_tenant[k], v,
+ "'%s' did not match" % k)
+ self.assertEqual(original_tenant['tenant'], tenant,
+ "Backend modified provided tenant")
def test_tenant_update(self):
- tenant = models.Tenant(id="T3", name="Tee Three",
+ id = "T3%s" % uuid.uuid4().hex
+ tenant = models.Tenant(id=id, name="Tee Three",
description="This is T3", enabled=True)
new_tenant = api.TENANT.create(tenant)
@@ -91,15 +93,15 @@ tenant")
new_tenant.enabled = False
new_tenant.description = "This is UPDATED T3"
- api.TENANT.update("T3", new_tenant)
+ api.TENANT.update(id, new_tenant)
- updated_tenant = api.TENANT.get("T3")
+ updated_tenant = api.TENANT.get(id)
self.assertEqual(new_tenant, updated_tenant)
class LDAPBackendTestCase(BackendTestCase):
- def __init__(self, options=None):
+ def setUp(self, options=None):
if options is None:
options = {
'backends': 'keystone.backends.sqlalchemy,keystone.backends.ldap',
@@ -121,7 +123,35 @@ class LDAPBackendTestCase(BackendTestCase):
'Role']"
}
}
- super(LDAPBackendTestCase, self).__init__(options)
+ super(LDAPBackendTestCase, self).setUp(options)
+
+
+class SQLiteBackendTestCase(BackendTestCase):
+ """ Tests SQLite backend using actual file (not in memory)
+
+ Since we have a code path that is specific to in-memory databases, we need
+ to test for when we have a real file behind the ORM
+ """
+ def setUp(self, options=None):
+ if options is None:
+ self.database_name = os.path.abspath('%s.test.db' % \
+ uuid.uuid4().hex)
+ options = {
+ 'backends': 'keystone.backends.sqlalchemy',
+ "keystone-service-admin-role": "KeystoneServiceAdmin",
+ "keystone-admin-role": "KeystoneAdmin",
+ "hash-password": "False",
+ 'keystone.backends.sqlalchemy': {
+ "sql_connection": "sqlite:///%s" % self.database_name,
+ "backend_entities": "['Tenant']",
+ "sql_idle_timeout": "30"
+ }
+ }
+ super(SQLiteBackendTestCase, self).setUp(options)
+
+ def tearDown(self):
+ if os.path.exists(self.database_name):
+ os.unlink(self.database_name)
if __name__ == '__main__':
unittest.main()