diff --git a/aodh/storage/hbase/base.py b/aodh/storage/hbase/base.py index 6db8152b8..0d1fcfd06 100644 --- a/aodh/storage/hbase/base.py +++ b/aodh/storage/hbase/base.py @@ -33,7 +33,7 @@ class Connection(object): opts = self._parse_connection_url(url) if opts['host'] == '__test__': - url = os.environ.get('AODH_TEST_HBASE_URL') + url = os.environ.get('AODH_TEST_STORAGE_URL') if url: # Reparse URL, but from the env variable now opts = self._parse_connection_url(url) diff --git a/aodh/tests/functional/api/v2/test_acl_scenarios.py b/aodh/tests/functional/api/v2/test_acl_scenarios.py index 8cf5da196..ae88aed2f 100644 --- a/aodh/tests/functional/api/v2/test_acl_scenarios.py +++ b/aodh/tests/functional/api/v2/test_acl_scenarios.py @@ -20,11 +20,9 @@ import webtest from aodh.api import app from aodh.tests.functional.api import v2 -from aodh.tests.functional import db as tests_db -class TestAPIACL(v2.FunctionalTest, - tests_db.MixinTestsWithBackendScenarios): +class TestAPIACL(v2.FunctionalTest): def _make_app(self): file_name = self.path_get('etc/aodh/api_paste.ini') diff --git a/aodh/tests/functional/api/v2/test_alarm_scenarios.py b/aodh/tests/functional/api/v2/test_alarm_scenarios.py index eb6415874..e82296764 100644 --- a/aodh/tests/functional/api/v2/test_alarm_scenarios.py +++ b/aodh/tests/functional/api/v2/test_alarm_scenarios.py @@ -29,7 +29,6 @@ from aodh import messaging from aodh.storage import models from aodh.tests import constants from aodh.tests.functional.api import v2 -from aodh.tests.functional import db as tests_db def default_alarms(auth_headers): @@ -138,8 +137,7 @@ def default_alarms(auth_headers): ] -class TestAlarmsBase(v2.FunctionalTest, - tests_db.MixinTestsWithBackendScenarios): +class TestAlarmsBase(v2.FunctionalTest): def setUp(self): super(TestAlarmsBase, self).setUp() diff --git a/aodh/tests/functional/api/v2/test_capabilities.py b/aodh/tests/functional/api/v2/test_capabilities.py index 775f4dbcf..599bbc2a7 100644 --- a/aodh/tests/functional/api/v2/test_capabilities.py +++ b/aodh/tests/functional/api/v2/test_capabilities.py @@ -14,17 +14,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - -import testscenarios - from aodh.tests.functional.api import v2 as tests_api -from aodh.tests.functional import db as tests_db - -load_tests = testscenarios.load_tests_apply_scenarios -class TestCapabilitiesController(tests_api.FunctionalTest, - tests_db.MixinTestsWithBackendScenarios): +class TestCapabilitiesController(tests_api.FunctionalTest): def setUp(self): super(TestCapabilitiesController, self).setUp() diff --git a/aodh/tests/functional/api/v2/test_complex_query_scenarios.py b/aodh/tests/functional/api/v2/test_complex_query_scenarios.py index a839f1f7d..0481f41d0 100644 --- a/aodh/tests/functional/api/v2/test_complex_query_scenarios.py +++ b/aodh/tests/functional/api/v2/test_complex_query_scenarios.py @@ -24,7 +24,6 @@ from oslo_utils import timeutils from aodh.storage import models from aodh.tests.functional.api import v2 as tests_api -from aodh.tests.functional import db as tests_db admin_header = {"X-Roles": "admin", @@ -35,8 +34,7 @@ non_admin_header = {"X-Roles": "Member", "project-id1"} -class TestQueryAlarmsController(tests_api.FunctionalTest, - tests_db.MixinTestsWithBackendScenarios): +class TestQueryAlarmsController(tests_api.FunctionalTest): def setUp(self): super(TestQueryAlarmsController, self).setUp() @@ -202,8 +200,7 @@ class TestQueryAlarmsController(tests_api.FunctionalTest, self.assertIn(b"Limit should be positive", data.body) -class TestQueryAlarmsHistoryController( - tests_api.FunctionalTest, tests_db.MixinTestsWithBackendScenarios): +class TestQueryAlarmsHistoryController(tests_api.FunctionalTest): def setUp(self): super(TestQueryAlarmsHistoryController, self).setUp() diff --git a/aodh/tests/functional/db.py b/aodh/tests/functional/db.py index 5f4df0af6..e0359716f 100644 --- a/aodh/tests/functional/db.py +++ b/aodh/tests/functional/db.py @@ -26,7 +26,6 @@ from oslotest import mockpatch import six from six.moves.urllib import parse as urlparse import sqlalchemy -import testscenarios.testcase from testtools import testcase from aodh import service @@ -120,7 +119,8 @@ class SQLiteManager(fixtures.Fixture): self.url = "sqlite://" -class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): +@six.add_metaclass(test_base.SkipNotImplementedMeta) +class TestBase(test_base.BaseTestCase): DRIVER_MANAGERS = { 'mongodb': MongoDbManager, @@ -132,11 +132,10 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): if mocks is not None: DRIVER_MANAGERS['hbase'] = HBaseManager - db_url = 'sqlite://' # NOTE(Alexei_987) Set default db url - def setUp(self): super(TestBase, self).setUp() - engine = urlparse.urlparse(self.db_url).scheme + db_url = os.environ.get('AODH_TEST_STORAGE_URL', 'sqlite://') + engine = urlparse.urlparse(db_url).scheme # NOTE(Alexei_987) Shortcut to skip expensive db setUp test_method = self._get_test_method() @@ -147,12 +146,14 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): conf = service.prepare_service(argv=[], config_files=[]) self.CONF = self.useFixture(fixture_config.Config(conf)).conf - self.CONF.set_override('connection', self.db_url, group="database") + self.CONF.set_override('connection', db_url, group="database") + + manager = self.DRIVER_MANAGERS.get(engine) + if not manager: + self.skipTest("missing driver manager: %s" % engine) + + self.db_manager = manager(self.CONF) - try: - self.db_manager = self._get_driver_manager(engine)(self.CONF) - except ValueError as exc: - self.skipTest("missing driver manager: %s" % exc) self.useFixture(self.db_manager) self.CONF.set_override('connection', self.db_manager.url, @@ -173,12 +174,6 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): def _get_connection(self, conf): return self.alarm_conn - def _get_driver_manager(self, engine): - manager = self.DRIVER_MANAGERS.get(engine) - if not manager: - raise ValueError('No manager available for %s' % engine) - return manager - def run_with(*drivers): """Used to mark tests that are only applicable for certain db driver. @@ -200,24 +195,3 @@ def run_with(*drivers): test._run_with = drivers return test return decorator - - -@six.add_metaclass(test_base.SkipNotImplementedMeta) -class MixinTestsWithBackendScenarios(object): - - scenarios = [ - ('sqlite', {'db_url': 'sqlite://'}), - ] - - for db in ('MONGODB', 'MYSQL', 'PGSQL', 'HBASE'): - if os.environ.get('AODH_TEST_%s_URL' % db): - scenarios.append( - (db.lower(), {'db_url': os.environ.get( - 'AODH_TEST_%s_URL' % db)})) - - scenarios_db = [db for db, _ in scenarios] - - # Insert default value for hbase test - if 'hbase' not in scenarios_db: - scenarios.append( - ('hbase', {'db_url': 'hbase://__test__'})) diff --git a/aodh/tests/functional/gabbi/fixtures.py b/aodh/tests/functional/gabbi/fixtures.py index d4ddb6059..0fbb9fdb3 100644 --- a/aodh/tests/functional/gabbi/fixtures.py +++ b/aodh/tests/functional/gabbi/fixtures.py @@ -23,6 +23,7 @@ from gabbi import fixture import mock from oslo_config import fixture as fixture_config from oslo_policy import opts +from six.moves.urllib import parse as urlparse from aodh import service from aodh import storage @@ -31,7 +32,7 @@ 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'] +ENGINES = ['mongodb'] class ConfigFixture(fixture.GabbiFixture): @@ -43,16 +44,15 @@ class ConfigFixture(fixture.GabbiFixture): self.conf = None # Determine the database connection. - db_url = None - for engine in ENGINES: - try: - db_url = os.environ['AODH_TEST_%s_URL' % engine] - except KeyError: - pass - if db_url is None: + db_url = os.environ.get('AODH_TEST_STORAGE_URL') + if not db_url: raise case.SkipTest('No database connection configured') - conf = service.prepare_service(argv=[], config_files=[]) + engine = urlparse.urlparse(db_url).scheme + if engine not in ENGINES: + raise case.SkipTest('Database engine not supported') + + conf = service.prepare_service([], config_files=[]) # NOTE(jd): prepare_service() is called twice: first by load_app() for # Pecan, then Pecan calls pastedeploy, which starts the app, which has # no way to pass the conf object so that Paste apps calls again diff --git a/aodh/tests/functional/storage/sqlalchemy/test_migrations.py b/aodh/tests/functional/storage/sqlalchemy/test_migrations.py index e3f184e67..6566d9757 100644 --- a/aodh/tests/functional/storage/sqlalchemy/test_migrations.py +++ b/aodh/tests/functional/storage/sqlalchemy/test_migrations.py @@ -31,7 +31,6 @@ class ABCSkip(base.SkipNotImplementedMeta, abc.ABCMeta): class ModelsMigrationsSync( six.with_metaclass(ABCSkip, tests_db.TestBase, - tests_db.MixinTestsWithBackendScenarios, test_migrations.ModelsMigrationsSync)): def setUp(self): diff --git a/aodh/tests/functional/storage/test_impl_hbase.py b/aodh/tests/functional/storage/test_impl_hbase.py index 020490b08..96b07d94e 100644 --- a/aodh/tests/functional/storage/test_impl_hbase.py +++ b/aodh/tests/functional/storage/test_impl_hbase.py @@ -33,8 +33,7 @@ from aodh.tests import base as test_base from aodh.tests.functional import db as tests_db -class ConnectionTest(tests_db.TestBase, - tests_db.MixinTestsWithBackendScenarios): +class ConnectionTest(tests_db.TestBase): @tests_db.run_with('hbase') def test_hbase_connection(self): diff --git a/aodh/tests/functional/storage/test_impl_mongodb.py b/aodh/tests/functional/storage/test_impl_mongodb.py index e106241e5..c26680d0a 100644 --- a/aodh/tests/functional/storage/test_impl_mongodb.py +++ b/aodh/tests/functional/storage/test_impl_mongodb.py @@ -27,8 +27,7 @@ from aodh.tests.functional import db as tests_db @tests_db.run_with('mongodb') -class MongoDBConnection(tests_db.TestBase, - tests_db.MixinTestsWithBackendScenarios): +class MongoDBConnection(tests_db.TestBase): def test_connection_pooling(self): test_conn = impl_mongodb.Connection(self.CONF, self.CONF.database.connection) @@ -41,9 +40,7 @@ class MongoDBConnection(tests_db.TestBase, @tests_db.run_with('mongodb') -class IndexTest(tests_db.TestBase, - tests_db.MixinTestsWithBackendScenarios): - +class IndexTest(tests_db.TestBase): def _test_ttl_index_absent(self, conn, coll_name, ttl_opt): # create a fake index and check it is deleted coll = getattr(conn.db, coll_name) diff --git a/aodh/tests/functional/storage/test_storage_scenarios.py b/aodh/tests/functional/storage/test_storage_scenarios.py index c1c048270..1d6ab24c1 100644 --- a/aodh/tests/functional/storage/test_storage_scenarios.py +++ b/aodh/tests/functional/storage/test_storage_scenarios.py @@ -138,8 +138,7 @@ class AlarmTestBase(DBTestBase): self.alarm_conn.create_alarm(a) -class AlarmTest(AlarmTestBase, - tests_db.MixinTestsWithBackendScenarios): +class AlarmTest(AlarmTestBase): def test_empty(self): alarms = list(self.alarm_conn.get_alarms()) @@ -254,8 +253,7 @@ class AlarmTest(AlarmTestBase, @tests_db.run_with('sqlite', 'mysql', 'pgsql', 'hbase') -class AlarmHistoryTest(AlarmTestBase, - tests_db.MixinTestsWithBackendScenarios): +class AlarmHistoryTest(AlarmTestBase): def setUp(self): super(AlarmTestBase, self).setUp() @@ -308,8 +306,7 @@ class AlarmHistoryTest(AlarmTestBase, self.assertEqual(0, len(history)) -class ComplexAlarmQueryTest(AlarmTestBase, - tests_db.MixinTestsWithBackendScenarios): +class ComplexAlarmQueryTest(AlarmTestBase): def test_no_filter(self): self.add_some_alarms() @@ -371,8 +368,7 @@ class ComplexAlarmQueryTest(AlarmTestBase, self.assertTrue(a.enabled) -class ComplexAlarmHistoryQueryTest(AlarmTestBase, - tests_db.MixinTestsWithBackendScenarios): +class ComplexAlarmHistoryQueryTest(AlarmTestBase): def setUp(self): super(DBTestBase, self).setUp() self.filter_expr = {"and": diff --git a/functions.sh b/functions.sh index 4b6f5e704..ead5eb498 100644 --- a/functions.sh +++ b/functions.sh @@ -1,9 +1,5 @@ function clean_exit(){ local error_code="$?" - if test -n "$AODH_TEST_HBASE_URL" - then - python tools/test_hbase_table_utils.py --clear - fi rm -rf "$1" kill $(jobs -p) return $error_code diff --git a/setup-test-env-mongodb.sh b/setup-test-env-mongodb.sh index 4676ba112..6374d2c58 100755 --- a/setup-test-env-mongodb.sh +++ b/setup-test-env-mongodb.sh @@ -21,12 +21,7 @@ mongod --maxConns 32 --nojournal --noprealloc --smallfiles --quiet --noauth --po wait_for_line "waiting for connections on port ${MONGO_PORT}" ${MONGO_DATA}/out # Read the fifo for ever otherwise mongod would block cat ${MONGO_DATA}/out > /dev/null & -export AODH_TEST_MONGODB_URL="mongodb://localhost:${MONGO_PORT}/AODH" -if test -n "$AODH_TEST_HBASE_URL" -then - export AODH_TEST_HBASE_TABLE_PREFIX=$(hexdump -n 16 -v -e '/1 "%02X"' /dev/urandom) - python tools/test_hbase_table_utils.py --upgrade -fi +export AODH_TEST_STORAGE_URL="mongodb://localhost:${MONGO_PORT}/AODH" # Yield execution to venv command $* diff --git a/setup-test-env-mysql.sh b/setup-test-env-mysql.sh index e6145328e..81d446923 100755 --- a/setup-test-env-mysql.sh +++ b/setup-test-env-mysql.sh @@ -22,7 +22,7 @@ mkfifo ${MYSQL_DATA}/out mysqld --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out & # Wait for MySQL to start listening to connections wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out -export AODH_TEST_MYSQL_URL="mysql+pymysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8" +export AODH_TEST_STORAGE_URL="mysql+pymysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8" # Yield execution to venv command $* diff --git a/setup-test-env-postgresql.sh b/setup-test-env-postgresql.sh index 7175d4bdb..34676956d 100755 --- a/setup-test-env-postgresql.sh +++ b/setup-test-env-postgresql.sh @@ -28,7 +28,7 @@ ${PGSQL_PATH}/pg_ctl initdb -D ${PGSQL_DATA} trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-k ${PGSQL_DATA} -p ${PGSQL_PORT}" start -export AODH_TEST_PGSQL_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1" +export AODH_TEST_STORAGE_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1" # Yield execution to venv command $* diff --git a/test-requirements.txt b/test-requirements.txt index 351238257..19a7cbbfa 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -20,7 +20,6 @@ sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 sphinxcontrib-httpdomain sphinxcontrib-pecanwsme>=0.8 testrepository>=0.0.18 -testscenarios>=0.4 testtools>=1.4.0 gabbi>=0.12.0 # Apache-2.0 # Provides subunit-trace diff --git a/tools/test_hbase_table_utils.py b/tools/test_hbase_table_utils.py index 6fec2e3fe..ed7780d70 100644 --- a/tools/test_hbase_table_utils.py +++ b/tools/test_hbase_table_utils.py @@ -20,9 +20,9 @@ from aodh import storage def main(argv): cfg.CONF([], project='aodh') - if os.getenv("AODH_TEST_HBASE_URL"): + if os.getenv("AODH_TEST_STORAGE_URL"): url = ("%s?table_prefix=%s" % - (os.getenv("AODH_TEST_HBASE_URL"), + (os.getenv("AODH_TEST_STORAGE_URL"), os.getenv("AODH_TEST_HBASE_TABLE_PREFIX", "test"))) cfg.CONF.set_override("connection", url, group="database") alarm_conn = storage.get_connection_from_conf(cfg.CONF)