Skip hbase tests on Python 3

The hbase driver requires the Python happybase module which is not
compatible with Python 3 yet.

* Fix run_with() of ceilometer.tests.db on Python 3: no need to get the
  __func__ attribute on Python 3, the method is bounded
* Skip hbase tests if the driver cannot be loaded
* Don't define the HBaseManager class if happybase cannot be imported
* Don't run tests with the hbase driver if the happybase cannot be
  imported

Change-Id: I07803446d089ed62c2368b4f76ff0e028fc4a3bd
This commit is contained in:
Victor Stinner 2015-05-25 13:44:27 +02:00
parent 281d317733
commit 5a18abd21a
3 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -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://",

View File

@ -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