From 09cd9c0fd3413b541bfc375a4bf009ac473fcef8 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Wed, 3 Dec 2014 12:17:18 +0100 Subject: [PATCH] Don't allow call with fanout target Using call with a fanout target is an oddity. This change removes that. Closes bug: #1336759 Change-Id: I5d7dc8a6df72b910d67bbcdddd5256b6ad6ec73a --- oslo/messaging/rpc/client.py | 4 ++++ tests/rpc/test_client.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/oslo/messaging/rpc/client.py b/oslo/messaging/rpc/client.py index af34c6b97..c934e222c 100644 --- a/oslo/messaging/rpc/client.py +++ b/oslo/messaging/rpc/client.py @@ -136,6 +136,10 @@ class _CallContext(object): def call(self, ctxt, method, **kwargs): """Invoke a method and wait for a reply. See RPCClient.call().""" + if self.target.fanout: + raise exceptions.InvalidTarget('A call cannot be used with fanout', + self.target) + msg = self._make_message(ctxt, method, kwargs) msg_ctxt = self.serializer.serialize_context(ctxt) diff --git a/tests/rpc/test_client.py b/tests/rpc/test_client.py index b7e1cff5f..e441e916e 100644 --- a/tests/rpc/test_client.py +++ b/tests/rpc/test_client.py @@ -17,6 +17,7 @@ import testscenarios from oslo.config import cfg from oslo import messaging +from oslo.messaging import exceptions from oslo.messaging import serializer as msg_serializer from tests import utils as test_utils @@ -283,6 +284,26 @@ class TestCallRetry(test_utils.BaseTestCase): client.call({}, 'foo') +class TestCallFanout(test_utils.BaseTestCase): + + scenarios = [ + ('target', dict(prepare=_notset, target={'fanout': True})), + ('prepare', dict(prepare={'fanout': True}, target={})), + ('both', dict(prepare={'fanout': True}, target={'fanout': True})), + ] + + def test_call_fanout(self): + transport = _FakeTransport(self.conf) + client = messaging.RPCClient(transport, + messaging.Target(**self.target)) + + if self.prepare is not _notset: + client = client.prepare(**self.prepare) + + self.assertRaises(exceptions.InvalidTarget, + client.call, {}, 'foo') + + class TestSerializer(test_utils.BaseTestCase): scenarios = [