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
This commit is contained in:
parent
dabdc26a1a
commit
f033fc9436
oslo_messaging
@ -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
|
||||
|
@ -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
|
||||
@ -384,6 +385,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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user