summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Gibizer <balazs.gibizer@est.tech>2019-09-20 19:33:27 +0200
committerBalazs Gibizer <balazs.gibizer@est.tech>2019-09-21 14:53:29 +0200
commitd8980bfed8621eadce36c6a56944ca23245187a6 (patch)
tree1328513bdbfdf7d31cc162267bc50876df8d2cea
parent440357d74027650701d74a82437921fe946fa347 (diff)
downloadoslo-messaging-d8980bfed8621eadce36c6a56944ca23245187a6.tar.gz
Align message serialization between drivers
Every in tree driver that implements RPC send uses jsonutils.dumps to serialize the message, except FakeDriver. FakeDriver uses json.dumps. However json.dumps is a lot more strict than jsonutils. This caused nova to introduce test specific changes in the rpc handling [1]. This patch makes sure that each driver uses the same json serialization. I've tried to dig in to the history of the strictness of the FakeDriver. That driver with the json.dumps() call was added back in 2013 with e2b74cc9e6605156dfd6e36cdfd1b5136161d526. (I cannot link to that commit in any online way but it is in my local git clone.) Checking out that commit I don't see any other drivers present in the repo but the code does mention drivers like RabbitDriver and ZmqDriver in oslo.messaging/openstack/common/messaging/drivers.py but only there. Today the oslo_messaging._drivers.common.serialize_msg() call is used to do the final serialization of the message. It uses jsonutils.dumps since Icd54ee8e3f5c976dfd50b4b62c7f51288649e112 which is a revert of I0e0f6b715ffc4a9ad82be52e55696d032b6d0976 that changed from jsonutils.dumps to jsonutils.dump_as_bytes by mistake. And before this back and forth it was jsonutils.dumps since the code was imported from oslo-incubator by I38507382b1ce68c7f8f697522f9a1bf00e76532d. Here I lost the trail. Honestly I don't know the reason why the fake driver was made stricter than the real drivers. Still I think today the strictness is unnecessary as every driver uses jsonutils and even counterproductive as in [1]. [1] https://github.com/openstack/nova/blob/09bf71407f4c0d1ddbef89c489ec87c3bca0b7b2/nova/compute/rpcapi.py#L820 Change-Id: I186305b7897a2a4ce033c11ab9e6bc028854381b Closes-Bug: #1529084
-rw-r--r--oslo_messaging/_drivers/impl_fake.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/oslo_messaging/_drivers/impl_fake.py b/oslo_messaging/_drivers/impl_fake.py
index 05300e7..c5476fd 100644
--- a/oslo_messaging/_drivers/impl_fake.py
+++ b/oslo_messaging/_drivers/impl_fake.py
@@ -14,10 +14,10 @@
# under the License.
import copy
-import json
import threading
import time
+from oslo_serialization import jsonutils
from six import moves
import oslo_messaging
@@ -180,13 +180,11 @@ class FakeDriver(base.BaseDriver):
def _check_serialize(message):
"""Make sure a message intended for rpc can be serialized.
- We specifically want to use json, not our own jsonutils because
- jsonutils has some extra logic to automatically convert objects to
- primitive types so that they can be serialized. We want to catch all
- cases where non-primitive types make it into this code and treat it as
- an error.
+ All the in tree drivers implementing RPC send uses jsonutils.dumps on
+ the message. So in the test we ensure here that all the messages are
+ serializable with this call.
"""
- json.dumps(message)
+ jsonutils.dumps(message)
def _send(self, target, ctxt, message, wait_for_reply=None, timeout=None,
transport_options=None):