diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index 3b7ef58f..cbac5f4e 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -31,7 +31,10 @@ from testtools import testcase from ceilometer import storage from ceilometer.tests import base as test_base -from ceilometer.tests import mocks +try: + from ceilometer.tests import mocks +except ImportError: + mocks = None # happybase module is not Python 3 compatible yet class MongoDbManager(fixtures.Fixture): @@ -183,9 +186,10 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): 'postgresql': PgSQLManager, 'db2': MongoDbManager, 'sqlite': SQLiteManager, - 'hbase': HBaseManager, 'es': ElasticSearchManager, } + if mocks is not None: + DRIVER_MANAGERS['hbase'] = HBaseManager db_url = 'sqlite://' # NOTE(Alexei_987) Set default db url @@ -203,7 +207,10 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase): self.CONF = self.useFixture(fixture_config.Config()).conf self.CONF([], project='ceilometer', validate_default_values=True) - self.db_manager = self._get_driver_manager(engine)(self.db_url) + try: + self.db_manager = self._get_driver_manager(engine)(self.db_url) + except ValueError as exc: + self.skipTest("missing driver manager: %s" % exc) self.useFixture(self.db_manager) self.conn = self.db_manager.connection @@ -261,7 +268,10 @@ def run_with(*drivers): for attr in dir(test): value = getattr(test, attr) if callable(value) and attr.startswith('test_'): - value.__func__._run_with = drivers + if six.PY3: + value._run_with = drivers + else: + value.__func__._run_with = drivers else: test._run_with = drivers return test diff --git a/ceilometer/tests/storage/test_get_connection.py b/ceilometer/tests/storage/test_get_connection.py index 55439ebb..7706bdb8 100644 --- a/ceilometer/tests/storage/test_get_connection.py +++ b/ceilometer/tests/storage/test_get_connection.py @@ -14,6 +14,8 @@ # under the License. """Tests for ceilometer/storage/ """ +import unittest + import mock from oslo_config import fixture as fixture_config from oslotest import base @@ -21,7 +23,10 @@ import retrying from ceilometer.alarm.storage import impl_log as impl_log_alarm from ceilometer.alarm.storage import impl_sqlalchemy as impl_sqlalchemy_alarm -from ceilometer.event.storage import impl_hbase as impl_hbase_event +try: + from ceilometer.event.storage import impl_hbase as impl_hbase_event +except ImportError: + impl_hbase_event = None from ceilometer import storage from ceilometer.storage import impl_log from ceilometer.storage import impl_sqlalchemy @@ -85,6 +90,7 @@ class ConnectionConfigTest(base.BaseTestCase): conn = storage.get_connection_from_config(self.CONF, 'alarm') self.assertIsInstance(conn, impl_sqlalchemy_alarm.Connection) + @unittest.skipIf(impl_hbase_event is None, 'need hbase implementation') def test_three_urls(self): self.CONF.set_override("connection", "log://", group="database") self.CONF.set_override("alarm_connection", "sqlite://", diff --git a/ceilometer/tests/storage/test_impl_hbase.py b/ceilometer/tests/storage/test_impl_hbase.py index bd097e3f..326939b6 100644 --- a/ceilometer/tests/storage/test_impl_hbase.py +++ b/ceilometer/tests/storage/test_impl_hbase.py @@ -22,6 +22,13 @@ """ import mock + +try: + import happybase # noqa +except ImportError: + import testtools.testcase + raise testtools.testcase.TestSkipped("happybase is needed") + from ceilometer.alarm.storage import impl_hbase as hbase_alarm from ceilometer.event.storage import impl_hbase as hbase_event from ceilometer.storage import impl_hbase as hbase