示例#1
0
    def _test_deserialize_entity_newer(self,
                                       obj_version,
                                       backported_to,
                                       mock_indirection_api,
                                       my_version='1.6'):
        ser = base.WatcherObjectSerializer()
        mock_indirection_api.object_backport_versions.return_value \
            = 'backported'

        @base.WatcherObjectRegistry.register
        class MyTestObj(MyObj):
            VERSION = my_version

        obj = MyTestObj(self.context)
        obj.VERSION = obj_version
        primitive = obj.obj_to_primitive()
        result = ser.deserialize_entity(self.context, primitive)
        if backported_to is None:
            self.assertFalse(
                mock_indirection_api.object_backport_versions.called)
        else:
            self.assertEqual('backported', result)
            versions = object_base.obj_tree_get_versions('MyTestObj')
            mock_indirection_api.object_backport_versions.assert_called_with(
                self.context, primitive, versions)
示例#2
0
 def test_object_serialization(self):
     ser = base.WatcherObjectSerializer()
     obj = MyObj(self.context)
     primitive = ser.serialize_entity(self.context, obj)
     self.assertIn('watcher_object.name', primitive)
     obj2 = ser.deserialize_entity(self.context, primitive)
     self.assertIsInstance(obj2, MyObj)
     self.assertEqual(self.context, obj2._context)
示例#3
0
 def test_object_serialization_iterables(self):
     ser = base.WatcherObjectSerializer()
     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.assertFalse(isinstance(item, base.WatcherObject))
         thing2 = ser.deserialize_entity(self.context, primitive)
         self.assertEqual(1, len(thing2))
         for item in thing2:
             self.assertIsInstance(item, MyObj)
示例#4
0
    def __init__(self, publisher_id, conductor_topic, status_topic,
                 api_version=API_VERSION):
        super(MessagingCore, self).__init__()
        self.serializer = rpc.RequestContextSerializer(
            base.WatcherObjectSerializer())
        self.publisher_id = publisher_id
        self.api_version = api_version

        self.conductor_topic = conductor_topic
        self.status_topic = status_topic
        self.conductor_topic_handler = self.build_topic_handler(
            conductor_topic)
        self.status_topic_handler = self.build_topic_handler(status_topic)

        self._conductor_client = None
        self._status_client = None
示例#5
0
    def __init__(self, manager_class):
        super(Service, self).__init__()
        self.manager = manager_class()

        self.publisher_id = self.manager.publisher_id
        self.api_version = self.manager.api_version

        self.conductor_topic = self.manager.conductor_topic
        self.status_topic = self.manager.status_topic
        self.notification_topics = self.manager.notification_topics

        self.conductor_endpoints = [
            ep(self) for ep in self.manager.conductor_endpoints
        ]
        self.status_endpoints = [
            ep(self.publisher_id) for ep in self.manager.status_endpoints
        ]
        self.notification_endpoints = self.manager.notification_endpoints

        self.serializer = rpc.RequestContextSerializer(
            base.WatcherObjectSerializer())

        self._transport = None
        self._notification_transport = None
        self._conductor_client = None
        self._status_client = None

        self.conductor_topic_handler = None
        self.status_topic_handler = None
        self.notification_handler = None

        self.heartbeat = None

        if self.conductor_topic and self.conductor_endpoints:
            self.conductor_topic_handler = self.build_topic_handler(
                self.conductor_topic, self.conductor_endpoints)
        if self.status_topic and self.status_endpoints:
            self.status_topic_handler = self.build_topic_handler(
                self.status_topic, self.status_endpoints)
        if self.notification_topics and self.notification_endpoints:
            self.notification_handler = self.build_notification_handler(
                self.notification_topics, self.notification_endpoints)
        self.service_name = self.manager.service_name
        if self.service_name:
            self.heartbeat = ServiceHeartbeat(
                service_name=self.manager.service_name)
示例#6
0
 def test_deserialize_entity_primitive(self):
     ser = base.WatcherObjectSerializer()
     for thing in (1, 'foo', [1, 2], {'foo': 'bar'}):
         self.assertEqual(thing, ser.deserialize_entity(None, thing))