import cinder.context
import cinder.exception
+from cinder.openstack.common import jsonutils
CONF = cfg.CONF
TRANSPORT = None
TRANSPORT = messaging.get_transport(conf,
allowed_remote_exmods=exmods,
aliases=TRANSPORT_ALIASES)
- NOTIFIER = messaging.Notifier(TRANSPORT,
- serializer=RequestContextSerializer(None))
+
+ serializer = RequestContextSerializer(JsonPayloadSerializer())
+ NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer)
def initialized():
return ALLOWED_EXMODS + EXTRA_EXMODS
+class JsonPayloadSerializer(messaging.NoOpSerializer):
+ @staticmethod
+ def serialize_entity(context, entity):
+ return jsonutils.to_primitive(entity, convert_instances=True)
+
+
class RequestContextSerializer(messaging.Serializer):
def __init__(self, base):
import collections
import functools
+import anyjson
from oslo import messaging
from cinder import rpc
class FakeNotifier(object):
- def __init__(self, transport, publisher_id):
+ def __init__(self, transport, publisher_id, serializer=None):
self.transport = transport
self.publisher_id = publisher_id
for priority in ['debug', 'info', 'warn', 'error', 'critical']:
setattr(self, priority,
functools.partial(self._notify, priority.upper()))
+ self._serializer = serializer or messaging.serializer.NoOpSerializer()
def prepare(self, publisher_id=None):
if publisher_id is None:
publisher_id = self.publisher_id
- return self.__class__(self.transport, publisher_id)
+ return self.__class__(self.transport, publisher_id, self._serializer)
def _notify(self, priority, ctxt, event_type, payload):
+ payload = self._serializer.serialize_entity(ctxt, payload)
+ # NOTE(sileht): simulate the kombu serializer
+ # this permit to raise an exception if something have not
+ # been serialized correctly
+ anyjson.serialize(payload)
msg = dict(publisher_id=self.publisher_id,
priority=priority,
event_type=event_type,
def stub_notifier(stubs):
stubs.Set(messaging, 'Notifier', FakeNotifier)
if rpc.NOTIFIER:
+ serializer = getattr(rpc.NOTIFIER, '_serializer', None)
stubs.Set(rpc, 'NOTIFIER', FakeNotifier(rpc.NOTIFIER.transport,
- rpc.NOTIFIER.publisher_id))
+ rpc.NOTIFIER.publisher_id,
+ serializer=serializer))