Merge "[zmq] Added a processing to handle ImportError in Redis plugin of Matchmaker"

This commit is contained in:
Jenkins 2016-10-03 17:46:36 +00:00 committed by Gerrit Code Review
commit f52e5cfbca
2 changed files with 18 additions and 1 deletions

View File

@ -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.matchmaker import zmq_matchmaker_base
from oslo_messaging._drivers.zmq_driver import zmq_address 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 = importutils.try_import('redis')
redis_sentinel = importutils.try_import('redis.sentinel') redis_sentinel = importutils.try_import('redis.sentinel')
@ -112,6 +112,8 @@ class MatchmakerRedis(zmq_matchmaker_base.MatchmakerBase):
def __init__(self, conf, *args, **kwargs): def __init__(self, conf, *args, **kwargs):
super(MatchmakerRedis, self).__init__(conf, *args, **kwargs) super(MatchmakerRedis, self).__init__(conf, *args, **kwargs)
self.conf.register_opts(matchmaker_redis_opts, "matchmaker_redis") 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() self.sentinel_hosts = self._extract_sentinel_options()
if not self.sentinel_hosts: if not self.sentinel_hosts:

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
from fixtures._fixtures import timeout from fixtures._fixtures import timeout
import inspect
import retrying import retrying
from stevedore import driver from stevedore import driver
import testscenarios import testscenarios
@ -100,3 +101,17 @@ class TestImplMatchmaker(test_utils.BaseTestCase):
except (timeout.TimeoutException, retrying.RetryError): except (timeout.TimeoutException, retrying.RetryError):
pass pass
self.assertEqual([], hosts) 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