Moved SQL backend tests into memory
(test_keystoneclient_sql still uses a db on disk) Change-Id: I476ee710983adbe3436f41882e8483f8193daf5c
This commit is contained in:
parent
f33e9f0279
commit
c6884c54a4
@ -129,40 +129,37 @@ class MySQLPingListener(object):
|
||||
|
||||
# Backends
|
||||
class Base(object):
|
||||
|
||||
_MAKER = None
|
||||
_ENGINE = None
|
||||
_engine = None
|
||||
_sessionmaker = None
|
||||
|
||||
def get_session(self, autocommit=True, expire_on_commit=False):
|
||||
"""Return a SQLAlchemy session."""
|
||||
if self._MAKER is None or self._ENGINE is None:
|
||||
self._ENGINE = self.get_engine()
|
||||
self._MAKER = self.get_maker(self._ENGINE,
|
||||
autocommit,
|
||||
expire_on_commit)
|
||||
|
||||
session = self._MAKER()
|
||||
return session
|
||||
self._engine = self._engine or self.get_engine()
|
||||
self._sessionmaker = self._sessionmaker or self.get_sessionmaker(
|
||||
self._engine)
|
||||
return self._sessionmaker()
|
||||
|
||||
def get_engine(self):
|
||||
"""Return a SQLAlchemy engine."""
|
||||
connection_dict = sql.engine.url.make_url(CONF.sql.connection)
|
||||
|
||||
engine_args = {'pool_recycle': CONF.sql.idle_timeout,
|
||||
'echo': False,
|
||||
'convert_unicode': True
|
||||
}
|
||||
engine_config = {
|
||||
'convert_unicode': True,
|
||||
'echo': CONF.debug and CONF.verbose,
|
||||
'pool_recycle': CONF.sql.idle_timeout,
|
||||
}
|
||||
|
||||
if 'sqlite' in connection_dict.drivername:
|
||||
engine_args['poolclass'] = sqlalchemy.pool.NullPool
|
||||
engine_config['poolclass'] = sqlalchemy.pool.StaticPool
|
||||
elif 'mysql' in connection_dict.drivername:
|
||||
engine_config['listeners'] = [MySQLPingListener()]
|
||||
|
||||
if 'mysql' in connection_dict.drivername:
|
||||
engine_args['listeners'] = [MySQLPingListener()]
|
||||
return sql.create_engine(CONF.sql.connection, **engine_config)
|
||||
|
||||
return sql.create_engine(CONF.sql.connection, **engine_args)
|
||||
|
||||
def get_maker(self, engine, autocommit=True, expire_on_commit=False):
|
||||
def get_sessionmaker(self, engine, autocommit=True,
|
||||
expire_on_commit=False):
|
||||
"""Return a SQLAlchemy sessionmaker using the given engine."""
|
||||
return sqlalchemy.orm.sessionmaker(bind=engine,
|
||||
autocommit=autocommit,
|
||||
expire_on_commit=expire_on_commit)
|
||||
return sqlalchemy.orm.sessionmaker(
|
||||
bind=engine,
|
||||
autocommit=autocommit,
|
||||
expire_on_commit=expire_on_commit)
|
||||
|
@ -1,5 +1,5 @@
|
||||
[sql]
|
||||
connection = sqlite:///test.db
|
||||
connection = sqlite://
|
||||
idle_timeout = 200
|
||||
|
||||
[identity]
|
||||
|
2
tests/backend_sql_disk.conf
Normal file
2
tests/backend_sql_disk.conf
Normal file
@ -0,0 +1,2 @@
|
||||
[sql]
|
||||
connection = sqlite:///test.db
|
@ -16,14 +16,13 @@
|
||||
|
||||
import uuid
|
||||
|
||||
from keystone.common import sql
|
||||
from keystone import catalog
|
||||
from keystone.catalog.backends import sql as catalog_sql
|
||||
from keystone.common.sql import util as sql_util
|
||||
from keystone import config
|
||||
from keystone import exception
|
||||
from keystone.identity.backends import sql as identity_sql
|
||||
from keystone import identity
|
||||
from keystone import test
|
||||
from keystone.token.backends import sql as token_sql
|
||||
from keystone import token
|
||||
|
||||
import default_fixtures
|
||||
import test_backend
|
||||
@ -32,20 +31,39 @@ import test_backend
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class SqlIdentity(test.TestCase, test_backend.IdentityTests):
|
||||
class SqlTests(test.TestCase):
|
||||
def setUp(self):
|
||||
super(SqlIdentity, self).setUp()
|
||||
super(SqlTests, self).setUp()
|
||||
self.config([test.etcdir('keystone.conf.sample'),
|
||||
test.testsdir('test_overrides.conf'),
|
||||
test.testsdir('backend_sql.conf')])
|
||||
sql_util.setup_test_database()
|
||||
self.identity_api = identity_sql.Identity()
|
||||
|
||||
# initialize managers and override drivers
|
||||
self.catalog_man = catalog.Manager()
|
||||
self.identity_man = identity.Manager()
|
||||
self.token_man = token.Manager()
|
||||
|
||||
# create shortcut references to each driver
|
||||
self.catalog_api = self.catalog_man.driver
|
||||
self.identity_api = self.identity_man.driver
|
||||
self.token_api = self.token_man.driver
|
||||
|
||||
# create and share a single sqlalchemy engine for testing
|
||||
engine = sql.Base().get_engine()
|
||||
self.identity_api._engine = engine
|
||||
self.catalog_api._engine = engine
|
||||
self.token_api._engine = engine
|
||||
|
||||
# populate the engine with tables & fixtures
|
||||
sql.ModelBase.metadata.bind = engine
|
||||
sql.ModelBase.metadata.create_all(engine)
|
||||
self.load_fixtures(default_fixtures)
|
||||
|
||||
def tearDown(self):
|
||||
sql_util.teardown_test_database()
|
||||
super(SqlIdentity, self).tearDown()
|
||||
super(SqlTests, self).tearDown()
|
||||
|
||||
|
||||
class SqlIdentity(SqlTests, test_backend.IdentityTests):
|
||||
def test_delete_user_with_tenant_association(self):
|
||||
user = {'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
@ -138,35 +156,11 @@ class SqlIdentity(test.TestCase, test_backend.IdentityTests):
|
||||
self.tenant_bar['id'])
|
||||
|
||||
|
||||
class SqlToken(test.TestCase, test_backend.TokenTests):
|
||||
def setUp(self):
|
||||
super(SqlToken, self).setUp()
|
||||
self.config([test.etcdir('keystone.conf.sample'),
|
||||
test.testsdir('test_overrides.conf'),
|
||||
test.testsdir('backend_sql.conf')])
|
||||
sql_util.setup_test_database()
|
||||
self.token_api = token_sql.Token()
|
||||
|
||||
def tearDown(self):
|
||||
sql_util.teardown_test_database()
|
||||
super(SqlToken, self).tearDown()
|
||||
class SqlToken(SqlTests, test_backend.TokenTests):
|
||||
pass
|
||||
|
||||
|
||||
class SqlCatalog(test.TestCase, test_backend.CatalogTests):
|
||||
def setUp(self):
|
||||
super(SqlCatalog, self).setUp()
|
||||
self.config([test.etcdir('keystone.conf.sample'),
|
||||
test.testsdir('test_overrides.conf'),
|
||||
test.testsdir('backend_sql.conf')])
|
||||
sql_util.setup_test_database()
|
||||
self.catalog_api = catalog_sql.Catalog()
|
||||
self.catalog_man = catalog.Manager()
|
||||
self.load_fixtures(default_fixtures)
|
||||
|
||||
def tearDown(self):
|
||||
sql_util.teardown_test_database()
|
||||
super(SqlCatalog, self).tearDown()
|
||||
|
||||
class SqlCatalog(SqlTests, test_backend.CatalogTests):
|
||||
def test_malformed_catalog_throws_error(self):
|
||||
self.catalog_api.create_service('a', {"id": "a", "desc": "a1",
|
||||
"name": "b"})
|
||||
|
@ -35,7 +35,8 @@ class ImportLegacy(test.TestCase):
|
||||
super(ImportLegacy, self).setUp()
|
||||
self.config([test.etcdir('keystone.conf.sample'),
|
||||
test.testsdir('test_overrides.conf'),
|
||||
test.testsdir('backend_sql.conf')])
|
||||
test.testsdir('backend_sql.conf'),
|
||||
test.testsdir('backend_sql_disk.conf')])
|
||||
sql_util.setup_test_database()
|
||||
self.identity_api = identity_sql.Identity()
|
||||
|
||||
|
@ -31,7 +31,8 @@ class KcMasterSqlTestCase(test_keystoneclient.KcMasterTestCase):
|
||||
super(KcMasterSqlTestCase, self).config([
|
||||
test.etcdir('keystone.conf.sample'),
|
||||
test.testsdir('test_overrides.conf'),
|
||||
test.testsdir('backend_sql.conf')])
|
||||
test.testsdir('backend_sql.conf'),
|
||||
test.testsdir('backend_sql_disk.conf')])
|
||||
sql_util.setup_test_database()
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -70,7 +70,8 @@ class MigrateNovaAuth(test.TestCase):
|
||||
super(MigrateNovaAuth, self).setUp()
|
||||
self.config([test.etcdir('keystone.conf.sample'),
|
||||
test.testsdir('test_overrides.conf'),
|
||||
test.testsdir('backend_sql.conf')])
|
||||
test.testsdir('backend_sql.conf'),
|
||||
test.testsdir('backend_sql_disk.conf')])
|
||||
sql_util.setup_test_database()
|
||||
self.identity_api = identity_sql.Identity()
|
||||
self.ec2_api = ec2_sql.Ec2()
|
||||
|
Loading…
Reference in New Issue
Block a user