def test_numa_topology_with_pci_fail(self, mock_get): dev_dict = { 'compute_node_id': 1, 'address': 'a', 'product_id': 'p', 'vendor_id': 'v', 'numa_node': 1, 'status': 'available' } dev_dict2 = { 'compute_node_id': 1, 'address': 'a', 'product_id': 'p', 'vendor_id': 'v', 'numa_node': 2, 'status': 'available' } self.tracker.new_pci_tracker() self.tracker.pci_tracker.set_hvdevs([dev_dict, dev_dict2]) request = objects.InstancePCIRequest(count=2, spec=[{ 'vendor_id': 'v', 'product_id': 'p' }]) mock_get.return_value = objects.InstancePCIRequests(requests=[request]) huge_instance = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512) ]) self.assertRaises(exception.ComputeResourcesUnavailable, self._claim, numa_topology=huge_instance)
def test_update_pci_for_instance_with_numa_fail(self, mock_get): self._create_pci_requests_object(mock_get, fake_pci_requests) self.inst.numa_topology = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512) ]) self.assertRaises(exception.PciDeviceRequestFailed, self.tracker.update_pci_for_instance, None, self.inst)
def test_numa_topology_passes(self, mock_get): huge_instance = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512) ]) limit_topo = objects.NUMATopologyLimits(cpu_allocation_ratio=1, ram_allocation_ratio=1) self._claim(limits={'numa_topology': limit_topo}, numa_topology=huge_instance)
def test_numa_topology_fails(self, mock_get): huge_instance = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell( id=1, cpuset=set([1, 2, 3, 4, 5]), memory=2048) ]) limit_topo = objects.NUMATopologyLimits(cpu_allocation_ratio=1, ram_allocation_ratio=1) self.assertRaises(exception.ComputeResourcesUnavailable, self._claim, limits={'numa_topology': limit_topo}, numa_topology=huge_instance)
def test_numa_topology_filter_numa_instance_no_numa_host_fail(self): instance_topology = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512), objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512) ]) instance = fake_instance.fake_instance_obj(mock.sentinel.ctx) instance.numa_topology = instance_topology filter_properties = { 'request_spec': { 'instance_properties': jsonutils.to_primitive(obj_base.obj_to_primitive(instance)) } } host = fakes.FakeHostState('host1', 'node1', {'pci_stats': None}) self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def test_update_pci_for_instance_with_numa(self, mock_get): fake_db_dev_3 = dict(fake_db_dev_1, id=4, address='0000:00:00.4') fake_devs_numa = copy.deepcopy(fake_db_devs) fake_devs_numa.append(fake_db_dev_3) self.tracker = manager.PciDevTracker(1) self.tracker.set_hvdevs(fake_devs_numa) pci_requests = copy.deepcopy(fake_pci_requests)[:1] pci_requests[0]['count'] = 2 self._create_pci_requests_object(mock_get, pci_requests) self.inst.numa_topology = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512) ]) self.tracker.update_pci_for_instance(None, self.inst) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(2, len(free_devs)) self.assertEqual('v1', free_devs[0]['vendor_id']) self.assertEqual('v1', free_devs[1]['vendor_id'])
def test_stat_consumption_from_instance_pci(self): inst_topology = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(cpuset=set([0]), memory=512, id=0) ]) fake_requests = [{ 'request_id': 'fake_request1', 'count': 1, 'spec': [{ 'vendor_id': '8086' }] }] fake_requests_obj = objects.InstancePCIRequests( requests=[objects.InstancePCIRequest(**r) for r in fake_requests], instance_uuid='fake-uuid') instance = objects.Instance(root_gb=0, ephemeral_gb=0, memory_mb=512, vcpus=1, project_id='12345', vm_state=vm_states.BUILDING, task_state=task_states.SCHEDULING, os_type='Linux', uuid='fake-uuid', numa_topology=inst_topology, pci_requests=fake_requests_obj, id=1243) req_spec = sched_utils.build_request_spec( None, None, [instance], objects.Flavor(root_gb=0, ephemeral_gb=0, memory_mb=1024, vcpus=1)) host = host_manager.HostState("fakehost", "fakenode") host.pci_stats = pci_stats.PciDeviceStats([ objects.PciDevicePool(vendor_id='8086', product_id='15ed', numa_node=1, count=1) ]) host.numa_topology = fakes.NUMA_TOPOLOGY host.consume_from_instance(req_spec['instance_properties']) self.assertIsInstance(req_spec['instance_properties']['numa_topology'], objects.InstanceNUMATopology) self.assertEqual(512, host.numa_topology.cells[1].memory_usage) self.assertEqual(1, host.numa_topology.cells[1].cpu_usage) self.assertEqual(0, len(host.pci_stats.pools))
def test_numa_topology_filter_pass_set_limit(self): self.flags(cpu_allocation_ratio=21) self.flags(ram_allocation_ratio=1.3) instance_topology = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512), objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512) ]) instance = fake_instance.fake_instance_obj(mock.sentinel.ctx) instance.numa_topology = instance_topology filter_properties = { 'request_spec': { 'instance_properties': jsonutils.to_primitive(obj_base.obj_to_primitive(instance)) } } host = fakes.FakeHostState('host1', 'node1', { 'numa_topology': fakes.NUMA_TOPOLOGY, 'pci_stats': None }) self.assertTrue(self.filt_cls.host_passes(host, filter_properties)) limits = host.limits['numa_topology'] self.assertEqual(limits.cpu_allocation_ratio, 21) self.assertEqual(limits.ram_allocation_ratio, 1.3)
def test_numa_topology_with_pci_no_numa_info(self, mock_get): dev_dict = { 'compute_node_id': 1, 'address': 'a', 'product_id': 'p', 'vendor_id': 'v', 'numa_node': None, 'status': 'available' } self.tracker.new_pci_tracker() self.tracker.pci_tracker.set_hvdevs([dev_dict]) request = objects.InstancePCIRequest(count=1, spec=[{ 'vendor_id': 'v', 'product_id': 'p' }]) mock_get.return_value = objects.InstancePCIRequests(requests=[request]) huge_instance = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512) ]) self._claim(numa_topology=huge_instance)
def test_numa_topology_no_limit(self, mock_get): huge_instance = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512) ]) self._claim(numa_topology=huge_instance)
import mock from oslo_serialization import jsonutils from patron import exception from patron import objects from patron.tests.unit.objects import test_objects fake_instance_uuid = str(uuid.uuid4()) fake_obj_numa_topology = objects.InstanceNUMATopology( instance_uuid=fake_instance_uuid, cells=[ objects.InstanceNUMACell(id=0, cpuset=set([1, 2]), memory=512, pagesize=2048), objects.InstanceNUMACell(id=1, cpuset=set([3, 4]), memory=512, pagesize=2048) ]) fake_numa_topology = fake_obj_numa_topology._to_dict() fake_db_topology = { 'created_at': None, 'updated_at': None, 'deleted_at': None, 'deleted': 0, 'id': 1, 'instance_uuid': fake_instance_uuid,