tests: remove testscenarios usage

We actually do not run the tests with different backend at the same
time, so there's no need for scenarios.

Change-Id: I2cc7aaee04834d1949bdb3c547f0d5b893d13aef
This commit is contained in:
Julien Danjou 2015-11-03 17:19:56 +01:00
parent bb870f861a
commit 59e3389655
17 changed files with 38 additions and 97 deletions

View File

@ -33,7 +33,7 @@ class Connection(object):
opts = self._parse_connection_url(url) opts = self._parse_connection_url(url)
if opts['host'] == '__test__': if opts['host'] == '__test__':
url = os.environ.get('AODH_TEST_HBASE_URL') url = os.environ.get('AODH_TEST_STORAGE_URL')
if url: if url:
# Reparse URL, but from the env variable now # Reparse URL, but from the env variable now
opts = self._parse_connection_url(url) opts = self._parse_connection_url(url)

View File

@ -20,11 +20,9 @@ import webtest
from aodh.api import app from aodh.api import app
from aodh.tests.functional.api import v2 from aodh.tests.functional.api import v2
from aodh.tests.functional import db as tests_db
class TestAPIACL(v2.FunctionalTest, class TestAPIACL(v2.FunctionalTest):
tests_db.MixinTestsWithBackendScenarios):
def _make_app(self): def _make_app(self):
file_name = self.path_get('etc/aodh/api_paste.ini') file_name = self.path_get('etc/aodh/api_paste.ini')

View File

@ -29,7 +29,6 @@ from aodh import messaging
from aodh.storage import models from aodh.storage import models
from aodh.tests import constants from aodh.tests import constants
from aodh.tests.functional.api import v2 from aodh.tests.functional.api import v2
from aodh.tests.functional import db as tests_db
def default_alarms(auth_headers): def default_alarms(auth_headers):
@ -138,8 +137,7 @@ def default_alarms(auth_headers):
] ]
class TestAlarmsBase(v2.FunctionalTest, class TestAlarmsBase(v2.FunctionalTest):
tests_db.MixinTestsWithBackendScenarios):
def setUp(self): def setUp(self):
super(TestAlarmsBase, self).setUp() super(TestAlarmsBase, self).setUp()

View File

@ -14,17 +14,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import testscenarios
from aodh.tests.functional.api import v2 as tests_api 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, class TestCapabilitiesController(tests_api.FunctionalTest):
tests_db.MixinTestsWithBackendScenarios):
def setUp(self): def setUp(self):
super(TestCapabilitiesController, self).setUp() super(TestCapabilitiesController, self).setUp()

View File

