Tests running on in-memory sqlite db

Change-Id: I79e26b38416f0c143a0e83bb601c0046bb3dcf02
This commit is contained in:
Dolph Mathews 2011-08-17 11:00:07 -05:00
parent fabeec2505
commit 73d26734d6
6 changed files with 35 additions and 23 deletions

View File

@ -20,18 +20,21 @@ import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import joinedload, aliased, sessionmaker
from sqlalchemy.pool import StaticPool
from keystone.common import config
from keystone.backends.sqlalchemy import models
import keystone.utils as utils
import keystone.backends.api as top_api
import keystone.backends.models as top_models
from keystone.test import sampledata
_ENGINE = None
_MAKER = None
BASE = models.Base
MODEL_PREFIX = 'keystone.backends.sqlalchemy.models.'
API_PREFIX = 'keystone.backends.sqlalchemy.api.'
FOR_TESTING_ONLY = 'for_testing_only'
def configure_backend(options):
@ -49,15 +52,28 @@ def configure_backend(options):
options, 'verbose', type='bool', default=False)
timeout = config.get_option(
options, 'sql_idle_timeout', type='int', default=3600)
_ENGINE = create_engine(options['sql_connection'],
pool_recycle=timeout)
if options['sql_connection'] == FOR_TESTING_ONLY:
_ENGINE = create_engine('sqlite://',
connect_args={'check_same_thread': False},
poolclass=StaticPool)
else:
_ENGINE = create_engine(options['sql_connection'],
pool_recycle=timeout)
logger = logging.getLogger('sqlalchemy.engine')
if debug:
logger.setLevel(logging.DEBUG)
elif verbose:
logger.setLevel(logging.INFO)
register_models(options)
# this is TERRIBLE coupling, but...
# if we're starting up a test database, load sample fixtures
if options['sql_connection'] == FOR_TESTING_ONLY:
sampledata.load_fixture()
def get_session(autocommit=True, expire_on_commit=False):
"""Helper method to grab session"""

View File

@ -67,17 +67,13 @@ class KeystoneTest(object):
self.clear_database()
self.construct_temp_conf_file()
# Populate the test database
print "Populating registry and token databases..."
execute('sampledata -c %s' % self.conf_fp.name)
# run the keystone server
print "Starting the keystone server..."
self.server = subprocess.Popen(
[os.path.join(BASE_DIR, 'bin/keystone'), '-c', self.conf_fp.name])
# blatent hack.
time.sleep(3)
time.sleep(1)
if self.server.poll() is not None:
raise RuntimeError('Failed to start server')

View File

@ -16,7 +16,7 @@ keystone-admin-role = Admin
keystone-service-admin-role = KeystoneServiceAdmin
[keystone.backends.sqlalchemy]
sql_connection = sqlite:///%(test_dir)s/keystone.db
sql_connection = for_testing_only
sql_idle_timeout = 30
backend_entities = ['Endpoints', 'Credentials', 'EndpointTemplates', 'Token', 'Service']
@ -28,15 +28,15 @@ backend_entities = ['Tenant', 'User', 'UserRoleAssociation', 'Role']
[pipeline:admin]
pipeline =
urlrewritefilter
admin_api
urlrewritefilter
admin_api
[pipeline:keystone-legacy-auth]
pipeline =
urlrewritefilter
legacy_auth
RAX-KEY-extension
service_api
RAX-KEY-extension
service_api
[app:service_api]
paste.app_factory = keystone.server:service_app_factory

View File

@ -16,7 +16,7 @@ keystone-admin-role = Admin
keystone-service-admin-role = KeystoneServiceAdmin
[keystone.backends.sqlalchemy]
sql_connection = sqlite:///%(test_dir)s/keystone.db
sql_connection = for_testing_only
sql_idle_timeout = 30
backend_entities = ['Endpoints', 'Credentials', 'EndpointTemplates', 'Tenant', 'User', 'UserRoleAssociation', 'Role', 'Service']
@ -27,15 +27,15 @@ cache_time = 86400
[pipeline:admin]
pipeline =
urlrewritefilter
admin_api
urlrewritefilter
admin_api
[pipeline:keystone-legacy-auth]
pipeline =
urlrewritefilter
legacy_auth
RAXKEY-extension
service_api
RAX-KEY-extension
service_api
[app:service_api]
paste.app_factory = keystone.server:service_app_factory

View File

@ -16,21 +16,21 @@ keystone-admin-role = Admin
keystone-service-admin-role = KeystoneServiceAdmin
[keystone.backends.sqlalchemy]
sql_connection = sqlite:///%(test_dir)s/keystone.db
sql_connection = for_testing_only
sql_idle_timeout = 30
backend_entities = ['Endpoints', 'Credentials', 'EndpointTemplates', 'Tenant', 'User', 'UserRoleAssociation', 'Role', 'Token', 'Service']
[pipeline:admin]
pipeline =
urlrewritefilter
admin_api
urlrewritefilter
admin_api
[pipeline:keystone-legacy-auth]
pipeline =
urlrewritefilter
legacy_auth
RAX-KEY-extension
service_api
RAX-KEY-extension
service_api
[app:service_api]
paste.app_factory = keystone.server:service_app_factory

View File

@ -20,7 +20,7 @@ class LDAPTest(KeystoneTest):
TESTS = [
SQLTest,
# not running MemcacheTest,
# currently failing, and has yet to pass in jenkins: MemcacheTest,
LDAPTest,
]