コード例 #1
0
    def test_get_by_uuid(self):
        req = self._create_req()
        db_req = self.build_req_obj._get_by_instance_uuid_from_db(
            self.context, self.instance_uuid)

        obj_comp = functools.partial(
            objects.base.obj_equal_prims,
            ignore=['deleted', 'deleted_at', 'created_at', 'updated_at'])

        def date_comp(db_val, obj_val):
            # We have this separate comparison method because compare_obj below
            # assumes that db datetimes are tz unaware. That's normally true
            # but not when they're part of a serialized object and not a
            # dedicated datetime column.
            self.assertEqual(db_val.replace(tzinfo=None),
                             obj_val.replace(tzinfo=None))

        for key in self.build_req_obj.fields.keys():
            expected = getattr(req, key)
            db_value = db_req[key]
            if key in ['created_at', 'updated_at']:
                # Objects store tz aware datetimes but the db does not.
                expected = expected.replace(tzinfo=None)
            elif key == 'instance':
                db_instance = objects.Instance.obj_from_primitive(
                    jsonutils.loads(db_value))
                test_objects.compare_obj(
                    self,
                    expected,
                    db_instance,
                    # These objects are not loaded in the test instance
                    allow_missing=[
                        'pci_requests', 'numa_topology', 'pci_devices',
                        'security_groups', 'info_cache', 'ec2_ids',
                        'migration_context', 'metadata', 'vcpu_model',
                        'services', 'system_metadata', 'tags', 'fault',
                        'device_metadata'
                    ],
                    comparators={
                        'flavor': obj_comp,
                        'created_at': date_comp,
                        'keypairs': obj_comp
                    })
                continue
            elif key == 'block_device_mappings':
                db_bdms = objects.BlockDeviceMappingList.obj_from_primitive(
                    jsonutils.loads(db_value))
                self.assertEqual(1, len(db_bdms))
                # Can't compare list objects directly, just compare the single
                # item they contain.
                test_objects.compare_obj(self,
                                         expected[0],
                                         db_bdms[0],
                                         allow_missing=['instance'],
                                         comparators={
                                             'created_at': date_comp,
                                             'updated_at': date_comp
                                         })
                continue
            self.assertEqual(expected, db_value)
コード例 #2
0
    def test_get_by_uuid(self):
        req = self._create_req()
        db_req = self.build_req_obj._get_by_instance_uuid_from_db(
            self.context, self.instance_uuid)

        flavor_comp = functools.partial(test_objects.compare_obj,
                                        self,
                                        allow_missing=[
                                            'deleted', 'deleted_at',
                                            'created_at', 'updated_at'
                                        ])

        def date_comp(db_val, obj_val):
            # We have this separate comparison method because compare_obj below
            # assumes that db datetimes are tz unaware. That's normally true
            # but not when they're part of a serialized object and not a
            # dedicated datetime column.
            self.assertEqual(db_val.replace(tzinfo=None),
                             obj_val.replace(tzinfo=None))

        for key in self.build_req_obj.fields.keys():
            expected = getattr(req, key)
            db_value = db_req[key]
            if key == 'request_spec':
                # NOTE: The object and db value can't be compared directly as
                # objects, so serialize them to a comparable form.
                db_value = jsonutils.dumps(
                    objects.RequestSpec._from_db_object(
                        self.context, objects.RequestSpec(),
                        db_value).obj_to_primitive())
                expected = jsonutils.dumps(expected.obj_to_primitive())
            elif key in build_request.OBJECT_FIELDS:
                expected = jsonutils.dumps(expected.obj_to_primitive())
            elif key in build_request.JSON_FIELDS:
                expected = jsonutils.dumps(expected)
            elif key in build_request.IP_FIELDS:
                expected = str(expected)
            elif key in ['created_at', 'updated_at']:
                # Objects store tz aware datetimes but the db does not.
                expected = expected.replace(tzinfo=None)
            elif key == 'instance':
                db_instance = objects.Instance.obj_from_primitive(
                    jsonutils.loads(db_value))
                test_objects.compare_obj(
                    self,
                    expected,
                    db_instance,
                    # These objects are not loaded in the test instance
                    allow_missing=[
                        'pci_requests', 'numa_topology', 'pci_devices',
                        'security_groups', 'info_cache', 'ec2_ids',
                        'migration_context', 'metadata', 'vcpu_model',
                        'services', 'system_metadata', 'tags', 'fault'
                    ],
                    comparators={
                        'flavor': flavor_comp,
                        'created_at': date_comp
                    })
                continue
            self.assertEqual(expected, db_value)
