def test_object_serialization(self): ser = base.MoganObjectSerializer() obj = MyObj(self.context) primitive = ser.serialize_entity(self.context, obj) self.assertIn('mogan_object.name', primitive) obj2 = ser.deserialize_entity(self.context, primitive) self.assertIsInstance(obj2, MyObj) self.assertEqual(self.context, obj2._context)
def __init__(self, topic=None): super(EngineAPI, self).__init__() self.topic = topic if self.topic is None: self.topic = constants.ENGINE_TOPIC target = messaging.Target(topic=self.topic, version='1.0') serializer = objects_base.MoganObjectSerializer() self.client = rpc.get_client(target, version_cap=self.RPC_API_VERSION, serializer=serializer)
def test_object_serialization_iterables(self): ser = base.MoganObjectSerializer() obj = MyObj(self.context) for iterable in (list, tuple, set): thing = iterable([obj]) primitive = ser.serialize_entity(self.context, thing) self.assertEqual(1, len(primitive)) for item in primitive: self.assertNotIsInstance(item, base.MoganObject) thing2 = ser.deserialize_entity(self.context, primitive) self.assertEqual(1, len(thing2)) for item in thing2: self.assertIsInstance(item, MyObj)
def start(self): super(RPCService, self).start() admin_context = context.get_admin_context() target = messaging.Target(topic=self.topic, server=self.host) endpoints = [self.manager] serializer = objects_base.MoganObjectSerializer() self.rpcserver = rpc.get_server(target, endpoints, serializer) self.rpcserver.start() self.manager.init_host() if isinstance(self.manager, periodic_task.PeriodicTasks): self.tg.add_dynamic_timer( self.manager.periodic_tasks, periodic_interval_max=CONF.periodic_interval, context=admin_context) LOG.info( 'Created RPC server for service %(service)s on host ' '%(host)s.', { 'service': self.topic, 'host': self.host })