def test_obj_make_compatible_numa_cell_pre_1_4(self): topo_obj = objects.InstanceNUMACell( cpuset_reserved=set([1, 2])) versions = ovo_base.obj_tree_get_versions('InstanceNUMACell') primitive = topo_obj.obj_to_primitive(target_version='1.3', version_manifest=versions) self.assertNotIn('cpuset_reserved', primitive)
def test_compat_pci_device_pools(self): compute = compute_node.ComputeNode() compute.pci_device_pools = fake_pci_device_pools.fake_pool_list versions = ovo_base.obj_tree_get_versions('ComputeNode') primitive = compute.obj_to_primitive(target_version='1.8', version_manifest=versions) self.assertNotIn('pci_device_pools', primitive)
def test_compat_security_groups(self): sgl = objects.SecurityGroupList(objects=[]) req_obj = objects.RequestSpec(security_groups=sgl) versions = ovo_base.obj_tree_get_versions('RequestSpec') primitive = req_obj.obj_to_primitive(target_version='1.7', version_manifest=versions) self.assertNotIn('security_groups', primitive)
def test_vif_migrate_data(self): source_vif = network_model.VIF( id=uuids.port_id, network=network_model.Network(id=uuids.network_id), type=network_model.VIF_TYPE_OVS, vnic_type=network_model.VNIC_TYPE_NORMAL, active=True, profile={'migrating_to': 'dest-host'}) vif_details_dict = {'port_filter': True} profile_dict = {'trusted': False} vif_data = objects.VIFMigrateData( port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL, vif_type=network_model.VIF_TYPE_BRIDGE, vif_details=vif_details_dict, profile=profile_dict, host='dest-host', source_vif=source_vif) # Make sure the vif_details and profile fields are converted and # stored properly. self.assertEqual( jsonutils.dumps(vif_details_dict), vif_data.vif_details_json) self.assertEqual( jsonutils.dumps(profile_dict), vif_data.profile_json) self.assertDictEqual(vif_details_dict, vif_data.vif_details) self.assertDictEqual(profile_dict, vif_data.profile) obj = migrate_data.LibvirtLiveMigrateData( file_backed_memory_discard=False) obj.vifs = [vif_data] manifest = ovo_base.obj_tree_get_versions(obj.obj_name()) primitive = obj.obj_to_primitive(target_version='1.8', version_manifest=manifest) self.assertIn( 'file_backed_memory_discard', primitive['nova_object.data']) self.assertNotIn('vifs', primitive['nova_object.data'])
def test_compat_supported_hv_specs(self): compute = compute_node.ComputeNode() compute.supported_hv_specs = fake_supported_hv_specs versions = ovo_base.obj_tree_get_versions('ComputeNode') primitive = compute.obj_to_primitive(target_version='1.5', version_manifest=versions) self.assertNotIn('supported_hv_specs', primitive)
def object_class_action(self, context, objname, objmethod, objver, args, kwargs): # NOTE(xek): This method is implemented for compatibility with # oslo.versionedobjects 0.10.0 and older. It will be replaced by # object_class_action_versions. versions = object_base.obj_tree_get_versions(objname) return self.object_class_action_versions( context, objname, objmethod, versions, args, kwargs)
def object_class_action(self, context, objname, objmethod, objver, args, kwargs): versions = ovo_base.obj_tree_get_versions(objname) return self.object_class_action_versions(context, objname, objmethod, versions, args, kwargs)
def test_compat_requested_resources(self): req_obj = objects.RequestSpec(requested_resources=[], instance_uuid=uuids.instance) versions = ovo_base.obj_tree_get_versions('RequestSpec') primitive = req_obj.obj_to_primitive(target_version='1.11', version_manifest=versions) primitive = primitive['nova_object.data'] self.assertNotIn('requested_resources', primitive) self.assertIn('instance_uuid', primitive)
def test_compat_user_id(self): req_obj = objects.RequestSpec(project_id=fakes.FAKE_PROJECT_ID, user_id=fakes.FAKE_USER_ID) versions = ovo_base.obj_tree_get_versions('RequestSpec') primitive = req_obj.obj_to_primitive(target_version='1.8', version_manifest=versions) primitive = primitive['nova_object.data'] self.assertNotIn('user_id', primitive) self.assertIn('project_id', primitive)
def test_compat_numa_topology(self): compute = compute_node.ComputeNode(numa_topology='fake-numa-topology') versions = ovo_base.obj_tree_get_versions('ComputeNode') primitive = compute.obj_to_primitive(target_version='1.4', version_manifest=versions) self.assertNotIn('numa_topology', primitive['nova_object.data']) primitive = compute.obj_to_primitive(target_version='1.5', version_manifest=versions) self.assertIn('numa_topology', primitive['nova_object.data'])
def test_obj_make_compatible_pre_1_1(self): topo_obj = objects.InstancePCIRequest( count=1, spec=[{'vendor_id': '8086', 'device_id': '1502'}], request_id=uuids.pci_request_id) versions = ovo_base.obj_tree_get_versions('InstancePCIRequest') primitive = topo_obj.obj_to_primitive(target_version='1.0', version_manifest=versions) self.assertNotIn('request_id', primitive['nova_object.data'])
def test_backport_fixedip_1_1(self): floating = objects.FloatingIP() fixed = objects.FixedIP() floating.fixed_ip = fixed versions = ovo_base.obj_tree_get_versions('FloatingIP') versions['FixedIP'] = '1.1' primitive = floating.obj_to_primitive(target_version='1.1', version_manifest=versions) self.assertEqual('1.1', primitive['nova_object.data']['fixed_ip']['nova_object.version'])
def test_backport_fixedip_1_1(self): floating = objects.FloatingIP() fixed = objects.FixedIP() floating.fixed_ip = fixed versions = ovo_base.obj_tree_get_versions('FloatingIP') versions['FixedIP'] = '1.1' primitive = floating.obj_to_primitive(target_version='1.1', version_manifest=versions) self.assertEqual( '1.1', primitive['nova_object.data']['fixed_ip']['nova_object.version'])
def test_obj_make_compatible_numa(self): topo_obj = objects.InstanceNUMATopology( emulator_threads_policy=(fields.CPUEmulatorThreadsPolicy.ISOLATE)) versions = ovo_base.obj_tree_get_versions('InstanceNUMATopology') primitive = topo_obj.obj_to_primitive(target_version='1.2', version_manifest=versions) self.assertNotIn('emulator_threads_policy', primitive['nova_object.data']) topo_obj = objects.InstanceNUMATopology.obj_from_primitive(primitive) self.assertFalse(topo_obj.emulator_threads_isolated)
def test_compat_pci_device_pools(self): compute = compute_node.ComputeNode() compute.pci_device_pools = fake_pci_device_pools.fake_pool_list versions = ovo_base.obj_tree_get_versions('ComputeNode') primitive = compute.obj_to_primitive(target_version='1.8', version_manifest=versions) self.assertNotIn('pci_device_pools', primitive['nova_object.data']) primitive = compute.obj_to_primitive(target_version='1.9', version_manifest=versions) self.assertIn('pci_device_pools', primitive['nova_object.data'])
def test_compat_network_metadata(self): network_metadata = objects.NetworkMetadata(physnets=set(), tunneled=False) req_obj = objects.RequestSpec(network_metadata=network_metadata, user_id=fakes.FAKE_USER_ID) versions = ovo_base.obj_tree_get_versions('RequestSpec') primitive = req_obj.obj_to_primitive(target_version='1.9', version_manifest=versions) primitive = primitive['nova_object.data'] self.assertNotIn('network_metadata', primitive) self.assertIn('user_id', primitive)
def test_obj_make_compatible_numa_cell_pre_1_4(self): topo_obj = objects.InstanceNUMACell( cpuset_reserved=set([1, 2])) versions = ovo_base.obj_tree_get_versions('InstanceNUMACell') data = lambda x: x['nova_object.data'] primitive = data(topo_obj.obj_to_primitive(target_version='1.4', version_manifest=versions)) self.assertIn('cpuset_reserved', primitive) primitive = data(topo_obj.obj_to_primitive(target_version='1.3', version_manifest=versions)) self.assertNotIn('cpuset_reserved', primitive)
def test_compat_supported_hv_specs(self): compute = compute_node.ComputeNode() compute.supported_hv_specs = fake_supported_hv_specs versions = ovo_base.obj_tree_get_versions('ComputeNode') primitive = compute.obj_to_primitive(target_version='1.5', version_manifest=versions) self.assertNotIn('supported_hv_specs', primitive['nova_object.data']) primitive = compute.obj_to_primitive(target_version='1.6', version_manifest=versions) self.assertIn('supported_hv_specs', primitive['nova_object.data'])
def test_compat_requester_and_provider(self): req_obj = objects.RequestGroup( requester_id=uuids.requester, provider_uuids=[uuids.rp1], required_traits=set(['CUSTOM_PHYSNET_2'])) versions = ovo_base.obj_tree_get_versions('RequestGroup') primitive = req_obj.obj_to_primitive( target_version='1.0', version_manifest=versions)['nova_object.data'] self.assertNotIn('requester_id', primitive) self.assertNotIn('provider_uuids', primitive) self.assertIn('required_traits', primitive)
def test_compat_requested_destination(self): req_obj = objects.RequestSpec( requested_destination=objects.Destination()) versions = ovo_base.obj_tree_get_versions('RequestSpec') primitive = req_obj.obj_to_primitive(target_version='1.5', version_manifest=versions) self.assertNotIn( 'requested_destination', primitive['nova_object.data']) primitive = req_obj.obj_to_primitive(target_version='1.6', version_manifest=versions) self.assertIn('requested_destination', primitive['nova_object.data'])
def test_obj_make_compatible_pre_1_2(self): topo_obj = objects.InstancePCIRequest( count=1, spec=[{'vendor_id': '8086', 'device_id': '1502'}], request_id=uuids.pci_request_id, numa_policy=fields.PCINUMAAffinityPolicy.PREFERRED) versions = ovo_base.obj_tree_get_versions('InstancePCIRequest') primitive = topo_obj.obj_to_primitive(target_version='1.1', version_manifest=versions) self.assertNotIn('numa_policy', primitive['nova_object.data']) self.assertIn('request_id', primitive['nova_object.data'])
def test_obj_make_compatible_numa_pre_1_3(self): topo_obj = objects.InstanceNUMATopology( emulator_threads_policy=( fields.CPUEmulatorThreadsPolicy.ISOLATE)) versions = ovo_base.obj_tree_get_versions('InstanceNUMATopology') primitive = topo_obj.obj_to_primitive(target_version='1.2', version_manifest=versions) self.assertNotIn( 'emulator_threads_policy', primitive['nova_object.data']) topo_obj = objects.InstanceNUMATopology.obj_from_primitive(primitive) self.assertFalse(topo_obj.emulator_threads_isolated)
def test_obj_make_compatible_pre_1_1(self): topo_obj = objects.InstancePCIRequest(count=1, spec=[{ 'vendor_id': '8086', 'device_id': '1502' }], request_id=uuids.pci_request_id) versions = ovo_base.obj_tree_get_versions('InstancePCIRequest') primitive = topo_obj.obj_to_primitive(target_version='1.0', version_manifest=versions) self.assertNotIn('request_id', primitive['nova_object.data'])
def test_compatibility_routines(self, use_manifest=False): # Iterate all object classes and verify that we can run # obj_make_compatible with every older version than current. # This doesn't actually test the data conversions, but it at least # makes sure the method doesn't blow up on something basic like # expecting the wrong version format. for obj_name in self.obj_classes: obj_classes = self.obj_classes[obj_name] if use_manifest: manifest = base.obj_tree_get_versions(obj_name) else: manifest = None for obj_class in obj_classes: self._test_object_compatibility(obj_class, manifest=manifest)
def test_obj_make_compatible(self): network_meta = objects.NetworkMetadata(physnets=set(['foo', 'bar']), tunneled=True) limits = objects.NUMATopologyLimits(cpu_allocation_ratio=1.0, ram_allocation_ratio=1.0, network_metadata=network_meta) versions = ovo_base.obj_tree_get_versions('NUMATopologyLimits') primitive = limits.obj_to_primitive(target_version='1.1', version_manifest=versions) self.assertIn('network_metadata', primitive['nova_object.data']) primitive = limits.obj_to_primitive(target_version='1.0', version_manifest=versions) self.assertNotIn('network_metadata', primitive['nova_object.data'])
def test_obj_make_compatible_for_compute_node(self, get_all_by_host): service_obj = objects.Service(context=self.context) fake_service_dict = fake_service.copy() fake_compute_obj = objects.ComputeNode(host=fake_service['host'], service_id=fake_service['id']) get_all_by_host.return_value = [fake_compute_obj] versions = ovo_base.obj_tree_get_versions('Service') versions['ComputeNode'] = '1.10' service_obj.obj_make_compatible_from_manifest(fake_service_dict, '1.9', versions) self.assertEqual( fake_compute_obj.obj_to_primitive(target_version='1.10', version_manifest=versions), fake_service_dict['compute_node'])
def test_obj_make_compatible(self): network_metadata = objects.NetworkMetadata( physnets=set(['foo', 'bar']), tunneled=True) cell = objects.NUMACell(id=1, cpuset=set([1, 2]), memory=32, cpu_usage=10, pinned_cpus=set([3, 4]), siblings=[set([5, 6])], network_metadata=network_metadata) versions = ovo_base.obj_tree_get_versions('NUMACell') primitive = cell.obj_to_primitive(target_version='1.3', version_manifest=versions) self.assertIn('network_metadata', primitive['nova_object.data']) primitive = cell.obj_to_primitive(target_version='1.2', version_manifest=versions) self.assertNotIn('network_metadata', primitive['nova_object.data'])
def test_numa_topology_limits_obj_make_compatible(self): network_meta = objects.NetworkMetadata( physnets=set(['foo', 'bar']), tunneled=True) limits = objects.NUMATopologyLimits( cpu_allocation_ratio=1.0, ram_allocation_ratio=1.0, network_metadata=network_meta) versions = ovo_base.obj_tree_get_versions('NUMATopologyLimits') primitive = limits.obj_to_primitive(target_version='1.1', version_manifest=versions) self.assertIn('network_metadata', primitive['nova_object.data']) primitive = limits.obj_to_primitive(target_version='1.0', version_manifest=versions) self.assertNotIn('network_metadata', primitive['nova_object.data'])
def object_class_action(self, context, objname, objmethod, objver, args, kwargs): if self.client.can_send_version('2.3'): # NOTE(danms): If we're new enough, collect the object # version manifest and redirect the call to the newer # class action handler versions = ovo_base.obj_tree_get_versions(objname) return self.object_class_action_versions(context, objname, objmethod, versions, args, kwargs) cctxt = self.client.prepare() return cctxt.call(context, 'object_class_action', objname=objname, objmethod=objmethod, objver=objver, args=args, kwargs=kwargs)
def _process_object(self, context, objprim): try: objinst = NovaObject.obj_from_primitive(objprim, context=context) except ovoo_exc.IncompatibleObjectVersion: objver = objprim["nova_object.version"] if objver.count(".") == 2: # NOTE(danms): For our purposes, the .z part of the version # should be safe to accept without requiring a backport objprim["nova_object.version"] = ".".join(objver.split(".")[:2]) return self._process_object(context, objprim) objname = objprim["nova_object.name"] version_manifest = ovoo_base.obj_tree_get_versions(objname) if objname in version_manifest: objinst = self.conductor.object_backport_versions(context, objprim, version_manifest) else: raise return objinst
def test_numa_migrate_data(self): data = lambda x: x['nova_object.data'] obj = migrate_data.LibvirtLiveMigrateNUMAInfo( cpu_pins={'0': set([1])}, cell_pins={'2': set([3])}, emulator_pins=set([4]), sched_vcpus=set([5]), sched_priority=6) manifest = ovo_base.obj_tree_get_versions(obj.obj_name()) primitive = data( obj.obj_to_primitive(target_version='1.0', version_manifest=manifest)) self.assertEqual({'0': (1, )}, primitive['cpu_pins']) self.assertEqual({'2': (3, )}, primitive['cell_pins']) self.assertEqual((4, ), primitive['emulator_pins']) self.assertEqual((5, ), primitive['sched_vcpus']) self.assertEqual(6, primitive['sched_priority'])
def _test_deserialize_entity_newer(self, obj_version, backported_to, mock_indirection_api, my_version="1.6"): ser = base.IronicObjectSerializer() mock_indirection_api.object_backport_versions.return_value = "backported" @base.IronicObjectRegistry.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)
def _process_object(self, context, objprim): try: objinst = NovaObject.obj_from_primitive(objprim, context=context) except ovoo_exc.IncompatibleObjectVersion: objver = objprim['nova_object.version'] if objver.count('.') == 2: # NOTE(danms): For our purposes, the .z part of the version # should be safe to accept without requiring a backport objprim['nova_object.version'] = \ '.'.join(objver.split('.')[:2]) return self._process_object(context, objprim) objname = objprim['nova_object.name'] version_manifest = ovoo_base.obj_tree_get_versions(objname) if objname in version_manifest: objinst = self.conductor.object_backport_versions( context, objprim, version_manifest) else: raise return objinst
def test_compatibility_routines(self, use_manifest=False, init_args=None, init_kwargs=None): """Test obj_make_compatible() on all object classes. :param use_manifest: a boolean that determines if the version manifest should be passed to obj_make_compatible :param init_args: a dictionary of the format {obj_class: [arg1, arg2]} that will be used to pass arguments to init on the given obj_class. If no args are needed, the obj_class does not need to be added to the dict :param init_kwargs: a dictionary of the format {obj_class: {'kwarg1': val1}} that will be used to pass kwargs to init on the given obj_class. If no kwargs are needed, the obj_class does not need to be added to the dict """ # Iterate all object classes and verify that we can run # obj_make_compatible with every older version than current. # This doesn't actually test the data conversions, but it at least # makes sure the method doesn't blow up on something basic like # expecting the wrong version format. init_args = init_args or {} init_kwargs = init_kwargs or {} for obj_name in self.obj_classes: obj_classes = self.obj_classes[obj_name] if use_manifest: manifest = base.obj_tree_get_versions(obj_name) else: manifest = None for obj_class in obj_classes: args_for_init = init_args.get(obj_class, []) kwargs_for_init = init_kwargs.get(obj_class, {}) self._test_object_compatibility(obj_class, manifest=manifest, init_args=args_for_init, init_kwargs=kwargs_for_init)
def test_obj_make_compatible(self): topo_obj = objects.InstanceNUMACell( cpuset=set(), pcpuset=set([0, 1]), cpuset_reserved=set([1, 2]), cpu_policy=fields.CPUAllocationPolicy.MIXED, ) versions = ovo_base.obj_tree_get_versions('InstanceNUMACell') data = lambda x: x['nova_object.data'] primitive = data( topo_obj.obj_to_primitive(target_version='1.6', version_manifest=versions)) self.assertEqual(fields.CPUAllocationPolicy.MIXED, primitive['cpu_policy']) self.assertRaises(exception.ObjectActionError, topo_obj.obj_to_primitive, target_version='1.5', version_manifest=versions) # set this to something compatible with < 1.6 so we can keep testing topo_obj.cpu_policy = fields.CPUAllocationPolicy.DEDICATED primitive = data( topo_obj.obj_to_primitive(target_version='1.5', version_manifest=versions)) self.assertIn('pcpuset', primitive) primitive = data( topo_obj.obj_to_primitive(target_version='1.4', version_manifest=versions)) self.assertNotIn('pcpuset', primitive) self.assertEqual(set([0, 1]), set(primitive['cpuset'])) self.assertIn('cpuset_reserved', primitive) primitive = data( topo_obj.obj_to_primitive(target_version='1.3', version_manifest=versions)) self.assertNotIn('cpuset_reserved', primitive)
def _test_deserialize_entity_newer(self, obj_version, backported_to, mock_indirection_api, my_version='1.6'): ser = base.IronicObjectSerializer() mock_indirection_api.object_backport_versions.return_value \ = 'backported' @base.IronicObjectRegistry.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)
def test_backport_default_route(self, mock_get): info = { "address": "1.2.3.4", "instance_uuid": "fake-uuid", "network_id": 0, "vif_id": 1, "vif_address": "de:ad:be:ee:f0:00", "instance_hostname": "fake-host", "instance_updated": datetime.datetime(1955, 11, 5), "instance_created": datetime.datetime(1955, 11, 5), "allocated": True, "leased": True, "default_route": True, } mock_get.return_value = [info] fixed_ips = fixed_ip.FixedIPList.get_by_network(self.context, {"id": 0}, host="fake-host") primitive = fixed_ips[0].obj_to_primitive() self.assertIn("default_route", primitive["nova_object.data"]) versions = ovo_base.obj_tree_get_versions("FixedIP") fixed_ips[0].obj_make_compatible_from_manifest( primitive["nova_object.data"], target_version="1.1", version_manifest=versions ) self.assertNotIn("default_route", primitive["nova_object.data"])
def test_backport_default_route(self, mock_get): info = {'address': '1.2.3.4', 'instance_uuid': uuids.instance, 'network_id': 0, 'vif_id': 1, 'vif_address': 'de:ad:be:ee:f0:00', 'instance_hostname': 'fake-host', 'instance_updated': datetime.datetime(1955, 11, 5), 'instance_created': datetime.datetime(1955, 11, 5), 'allocated': True, 'leased': True, 'default_route': True, } mock_get.return_value = [info] fixed_ips = fixed_ip.FixedIPList.get_by_network( self.context, {'id': 0}, host='fake-host') primitive = fixed_ips[0].obj_to_primitive() self.assertIn('default_route', primitive['nova_object.data']) versions = ovo_base.obj_tree_get_versions('FixedIP') fixed_ips[0].obj_make_compatible_from_manifest( primitive['nova_object.data'], target_version='1.1', version_manifest=versions) self.assertNotIn('default_route', primitive['nova_object.data'])
def test_compat_numa_topology(self): compute = compute_node.ComputeNode() versions = ovo_base.obj_tree_get_versions("ComputeNode") primitive = compute.obj_to_primitive(target_version="1.4", version_manifest=versions) self.assertNotIn("numa_topology", primitive)
def object_backport(self, context, objinst, target_version): # NOTE(hanlind): This shouldn't be called anymore but leaving it for # now just in case. Collect the object version manifest and redirect # to the newer backport call. object_versions = ovo_base.obj_tree_get_versions(objinst.obj_name()) return self.object_backport_versions(context, objinst, object_versions)
def test_compat_requested_destination(self): req_obj = objects.RequestSpec() versions = ovo_base.obj_tree_get_versions('RequestSpec') primitive = req_obj.obj_to_primitive(target_version='1.5', version_manifest=versions) self.assertNotIn('requested_destination', primitive)
def test_compat_numa_topology(self): compute = compute_node.ComputeNode() versions = ovo_base.obj_tree_get_versions('ComputeNode') primitive = compute.obj_to_primitive(target_version='1.4', version_manifest=versions) self.assertNotIn('numa_topology', primitive)