summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Ma <skywalker.nick@gmail.com>2015-03-19 00:32:01 -0700
committerLi Ma <skywalker.nick@gmail.com>2015-04-09 13:55:59 +0000
commit513b1c9f3b4727f99f5d637aadb37f3710a8e7d6 (patch)
tree67c66f013d4a164a14f2c826818eb6570d5f9ff3
parentd9c252088130a1d6d0ae87685fbf7bf07e63e583 (diff)
downloadoslo-messaging-513b1c9f3b4727f99f5d637aadb37f3710a8e7d6.tar.gz
Don't raise Timeout on no-matchmaker results
This patch was proposed by this review: https://review.openstack.org/#/c/31231 The unit test is added. Change-Id: Ie124dc22f4ef3bbaeed76186cf08924a39b52812 Co-Authored-By: Eric Windisch <ewindisch@docker.com> Closes-Bug: #1186310 (cherry picked from commit f033fc9436b6f3bc924f19e1457b3cbc85ea548a)
-rw-r--r--oslo_messaging/_drivers/impl_zmq.py11
-rw-r--r--oslo_messaging/tests/drivers/test_impl_zmq.py33
2 files changed, 41 insertions, 3 deletions
diff --git a/oslo_messaging/_drivers/impl_zmq.py b/oslo_messaging/_drivers/impl_zmq.py
index 23961ee..52bd0fa 100644
--- a/oslo_messaging/_drivers/impl_zmq.py
+++ b/oslo_messaging/_drivers/impl_zmq.py
@@ -35,7 +35,7 @@ from six import moves
from oslo_messaging._drivers import base
from oslo_messaging._drivers import common as rpc_common
from oslo_messaging._executors import base as executor_base # FIXME(markmc)
-from oslo_messaging._i18n import _, _LE
+from oslo_messaging._i18n import _, _LE, _LW
zmq = importutils.try_import('eventlet.green.zmq')
@@ -770,10 +770,15 @@ def _multi_send(method, context, topic, msg, timeout=None,
# Don't stack if we have no matchmaker results
if not queues:
- LOG.warn(_("No matchmaker results. Not casting."))
+ warn_log = _LW("No matchmaker results. Not sending.")
+
+ if method.__name__ == '_cast':
+ LOG.warn(warn_log)
+ return
+
# While not strictly a timeout, callers know how to handle
# this exception and a timeout isn't too big a lie.
- raise rpc_common.Timeout(_("No match from matchmaker."))
+ raise rpc_common.Timeout(warn_log)
# This supports brokerless fanout (addresses > 1)
return_val = None
diff --git a/oslo_messaging/tests/drivers/test_impl_zmq.py b/oslo_messaging/tests/drivers/test_impl_zmq.py
index 5f3527d..ee0f034 100644
--- a/oslo_messaging/tests/drivers/test_impl_zmq.py
+++ b/oslo_messaging/tests/drivers/test_impl_zmq.py
@@ -27,6 +27,7 @@ except ImportError:
zmq = None
import oslo_messaging
+from oslo_messaging._drivers import common as rpc_common
from oslo_messaging.tests import utils as test_utils
# eventlet is not yet py3 compatible, so skip if not installed
@@ -385,6 +386,38 @@ class TestZmqListener(ZmqBaseTestCase):
class TestZmqDriver(ZmqBaseTestCase):
@mock.patch('oslo_messaging._drivers.impl_zmq._cast', autospec=True)
+ @mock.patch('oslo_messaging._drivers.matchmaker.MatchMakerBase.queues',
+ autospec=True)
+ def test_zmqdriver_multi_send_cast_with_no_queues(self,
+ mock_queues,
+ mock_cast):
+ context = mock.Mock(autospec=impl_zmq.RpcContext)
+ topic = 'testtopic'
+ msg = 'jeronimo'
+
+ with mock.patch.object(impl_zmq.LOG, 'warn') as flog:
+ mock_queues.return_value = None
+ impl_zmq._multi_send(mock_cast, context, topic, msg)
+ self.assertEqual(1, flog.call_count)
+ args, kwargs = flog.call_args
+ self.assertIn('No matchmaker results', args[0])
+
+ @mock.patch('oslo_messaging._drivers.impl_zmq._call', autospec=True)
+ @mock.patch('oslo_messaging._drivers.matchmaker.MatchMakerBase.queues',
+ autospec=True)
+ def test_zmqdriver_multi_send_call_with_no_queues(self,
+ mock_queues,
+ mock_call):
+ context = mock.Mock(autospec=impl_zmq.RpcContext)
+ topic = 'testtopic'
+ msg = 'jeronimo'
+
+ mock_queues.return_value = None
+ self.assertRaises(rpc_common.Timeout,
+ impl_zmq._multi_send,
+ mock_call, context, topic, msg)
+
+ @mock.patch('oslo_messaging._drivers.impl_zmq._cast', autospec=True)
@mock.patch('oslo_messaging._drivers.impl_zmq._multi_send', autospec=True)
def test_zmqdriver_send(self, mock_multi_send, mock_cast):
context = mock.Mock(autospec=impl_zmq.RpcContext)