Merge "tests/functional: enable Gabbi for all backends"
This commit is contained in:
commit
5f94fbc6c0
@ -25,17 +25,12 @@ from oslo_config import cfg
|
|||||||
from oslo_config import fixture as fixture_config
|
from oslo_config import fixture as fixture_config
|
||||||
from oslo_policy import opts
|
from oslo_policy import opts
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
|
import sqlalchemy_utils
|
||||||
|
|
||||||
from aodh import service
|
from aodh import service
|
||||||
from aodh import storage
|
from aodh import storage
|
||||||
|
|
||||||
|
|
||||||
# TODO(chdent): For now only MongoDB is supported, because of easy
|
|
||||||
# database name handling and intentional focus on the API, not the
|
|
||||||
# data store.
|
|
||||||
ENGINES = ['mongodb']
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigFixture(fixture.GabbiFixture):
|
class ConfigFixture(fixture.GabbiFixture):
|
||||||
"""Establish the relevant configuration for a test run."""
|
"""Establish the relevant configuration for a test run."""
|
||||||
|
|
||||||
@ -43,6 +38,7 @@ class ConfigFixture(fixture.GabbiFixture):
|
|||||||
"""Set up config."""
|
"""Set up config."""
|
||||||
|
|
||||||
self.conf = None
|
self.conf = None
|
||||||
|
self.conn = None
|
||||||
|
|
||||||
# Determine the database connection.
|
# Determine the database connection.
|
||||||
db_url = os.environ.get(
|
db_url = os.environ.get(
|
||||||
@ -53,10 +49,6 @@ class ConfigFixture(fixture.GabbiFixture):
|
|||||||
if not db_url:
|
if not db_url:
|
||||||
raise case.SkipTest('No database connection configured')
|
raise case.SkipTest('No database connection configured')
|
||||||
|
|
||||||
engine = urlparse.urlparse(db_url).scheme
|
|
||||||
if engine not in ENGINES:
|
|
||||||
raise case.SkipTest('Database engine not supported')
|
|
||||||
|
|
||||||
conf = service.prepare_service([], config_files=[])
|
conf = service.prepare_service([], config_files=[])
|
||||||
# NOTE(jd): prepare_service() is called twice: first by load_app() for
|
# NOTE(jd): prepare_service() is called twice: first by load_app() for
|
||||||
# Pecan, then Pecan calls pastedeploy, which starts the app, which has
|
# Pecan, then Pecan calls pastedeploy, which starts the app, which has
|
||||||
@ -83,17 +75,28 @@ class ConfigFixture(fixture.GabbiFixture):
|
|||||||
group='api',
|
group='api',
|
||||||
)
|
)
|
||||||
|
|
||||||
database_name = '%s-%s' % (db_url, str(uuid.uuid4()))
|
|
||||||
conf.set_override('connection', database_name, group='database',
|
|
||||||
enforce_type=True)
|
|
||||||
|
|
||||||
conf.set_override('pecan_debug', True, group='api',
|
conf.set_override('pecan_debug', True, group='api',
|
||||||
enforce_type=True)
|
enforce_type=True)
|
||||||
|
|
||||||
|
parsed_url = list(urlparse.urlparse(db_url))
|
||||||
|
parsed_url[2] += '-%s' % str(uuid.uuid4()).replace('-', '')
|
||||||
|
db_url = urlparse.urlunparse(parsed_url)
|
||||||
|
|
||||||
|
conf.set_override('connection', db_url, group='database',
|
||||||
|
enforce_type=True)
|
||||||
|
|
||||||
|
if (parsed_url[0].startswith("mysql")
|
||||||
|
or parsed_url[0].startswith("postgresql")):
|
||||||
|
sqlalchemy_utils.create_database(conf.database.connection)
|
||||||
|
|
||||||
|
self.conn = storage.get_connection_from_config(self.conf)
|
||||||
|
self.conn.upgrade()
|
||||||
|
|
||||||
def stop_fixture(self):
|
def stop_fixture(self):
|
||||||
"""Reset the config and remove data."""
|
"""Reset the config and remove data."""
|
||||||
|
if self.conn:
|
||||||
|
self.conn.clear()
|
||||||
if self.conf:
|
if self.conf:
|
||||||
storage.get_connection_from_config(self.conf).clear()
|
|
||||||
self.conf.reset()
|
self.conf.reset()
|
||||||
service.prepare_service = self.prepare_service
|
service.prepare_service = self.prepare_service
|
||||||
|
|
||||||
|
@ -32,11 +32,13 @@ data_files =
|
|||||||
[extras]
|
[extras]
|
||||||
mysql =
|
mysql =
|
||||||
SQLAlchemy<1.1.0,>=0.9.7
|
SQLAlchemy<1.1.0,>=0.9.7
|
||||||
|
sqlalchemy-utils
|
||||||
alembic>=0.7.2
|
alembic>=0.7.2
|
||||||
PyMySQL>=0.6.2 # MIT License
|
PyMySQL>=0.6.2 # MIT License
|
||||||
|
|
||||||
postgresql =
|
postgresql =
|
||||||
SQLAlchemy<1.1.0,>=0.9.7
|
SQLAlchemy<1.1.0,>=0.9.7
|
||||||
|
sqlalchemy-utils
|
||||||
alembic>=0.7.2
|
alembic>=0.7.2
|
||||||
psycopg2
|
psycopg2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user