From d9bb2f4b94dce727427e4fe57a52214e606c1fb0 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Tue, 6 Oct 2015 18:29:13 -0700 Subject: [PATCH] ConfFixture should work even when zmq/redis is not present Previous driver and other locations in the code we used zmq_async.import_zmq() and importutils.try_import() to not fail fast when pyzmq and redis python packages are not installed. If we don't do this, we are going to break Nova/Cinder/Glance etc. Closes-Bug: #1503499 Change-Id: I1529241b5e1d902b37d6b610646a5a46a18f13b0 --- .../_drivers/zmq_driver/broker/zmq_broker.py | 4 ++-- .../_drivers/zmq_driver/broker/zmq_queue_proxy.py | 2 +- .../zmq_driver/matchmaker/matchmaker_redis.py | 4 ++-- .../_drivers/zmq_driver/poller/threading_poller.py | 4 +++- oslo_messaging/_drivers/zmq_driver/zmq_async.py | 11 +++++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/oslo_messaging/_drivers/zmq_driver/broker/zmq_broker.py b/oslo_messaging/_drivers/zmq_driver/broker/zmq_broker.py index 163d3c174..5f20b807d 100644 --- a/oslo_messaging/_drivers/zmq_driver/broker/zmq_broker.py +++ b/oslo_messaging/_drivers/zmq_driver/broker/zmq_broker.py @@ -18,12 +18,12 @@ import os from oslo_utils import excutils import six from stevedore import driver -import zmq from oslo_messaging._drivers.zmq_driver.broker import zmq_queue_proxy +from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._i18n import _LE, _LI - +zmq = zmq_async.import_zmq(zmq_concurrency='native') LOG = logging.getLogger(__name__) diff --git a/oslo_messaging/_drivers/zmq_driver/broker/zmq_queue_proxy.py b/oslo_messaging/_drivers/zmq_driver/broker/zmq_queue_proxy.py index c3c547fe5..11114d008 100644 --- a/oslo_messaging/_drivers/zmq_driver/broker/zmq_queue_proxy.py +++ b/oslo_messaging/_drivers/zmq_driver/broker/zmq_queue_proxy.py @@ -15,7 +15,6 @@ import logging import six -import zmq from oslo_messaging._drivers.zmq_driver.broker import zmq_base_proxy from oslo_messaging._drivers.zmq_driver.client.publishers\ @@ -24,6 +23,7 @@ from oslo_messaging._drivers.zmq_driver import zmq_address from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._i18n import _LI +zmq = zmq_async.import_zmq(zmq_concurrency='native') LOG = logging.getLogger(__name__) diff --git a/oslo_messaging/_drivers/zmq_driver/matchmaker/matchmaker_redis.py b/oslo_messaging/_drivers/zmq_driver/matchmaker/matchmaker_redis.py index ac4633bb2..c8402c6c8 100644 --- a/oslo_messaging/_drivers/zmq_driver/matchmaker/matchmaker_redis.py +++ b/oslo_messaging/_drivers/zmq_driver/matchmaker/matchmaker_redis.py @@ -14,11 +14,11 @@ import logging from oslo_config import cfg -import redis +from oslo_utils import importutils from oslo_messaging._drivers.zmq_driver.matchmaker import base - +redis = importutils.try_import('redis') LOG = logging.getLogger(__name__) diff --git a/oslo_messaging/_drivers/zmq_driver/poller/threading_poller.py b/oslo_messaging/_drivers/zmq_driver/poller/threading_poller.py index 0c2beea0d..c0a46d981 100644 --- a/oslo_messaging/_drivers/zmq_driver/poller/threading_poller.py +++ b/oslo_messaging/_drivers/zmq_driver/poller/threading_poller.py @@ -16,10 +16,12 @@ import logging import threading from oslo_utils import eventletutils -import zmq +from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._drivers.zmq_driver import zmq_poller +zmq = zmq_async.import_zmq(zmq_concurrency='native') + LOG = logging.getLogger(__name__) _threading = threading diff --git a/oslo_messaging/_drivers/zmq_driver/zmq_async.py b/oslo_messaging/_drivers/zmq_driver/zmq_async.py index c228e7215..7a993a285 100644 --- a/oslo_messaging/_drivers/zmq_driver/zmq_async.py +++ b/oslo_messaging/_drivers/zmq_driver/zmq_async.py @@ -14,8 +14,6 @@ import logging -from oslo_messaging._drivers.zmq_driver.poller import green_poller -from oslo_messaging._drivers.zmq_driver.poller import threading_poller from oslo_messaging._i18n import _, _LE from oslo_utils import importutils @@ -45,7 +43,10 @@ def get_poller(zmq_concurrency='eventlet'): _raise_error_if_invalid_config_value(zmq_concurrency) if zmq_concurrency == 'eventlet' and _is_eventlet_zmq_available(): + from oslo_messaging._drivers.zmq_driver.poller import green_poller return green_poller.GreenPoller() + + from oslo_messaging._drivers.zmq_driver.poller import threading_poller return threading_poller.ThreadingPoller() @@ -53,7 +54,10 @@ def get_reply_poller(zmq_concurrency='eventlet'): _raise_error_if_invalid_config_value(zmq_concurrency) if zmq_concurrency == 'eventlet' and _is_eventlet_zmq_available(): + from oslo_messaging._drivers.zmq_driver.poller import green_poller return green_poller.HoldReplyPoller() + + from oslo_messaging._drivers.zmq_driver.poller import threading_poller return threading_poller.ThreadingPoller() @@ -61,7 +65,10 @@ def get_executor(method, zmq_concurrency='eventlet'): _raise_error_if_invalid_config_value(zmq_concurrency) if zmq_concurrency == 'eventlet' and _is_eventlet_zmq_available(): + from oslo_messaging._drivers.zmq_driver.poller import green_poller return green_poller.GreenExecutor(method) + + from oslo_messaging._drivers.zmq_driver.poller import threading_poller return threading_poller.ThreadingExecutor(method)