diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index adee9be09796..7fc90988bb87 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -4050,6 +4050,32 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual(conf.cpu.cores, 1) self.assertEqual(conf.cpu.threads, 1) + @mock.patch.object(host.Host, "has_min_version", return_value=True) + def test_get_guest_cpu_config_numa_topology(self, mock_has_min_version): + drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + instance_ref = objects.Instance(**self.test_instance) + instance_ref.flavor.vcpus = 2 + instance_ref.numa_topology = objects.InstanceNUMATopology(cells=[ + objects.InstanceNUMACell( + id=0, + cpuset=set([0, 1]), + memory=1024, + cpu_pinning={})]) + image_meta = {} + disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type, + instance_ref, + image_meta) + + self.assertIsNone(instance_ref.numa_topology.cells[0].cpu_topology) + + drvr._get_guest_config( + instance_ref, _fake_network_info(self.stubs, 1), {}, disk_info) + + topo = instance_ref.numa_topology.cells[0].cpu_topology + self.assertIsNotNone(topo) + self.assertEqual(topo.cores * topo.sockets * topo.threads, + instance_ref.flavor.vcpus) + def test_get_guest_cpu_topology(self): instance_ref = objects.Instance(**self.test_instance) instance_ref.flavor.vcpus = 8 diff --git a/nova/virt/hardware.py b/nova/virt/hardware.py index 73e1df814149..53f42fc13cea 100644 --- a/nova/virt/hardware.py +++ b/nova/virt/hardware.py @@ -698,6 +698,7 @@ def _pack_instance_onto_cores(available_siblings, instance_cell, host_cell_id): pinning = zip(sorted(instance_cell.cpuset), itertools.chain(*sliced_sibs)) + # NOTE(sfinucan) - this may be overriden later on by the drivers topology = (instance_cell.cpu_topology or objects.VirtCPUTopology(sockets=1, cores=len(sliced_sibs), diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 8bdd6eeafccd..c1165a6d8f4e 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -3083,6 +3083,10 @@ class LibvirtDriver(driver.ComputeDriver): topology = hardware.get_best_cpu_topology( flavor, image_meta, numa_topology=instance_numa_topology) + if instance_numa_topology: + for cell in instance_numa_topology.cells: + cell.cpu_topology = topology + cpu.sockets = topology.sockets cpu.cores = topology.cores cpu.threads = topology.threads