예제 #1
0
 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)
예제 #2
0
파일: rpcapi.py 프로젝트: YuShangbin/mogan
    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)
예제 #3
0
 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)
예제 #4
0
파일: service.py 프로젝트: weizai118/mogan
    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
            })