Refactor RPC serialization: remove JsonPayloadSerializer class

* This class is not needed in Mistral, we can use the exact same
  class from oslo.messaging
* Changed RpcContextSerializer to use JsonPayloadSerializer by
  default so that we don't have to pass it as a parameter
  every time

Change-Id: Ic4ad92cb732c33e6d1971b50076afde219147536
This commit is contained in:
Renat Akhmerov 2017-02-03 13:17:43 +07:00
parent 1428078e03
commit c30b3bfd26
5 changed files with 7 additions and 19 deletions

View File

@ -19,6 +19,7 @@ from keystoneclient.v3 import client as keystone_client
import logging
from oslo_config import cfg
import oslo_messaging as messaging
from oslo_messaging import serializer as messaging_serializer
from oslo_serialization import jsonutils
from osprofiler import profiler
import pecan
@ -225,15 +226,9 @@ def context_from_config():
)
class JsonPayloadSerializer(messaging.NoOpSerializer):
@staticmethod
def serialize_entity(context, entity):
return jsonutils.to_primitive(entity, convert_instances=True)
class RpcContextSerializer(messaging.Serializer):
def __init__(self, base=None):
self._base = base or messaging.NoOpSerializer()
self._base = base or messaging_serializer.JsonPayloadSerializer()
def serialize_entity(self, context, entity):
if not self._base:

View File

@ -24,8 +24,7 @@ class OsloRPCClient(rpc_base.RPCClient):
super(OsloRPCClient, self).__init__(conf)
self.topic = conf.topic
serializer = auth_ctx.RpcContextSerializer(
auth_ctx.JsonPayloadSerializer())
serializer = auth_ctx.RpcContextSerializer()
self._client = messaging.RPCClient(
rpc.get_transport(),

View File

@ -52,7 +52,7 @@ class OsloRPCServer(rpc_base.RPCServer):
target,
self.endpoints,
executor=executor,
serializer=ctx.RpcContextSerializer(ctx.JsonPayloadSerializer())
serializer=ctx.RpcContextSerializer()
)
self.oslo_server.start()

View File

@ -58,9 +58,7 @@ def schedule_call(factory_method_path, target_method_name,
delayed calls.
:param method_args: Target method keyword arguments.
"""
ctx_serializer = context.RpcContextSerializer(
context.JsonPayloadSerializer()
)
ctx_serializer = context.RpcContextSerializer()
ctx = (
ctx_serializer.serialize_context(context.ctx())
@ -167,9 +165,7 @@ class CallScheduler(periodic_task.PeriodicTasks):
(target_auth_context, target_method, method_args)
)
ctx_serializer = context.RpcContextSerializer(
context.JsonPayloadSerializer()
)
ctx_serializer = context.RpcContextSerializer()
for (target_auth_context, target_method, method_args) in delayed_calls:
try:

View File

@ -40,9 +40,7 @@ class EngineProfilerTest(base.EngineTestCase):
self.mock_profiler_log_func = mock.Mock(return_value=None)
osprofiler.notifier.set(self.mock_profiler_log_func)
self.ctx_serializer = context.RpcContextSerializer(
context.JsonPayloadSerializer()
)
self.ctx_serializer = context.RpcContextSerializer()
def test_profile_trace(self):
wf_def = """