diff --git a/oslo_messaging/_drivers/common.py b/oslo_messaging/_drivers/common.py index 7b446d74d..bad575832 100644 --- a/oslo_messaging/_drivers/common.py +++ b/oslo_messaging/_drivers/common.py @@ -197,13 +197,13 @@ def serialize_remote_exception(failure_info, log_failure=True): 'kwargs': kwargs } - json_data = jsonutils.dumps(data) + json_data = jsonutils.dump_as_bytes(data) return json_data def deserialize_remote_exception(data, allowed_remote_exmods): - failure = jsonutils.loads(six.text_type(data)) + failure = jsonutils.loads(data) trace = failure.get('tb', []) message = failure.get('message', "") + "\n" + "\n".join(trace) @@ -284,7 +284,7 @@ def serialize_msg(raw_msg): # NOTE(russellb) See the docstring for _RPC_ENVELOPE_VERSION for more # information about this format. msg = {_VERSION_KEY: _RPC_ENVELOPE_VERSION, - _MESSAGE_KEY: jsonutils.dumps(raw_msg)} + _MESSAGE_KEY: jsonutils.dump_as_bytes(raw_msg)} return msg diff --git a/oslo_messaging/_drivers/impl_kafka.py b/oslo_messaging/_drivers/impl_kafka.py index 11b72bb28..79511fef3 100644 --- a/oslo_messaging/_drivers/impl_kafka.py +++ b/oslo_messaging/_drivers/impl_kafka.py @@ -126,7 +126,7 @@ class Connection(object): def _send_and_retry(self, message, topic, retry): current_retry = 0 if not isinstance(message, str): - message = jsonutils.dumps(message) + message = jsonutils.dump_as_bytes(message) while message is not None: try: self._send(message, topic) diff --git a/oslo_messaging/_drivers/protocols/amqp/driver.py b/oslo_messaging/_drivers/protocols/amqp/driver.py index 04feb2de1..68efdcb3c 100644 --- a/oslo_messaging/_drivers/protocols/amqp/driver.py +++ b/oslo_messaging/_drivers/protocols/amqp/driver.py @@ -56,7 +56,7 @@ def marshal_response(reply=None, failure=None): data = {"failure": failure} else: data = {"response": reply} - msg.body = jsonutils.dumps(data) + msg.body = jsonutils.dump_as_bytes(data) return msg @@ -80,7 +80,7 @@ def marshal_request(request, context, envelope): "request": request, "context": context } - msg.body = jsonutils.dumps(data) + msg.body = jsonutils.dump_as_bytes(data) return msg diff --git a/oslo_messaging/notify/_impl_log.py b/oslo_messaging/notify/_impl_log.py index 7322f07b6..ceca6d451 100644 --- a/oslo_messaging/notify/_impl_log.py +++ b/oslo_messaging/notify/_impl_log.py @@ -40,6 +40,7 @@ class LogDriver(notifier.Driver): message['event_type'])) method = getattr(logger, priority.lower(), None) if method: + # NOTE: The logger needs json formatted string instead of bytes method(jsonutils.dumps(strutils.mask_dict_password(message))) else: warnings.warn('Unable to log message as notify cannot find a ' diff --git a/oslo_messaging/tests/drivers/test_impl_kafka.py b/oslo_messaging/tests/drivers/test_impl_kafka.py index 7f1d5e377..5843d92ce 100644 --- a/oslo_messaging/tests/drivers/test_impl_kafka.py +++ b/oslo_messaging/tests/drivers/test_impl_kafka.py @@ -145,7 +145,7 @@ class TestKafkaConnection(test_utils.BaseTestCase): conn.consumer = mock.MagicMock() conn.consumer.fetch_messages = mock.MagicMock( - return_value=iter([jsonutils.dumps(fake_message)])) + return_value=iter([jsonutils.dump_as_bytes(fake_message)])) self.assertEqual(fake_message, jsonutils.loads(conn.consume()[0])) self.assertEqual(1, len(conn.consumer.fetch_messages.mock_calls)) diff --git a/oslo_messaging/tests/drivers/test_impl_rabbit.py b/oslo_messaging/tests/drivers/test_impl_rabbit.py index bb449606d..b1040f26f 100644 --- a/oslo_messaging/tests/drivers/test_impl_rabbit.py +++ b/oslo_messaging/tests/drivers/test_impl_rabbit.py @@ -919,7 +919,7 @@ class TestReplyWireFormat(test_utils.BaseTestCase): '_reply_q': 'reply_' + uuid.uuid4().hex, }) - msg['oslo.message'] = jsonutils.dumps(msg['oslo.message']) + msg['oslo.message'] = jsonutils.dump_as_bytes(msg['oslo.message']) producer.publish(msg) diff --git a/oslo_messaging/tests/test_exception_serialization.py b/oslo_messaging/tests/test_exception_serialization.py index c1079c0a4..0b2998c00 100644 --- a/oslo_messaging/tests/test_exception_serialization.py +++ b/oslo_messaging/tests/test_exception_serialization.py @@ -293,7 +293,7 @@ class DeserializeRemoteExceptionTestCase(test_utils.BaseTestCase): 'kwargs': self.kwargs, } - serialized = jsonutils.dumps(failure) + serialized = jsonutils.dump_as_bytes(failure) ex = exceptions.deserialize_remote_exception(serialized, self.allowed)