@ -24,7 +24,6 @@ from oslo_utils import timeutils
from aodh.storage import models from aodh.storage import models
from aodh.tests.functional.api import v2 as tests_api from aodh.tests.functional.api import v2 as tests_api
from aodh.tests.functional import db as tests_db
admin_header = {"X-Roles": "admin", admin_header = {"X-Roles": "admin",
@ -35,8 +34,7 @@ non_admin_header = {"X-Roles": "Member",
"project-id1"} "project-id1"}
class TestQueryAlarmsController(tests_api.FunctionalTest, class TestQueryAlarmsController(tests_api.FunctionalTest):
tests_db.MixinTestsWithBackendScenarios):
def setUp(self): def setUp(self):
super(TestQueryAlarmsController, self).setUp() super(TestQueryAlarmsController, self).setUp()
@ -202,8 +200,7 @@ class TestQueryAlarmsController(tests_api.FunctionalTest,
self.assertIn(b"Limit should be positive", data.body) self.assertIn(b"Limit should be positive", data.body)
class TestQueryAlarmsHistoryController( class TestQueryAlarmsHistoryController(tests_api.FunctionalTest):
tests_api.FunctionalTest, tests_db.MixinTestsWithBackendScenarios):
def setUp(self): def setUp(self):
super(TestQueryAlarmsHistoryController, self).setUp() super(TestQueryAlarmsHistoryController, self).setUp()

View File

@ -26,7 +26,6 @@ from oslotest import mockpatch
import six import six
from six.moves.urllib import parse as urlparse from six.moves.urllib import parse as urlparse
import sqlalchemy import sqlalchemy
import testscenarios.testcase
from testtools import testcase from testtools import testcase
from aodh import service from aodh import service
@ -120,7 +119,8 @@ class SQLiteManager(fixtures.Fixture):
self.url = "sqlite://" self.url = "sqlite://"
class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): @six.add_metaclass(test_base.SkipNotImplementedMeta)
class TestBase(test_base.BaseTestCase):
DRIVER_MANAGERS = { DRIVER_MANAGERS = {
'mongodb': MongoDbManager, 'mongodb': MongoDbManager,
@ -132,11 +132,10 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
if mocks is not None: if mocks is not None:
DRIVER_MANAGERS['hbase'] = HBaseManager DRIVER_MANAGERS['hbase'] = HBaseManager
db_url = 'sqlite://' # NOTE(Alexei_987) Set default db url
def setUp(self): def setUp(self):
super(TestBase, self).setUp() 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 # NOTE(Alexei_987) Shortcut to skip expensive db setUp
test_method = self._get_test_method() 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=[]) conf = service.prepare_service(argv=[], config_files=[])
self.CONF = self.useFixture(fixture_config.Config(conf)).conf 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.useFixture(self.db_manager)
self.CONF.set_override('connection', self.db_manager.url, 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): def _get_connection(self, conf):
return self.alarm_conn 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): def run_with(*drivers):
"""Used to mark tests that are only applicable for certain db driver. """Used to mark tests that are only applicable for certain db driver.
@ -200,24 +195,3 @@ def run_with(*drivers):
test._run_with = drivers test._run_with = drivers
return test return test
return decorator 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__'}))

View File

@ -23,6 +23,7 @@ from gabbi import fixture
import mock import mock
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 aodh import service from aodh import service
from aodh import storage from aodh import storage
@ -31,7 +32,7 @@ from aodh import storage
# TODO(chdent): For now only MongoDB is supported, because of easy # TODO(chdent): For now only MongoDB is supported, because of easy
# database name handling and intentional focus on the API, not the # database name handling and intentional focus on the API, not the
# data store. # data store.
ENGINES = ['MONGODB'] ENGINES = ['mongodb']
class ConfigFixture(fixture.GabbiFixture): class ConfigFixture(fixture.GabbiFixture):
@ -43,16 +44,15 @@ class ConfigFixture(fixture.GabbiFixture):
self.conf = None self.conf = None
# Determine the database connection. # Determine the database connection.
db_url = None db_url = os.environ.get('AODH_TEST_STORAGE_URL')
for engine in ENGINES: if not db_url:
try:
db_url = os.environ['AODH_TEST_%s_URL' % engine]
except KeyError:
pass
if db_url is None:
raise case.SkipTest('No database connection configured') 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 # 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
# no way to pass the conf object so that Paste apps calls again # no way to pass the conf object so that Paste apps calls again

View File

@ -31,7 +31,6 @@ class ABCSkip(base.SkipNotImplementedMeta, abc.ABCMeta):
class ModelsMigrationsSync( class ModelsMigrationsSync(
six.with_metaclass(ABCSkip, six.with_metaclass(ABCSkip,
tests_db.TestBase, tests_db.TestBase,
tests_db.MixinTestsWithBackendScenarios,
test_migrations.ModelsMigrationsSync)): test_migrations.ModelsMigrationsSync)):
def setUp(self): def setUp(self):

View File

@ -33,8 +33,7 @@ from aodh.tests import base as test_base
from aodh.tests.functional import db as tests_db from aodh.tests.functional import db as tests_db
class ConnectionTest(tests_db.TestBase, class ConnectionTest(tests_db.TestBase):
tests_db.MixinTestsWithBackendScenarios):
@tests_db.run_with('hbase') @tests_db.run_with('hbase')
def test_hbase_connection(self): def test_hbase_connection(self):

View File

@ -27,8 +27,7 @@ from aodh.tests.functional import db as tests_db
@tests_db.run_with('mongodb') @tests_db.run_with('mongodb')
class MongoDBConnection(tests_db.TestBase, class MongoDBConnection(tests_db.TestBase):
tests_db.MixinTestsWithBackendScenarios):
def test_connection_pooling(self): def test_connection_pooling(self):
test_conn = impl_mongodb.Connection(self.CONF, test_conn = impl_mongodb.Connection(self.CONF,
self.CONF.database.connection) self.CONF.database.connection)
@ -41,9 +40,7 @@ class MongoDBConnection(tests_db.TestBase,
@tests_db.run_with('mongodb') @tests_db.run_with('mongodb')
class IndexTest(tests_db.TestBase, class IndexTest(tests_db.TestBase):
tests_db.MixinTestsWithBackendScenarios):
def _test_ttl_index_absent(self, conn, coll_name, ttl_opt): def _test_ttl_index_absent(self, conn, coll_name, ttl_opt):
# create a fake index and check it is deleted # create a fake index and check it is deleted
coll = getattr(conn.db, coll_name) coll = getattr(conn.db, coll_name)

View File

@ -138,8 +138,7 @@ class AlarmTestBase(DBTestBase):
self.alarm_conn.create_alarm(a) self.alarm_conn.create_alarm(a)
class AlarmTest(AlarmTestBase, class AlarmTest(AlarmTestBase):
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self): def test_empty(self):
alarms = list(self.alarm_conn.get_alarms()) alarms = list(self.alarm_conn.get_alarms())
@ -254,8 +253,7 @@ class AlarmTest(AlarmTestBase,
@tests_db.run_with('sqlite', 'mysql', 'pgsql', 'hbase') @tests_db.run_with('sqlite', 'mysql', 'pgsql', 'hbase')
class AlarmHistoryTest(AlarmTestBase, class AlarmHistoryTest(AlarmTestBase):
tests_db.MixinTestsWithBackendScenarios):
def setUp(self): def setUp(self):
super(AlarmTestBase, self).setUp() super(AlarmTestBase, self).setUp()
@ -308,8 +306,7 @@ class AlarmHistoryTest(AlarmTestBase,
self.assertEqual(0, len(history)) self.assertEqual(0, len(history))
class ComplexAlarmQueryTest(AlarmTestBase, class ComplexAlarmQueryTest(AlarmTestBase):
tests_db.MixinTestsWithBackendScenarios):
def test_no_filter(self): def test_no_filter(self):
self.add_some_alarms() self.add_some_alarms()
@ -371,8 +368,7 @@ class ComplexAlarmQueryTest(AlarmTestBase,
self.assertTrue(a.enabled) self.assertTrue(a.enabled)
class ComplexAlarmHistoryQueryTest(AlarmTestBase, class ComplexAlarmHistoryQueryTest(AlarmTestBase):
tests_db.MixinTestsWithBackendScenarios):
def setUp(self): def setUp(self):
super(DBTestBase, self).setUp() super(DBTestBase, self).setUp()
self.filter_expr = {"and": self.filter_expr = {"and":

View File

@ -1,9 +1,5 @@
function clean_exit(){ function clean_exit(){
local error_code="$?" local error_code="$?"
if test -n "$AODH_TEST_HBASE_URL"
then
python tools/test_hbase_table_utils.py --clear
fi
rm -rf "$1" rm -rf "$1"
kill $(jobs -p) kill $(jobs -p)
return $error_code return $error_code

View File

@ -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 wait_for_line "waiting for connections on port ${MONGO_PORT}" ${MONGO_DATA}/out
# Read the fifo for ever otherwise mongod would block # Read the fifo for ever otherwise mongod would block
cat ${MONGO_DATA}/out > /dev/null & cat ${MONGO_DATA}/out > /dev/null &
export AODH_TEST_MONGODB_URL="mongodb://localhost:${MONGO_PORT}/AODH" export AODH_TEST_STORAGE_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
# Yield execution to venv command # Yield execution to venv command
$* $*

View File

@ -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 & 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 MySQL to start listening to connections
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out 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 # Yield execution to venv command
$* $*

View File

@ -28,7 +28,7 @@ ${PGSQL_PATH}/pg_ctl initdb -D ${PGSQL_DATA}
trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT 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 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 # Yield execution to venv command
$* $*

View File

@ -20,7 +20,6 @@ sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
sphinxcontrib-httpdomain sphinxcontrib-httpdomain
sphinxcontrib-pecanwsme>=0.8 sphinxcontrib-pecanwsme>=0.8
testrepository>=0.0.18 testrepository>=0.0.18
testscenarios>=0.4
testtools>=1.4.0 testtools>=1.4.0
gabbi>=0.12.0 # Apache-2.0 gabbi>=0.12.0 # Apache-2.0
# Provides subunit-trace # Provides subunit-trace

View File

@ -20,9 +20,9 @@ from aodh import storage
def main(argv): def main(argv):
cfg.CONF([], project='aodh') cfg.CONF([], project='aodh')
if os.getenv("AODH_TEST_HBASE_URL"): if os.getenv("AODH_TEST_STORAGE_URL"):
url = ("%s?table_prefix=%s" % 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"))) os.getenv("AODH_TEST_HBASE_TABLE_PREFIX", "test")))
cfg.CONF.set_override("connection", url, group="database") cfg.CONF.set_override("connection", url, group="database")
alarm_conn = storage.get_connection_from_conf(cfg.CONF) alarm_conn = storage.get_connection_from_conf(cfg.CONF)