コード例 #3
0
    def test_get_by_uuid(self):
        req = self._create_req()
        db_req = self.build_req_obj._get_by_instance_uuid_from_db(self.context,
                self.instance_uuid)

        flavor_comp = functools.partial(test_objects.compare_obj, self,
                allow_missing=['deleted', 'deleted_at', 'created_at',
                    'updated_at'])

        def date_comp(db_val, obj_val):
            # We have this separate comparison method because compare_obj below
            # assumes that db datetimes are tz unaware. That's normally true
            # but not when they're part of a serialized object and not a
            # dedicated datetime column.
            self.assertEqual(db_val.replace(tzinfo=None),
                             obj_val.replace(tzinfo=None))

        for key in self.build_req_obj.fields.keys():
            expected = getattr(req, key)
            db_value = db_req[key]
            if key == 'request_spec':
                # NOTE: The object and db value can't be compared directly as
                # objects, so serialize them to a comparable form.
                db_value = jsonutils.dumps(objects.RequestSpec._from_db_object(
                    self.context, objects.RequestSpec(),
                    db_value).obj_to_primitive())
                expected = jsonutils.dumps(expected.obj_to_primitive())
            elif key in build_request.OBJECT_FIELDS:
                expected = jsonutils.dumps(expected.obj_to_primitive())
            elif key in build_request.JSON_FIELDS:
                expected = jsonutils.dumps(expected)
            elif key in build_request.IP_FIELDS:
                expected = str(expected)
            elif key in ['created_at', 'updated_at']:
                # Objects store tz aware datetimes but the db does not.
                expected = expected.replace(tzinfo=None)
            elif key == 'instance':
                db_instance = objects.Instance.obj_from_primitive(
                        jsonutils.loads(db_value))
                test_objects.compare_obj(self, expected, db_instance,
                        # These objects are not loaded in the test instance
                        allow_missing=['pci_requests', 'numa_topology',
                            'pci_devices', 'security_groups', 'info_cache',
                            'ec2_ids', 'migration_context', 'metadata',
                            'vcpu_model', 'services', 'system_metadata',
                            'tags', 'fault'],
                        comparators={'flavor': flavor_comp,
                                     'created_at': date_comp})
                continue
            self.assertEqual(expected, db_value)
コード例 #4
0
ファイル: test_build_request.py プロジェクト: 4everming/nova
    def test_get_by_uuid(self):
        req = self._create_req()
        db_req = self.build_req_obj._get_by_instance_uuid_from_db(self.context,
                self.instance_uuid)

        obj_comp = functools.partial(objects.base.obj_equal_prims,
                ignore=['deleted', 'deleted_at', 'created_at',
                    'updated_at'])

        def date_comp(db_val, obj_val):
            # We have this separate comparison method because compare_obj below
            # assumes that db datetimes are tz unaware. That's normally true
            # but not when they're part of a serialized object and not a
            # dedicated datetime column.
            self.assertEqual(db_val.replace(tzinfo=None),
                             obj_val.replace(tzinfo=None))

        for key in self.build_req_obj.fields.keys():
            expected = getattr(req, key)
            db_value = db_req[key]
            if key in ['created_at', 'updated_at']:
                # Objects store tz aware datetimes but the db does not.
                expected = expected.replace(tzinfo=None)
            elif key == 'instance':
                db_instance = objects.Instance.obj_from_primitive(
                        jsonutils.loads(db_value))
                test_objects.compare_obj(self, expected, db_instance,
                        # These objects are not loaded in the test instance
                        allow_missing=['pci_requests', 'numa_topology',
                            'pci_devices', 'security_groups', 'info_cache',
                            'ec2_ids', 'migration_context', 'metadata',
                            'vcpu_model', 'services', 'system_metadata',
                            'tags', 'fault', 'device_metadata'],
                        comparators={'flavor': obj_comp,
                                     'created_at': date_comp,
                                     'keypairs': obj_comp})
                continue
            elif key == 'block_device_mappings':
                db_bdms = objects.BlockDeviceMappingList.obj_from_primitive(
                    jsonutils.loads(db_value))
                self.assertEqual(1, len(db_bdms))
                # Can't compare list objects directly, just compare the single
                # item they contain.
                test_objects.compare_obj(self, expected[0], db_bdms[0],
                                         allow_missing=['instance'],
                                         comparators={'created_at': date_comp,
                                                      'updated_at': date_comp})
                continue
            self.assertEqual(expected, db_value)
コード例 #5
0
ファイル: test_host_api.py プロジェクト: wenlongwljs/nova
 def _compare_obj(self, obj, db_obj):
     test_objects.compare_obj(self, obj, db_obj, allow_missing=test_service.OPTIONAL)
コード例 #6
0
 def _compare_obj(self, obj, db_obj):
     test_objects.compare_obj(self,
                              obj,
                              db_obj,
                              allow_missing=test_service.OPTIONAL)