Merge "[zmq] Added a processing to handle ImportError in Redis plugin of Matchmaker"
This commit is contained in:
commit
f52e5cfbca
@ -19,7 +19,7 @@ from oslo_utils import importutils
|
||||
|
||||
from oslo_messaging._drivers.zmq_driver.matchmaker import zmq_matchmaker_base
|
||||
from oslo_messaging._drivers.zmq_driver import zmq_address
|
||||
from oslo_messaging._i18n import _LW
|
||||
from oslo_messaging._i18n import _LW, _LE
|
||||
|
||||
redis = importutils.try_import('redis')
|
||||
redis_sentinel = importutils.try_import('redis.sentinel')
|
||||
@ -112,6 +112,8 @@ class MatchmakerRedis(zmq_matchmaker_base.MatchmakerBase):
|
||||
def __init__(self, conf, *args, **kwargs):
|
||||
super(MatchmakerRedis, self).__init__(conf, *args, **kwargs)
|
||||
self.conf.register_opts(matchmaker_redis_opts, "matchmaker_redis")
|
||||
if redis is None:
|
||||
raise ImportError(_LE("Redis package is not available!"))
|
||||
|
||||
self.sentinel_hosts = self._extract_sentinel_options()
|
||||
if not self.sentinel_hosts:
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from fixtures._fixtures import timeout
|
||||
import inspect
|
||||
import retrying
|
||||
from stevedore import driver
|
||||
import testscenarios
|
||||
@ -100,3 +101,17 @@ class TestImplMatchmaker(test_utils.BaseTestCase):
|
||||
except (timeout.TimeoutException, retrying.RetryError):
|
||||
pass
|
||||
self.assertEqual([], hosts)
|
||||
|
||||
def test_handle_redis_package_error(self):
|
||||
if self.rpc_zmq_matchmaker == "redis":
|
||||
# move 'redis' variable to prevent this case affect others
|
||||
module = inspect.getmodule(self.test_matcher)
|
||||
redis_package = module.redis
|
||||
|
||||
# 'redis' variable is set None, when importing package is failed
|
||||
module.redis = None
|
||||
self.assertRaises(ImportError, self.test_matcher.__init__,
|
||||
self.conf)
|
||||
|
||||
# retrieve 'redis' variable wihch is set originally
|
||||
module.redis = redis_package
|
||||
|
Loading…
Reference in New Issue
Block a user