Properly skip zmq tests without ZeroMQ being installed
In this change import_zmq() doesn't raise ImportError any more for the benefit of skipping tests. Alarm about zmq unavailability moved to driver's init. Change-Id: I6e6acc39f42c979333510064d9e845228400d233 Closes-Bug: #1522920
This commit is contained in:
parent
ee240fbb8d
commit
52ccff7cbc
@ -26,7 +26,9 @@ from oslo_messaging._drivers import common as rpc_common
|
|||||||
from oslo_messaging._drivers.zmq_driver.client import zmq_client
|
from oslo_messaging._drivers.zmq_driver.client import zmq_client
|
||||||
from oslo_messaging._drivers.zmq_driver.client import zmq_client_light
|
from oslo_messaging._drivers.zmq_driver.client import zmq_client_light
|
||||||
from oslo_messaging._drivers.zmq_driver.server import zmq_server
|
from oslo_messaging._drivers.zmq_driver.server import zmq_server
|
||||||
|
from oslo_messaging._drivers.zmq_driver import zmq_async
|
||||||
from oslo_messaging._executors import impl_pooledexecutor # FIXME(markmc)
|
from oslo_messaging._executors import impl_pooledexecutor # FIXME(markmc)
|
||||||
|
from oslo_messaging._i18n import _LE
|
||||||
|
|
||||||
|
|
||||||
pformat = pprint.pformat
|
pformat = pprint.pformat
|
||||||
@ -162,6 +164,10 @@ class ZmqDriver(base.BaseDriver):
|
|||||||
:param allowed_remote_exmods: remote exception passing options
|
:param allowed_remote_exmods: remote exception passing options
|
||||||
:type allowed_remote_exmods: list
|
:type allowed_remote_exmods: list
|
||||||
"""
|
"""
|
||||||
|
zmq = zmq_async.import_zmq()
|
||||||
|
if zmq is None:
|
||||||
|
raise ImportError(_LE("ZeroMQ is not available!"))
|
||||||
|
|
||||||
conf.register_opts(zmq_opts)
|
conf.register_opts(zmq_opts)
|
||||||
conf.register_opts(impl_pooledexecutor._pool_opts)
|
conf.register_opts(impl_pooledexecutor._pool_opts)
|
||||||
conf.register_opts(base.base_opts)
|
conf.register_opts(base.base_opts)
|
||||||
|
@ -30,12 +30,10 @@ def import_zmq(zmq_concurrency='eventlet'):
|
|||||||
_raise_error_if_invalid_config_value(zmq_concurrency)
|
_raise_error_if_invalid_config_value(zmq_concurrency)
|
||||||
|
|
||||||
imported_zmq = importutils.try_import(ZMQ_MODULES[zmq_concurrency],
|
imported_zmq = importutils.try_import(ZMQ_MODULES[zmq_concurrency],
|
||||||
default='zmq')
|
default=None)
|
||||||
|
|
||||||
if imported_zmq is None:
|
if imported_zmq is None:
|
||||||
errmsg = _LE("ZeroMQ not found!")
|
|
||||||
LOG.error(_LE("ZeroMQ not found!"))
|
LOG.error(_LE("ZeroMQ not found!"))
|
||||||
raise ImportError(errmsg)
|
|
||||||
return imported_zmq
|
return imported_zmq
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,6 +224,7 @@ class TestZmqBasics(ZmqBaseTestCase):
|
|||||||
|
|
||||||
class TestPoller(test_utils.BaseTestCase):
|
class TestPoller(test_utils.BaseTestCase):
|
||||||
|
|
||||||
|
@testtools.skipIf(zmq is None, "zmq not available")
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPoller, self).setUp()
|
super(TestPoller, self).setUp()
|
||||||
self.poller = zmq_async.get_poller()
|
self.poller = zmq_async.get_poller()
|
||||||
|
@ -11,15 +11,19 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import testtools
|
||||||
|
|
||||||
from oslo_messaging._drivers.zmq_driver.poller import green_poller
|
from oslo_messaging._drivers.zmq_driver.poller import green_poller
|
||||||
from oslo_messaging._drivers.zmq_driver.poller import threading_poller
|
from oslo_messaging._drivers.zmq_driver.poller import threading_poller
|
||||||
from oslo_messaging._drivers.zmq_driver import zmq_async
|
from oslo_messaging._drivers.zmq_driver import zmq_async
|
||||||
from oslo_messaging.tests import utils as test_utils
|
from oslo_messaging.tests import utils as test_utils
|
||||||
|
|
||||||
|
zmq = zmq_async.import_zmq()
|
||||||
|
|
||||||
|
|
||||||
class TestImportZmq(test_utils.BaseTestCase):
|
class TestImportZmq(test_utils.BaseTestCase):
|
||||||
|
|
||||||
|
@testtools.skipIf(zmq is None, "zmq not available")
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestImportZmq, self).setUp()
|
super(TestImportZmq, self).setUp()
|
||||||
|
|
||||||
@ -29,12 +33,12 @@ class TestImportZmq(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
zmq_async.importutils.try_import.return_value = 'mock zmq module'
|
zmq_async.importutils.try_import.return_value = 'mock zmq module'
|
||||||
self.assertEqual('mock zmq module', zmq_async.import_zmq('native'))
|
self.assertEqual('mock zmq module', zmq_async.import_zmq('native'))
|
||||||
mock_try_import.assert_called_with('zmq', default='zmq')
|
mock_try_import.assert_called_with('zmq', default=None)
|
||||||
|
|
||||||
zmq_async.importutils.try_import.return_value = 'mock eventlet module'
|
zmq_async.importutils.try_import.return_value = 'mock eventlet module'
|
||||||
self.assertEqual('mock eventlet module',
|
self.assertEqual('mock eventlet module',
|
||||||
zmq_async.import_zmq('eventlet'))
|
zmq_async.import_zmq('eventlet'))
|
||||||
mock_try_import.assert_called_with('eventlet.green.zmq', default='zmq')
|
mock_try_import.assert_called_with('eventlet.green.zmq', default=None)
|
||||||
|
|
||||||
def test_when_no_args_then_default_zmq_module_is_loaded(self):
|
def test_when_no_args_then_default_zmq_module_is_loaded(self):
|
||||||
mock_try_import = mock.Mock()
|
mock_try_import = mock.Mock()
|
||||||
@ -42,14 +46,7 @@ class TestImportZmq(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
zmq_async.import_zmq()
|
zmq_async.import_zmq()
|
||||||
|
|
||||||
mock_try_import.assert_called_with('eventlet.green.zmq', default='zmq')
|
mock_try_import.assert_called_with('eventlet.green.zmq', default=None)
|
||||||
|
|
||||||
def test_when_import_fails_then_raise_ImportError(self):
|
|
||||||
zmq_async.importutils.try_import = mock.Mock()
|
|
||||||
zmq_async.importutils.try_import.return_value = None
|
|
||||||
|
|
||||||
with self.assertRaisesRegexp(ImportError, "ZeroMQ not found!"):
|
|
||||||
zmq_async.import_zmq('native')
|
|
||||||
|
|
||||||
def test_invalid_config_value_raise_ValueError(self):
|
def test_invalid_config_value_raise_ValueError(self):
|
||||||
invalid_opt = 'x'
|
invalid_opt = 'x'
|
||||||
@ -61,6 +58,7 @@ class TestImportZmq(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
class TestGetPoller(test_utils.BaseTestCase):
|
class TestGetPoller(test_utils.BaseTestCase):
|
||||||
|
|
||||||
|
@testtools.skipIf(zmq is None, "zmq not available")
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGetPoller, self).setUp()
|
super(TestGetPoller, self).setUp()
|
||||||
|
|
||||||
@ -100,6 +98,7 @@ class TestGetPoller(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
class TestGetReplyPoller(test_utils.BaseTestCase):
|
class TestGetReplyPoller(test_utils.BaseTestCase):
|
||||||
|
|
||||||
|
@testtools.skipIf(zmq is None, "zmq not available")
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGetReplyPoller, self).setUp()
|
super(TestGetReplyPoller, self).setUp()
|
||||||
|
|
||||||
@ -134,6 +133,7 @@ class TestGetReplyPoller(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
class TestGetExecutor(test_utils.BaseTestCase):
|
class TestGetExecutor(test_utils.BaseTestCase):
|
||||||
|
|
||||||
|
@testtools.skipIf(zmq is None, "zmq not available")
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGetExecutor, self).setUp()
|
super(TestGetExecutor, self).setUp()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user