From 747e1a4099e003025d523f6ec49395fc91c43f53 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Thu, 15 Aug 2013 21:06:31 +0100 Subject: [PATCH] Fix handling of None, etc. replies A rather embarassing and obvious bug - we're currently not allowing endpoint methods to send replies of None, '', False, [], {}, etc. Change-Id: Ifc5ff8f308f526197559a4df7bed244cff6ed3c1 --- oslo/messaging/_executors/base.py | 4 +--- tests/test_rpc_server.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/oslo/messaging/_executors/base.py b/oslo/messaging/_executors/base.py index 7a58bb4f4..941148107 100644 --- a/oslo/messaging/_executors/base.py +++ b/oslo/messaging/_executors/base.py @@ -32,9 +32,7 @@ class ExecutorBase(object): def _dispatch(self, incoming): try: - reply = self.callback(incoming.ctxt, incoming.message) - if reply: - incoming.reply(reply) + incoming.reply(self.callback(incoming.ctxt, incoming.message)) except messaging.ExpectedException as e: _LOG.debug('Expected exception during message handling (%s)' % e.exc_info[1]) diff --git a/tests/test_rpc_server.py b/tests/test_rpc_server.py index 394bf99e0..27bc6742b 100644 --- a/tests/test_rpc_server.py +++ b/tests/test_rpc_server.py @@ -46,10 +46,10 @@ class ServerSetupMixin(object): class TestSerializer(object): def serialize_entity(self, ctxt, entity): - return 's' + (entity or '') + return ('s' + entity) if entity else entity def deserialize_entity(self, ctxt, entity): - return 'd' + (entity or '') + return ('d' + entity) if entity else entity def serialize_context(self, ctxt): return dict([(k, 's' + v) for k, v in ctxt.items()]) @@ -228,6 +228,11 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin): server_thread = self._setup_server(transport, TestEndpoint()) client = self._setup_client(transport) + self.assertIsNone(client.call({}, 'ping', arg=None)) + self.assertEqual(client.call({}, 'ping', arg=0), 0) + self.assertEqual(client.call({}, 'ping', arg=False), False) + self.assertEqual(client.call({}, 'ping', arg=[]), []) + self.assertEqual(client.call({}, 'ping', arg={}), {}) self.assertEqual(client.call({}, 'ping', arg='foo'), 'dsdsfoo') self._stop_server(client, server_thread) @@ -243,6 +248,11 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin): client = self._setup_client(transport) direct = client.prepare(server='testserver') + self.assertIsNone(direct.call({}, 'ping', arg=None)) + self.assertEqual(client.call({}, 'ping', arg=0), 0) + self.assertEqual(client.call({}, 'ping', arg=False), False) + self.assertEqual(client.call({}, 'ping', arg=[]), []) + self.assertEqual(client.call({}, 'ping', arg={}), {}) self.assertEqual(direct.call({}, 'ping', arg='foo'), 'dsdsfoo') self._stop_server(client, server_thread)