summaryrefslogtreecommitdiff
path: root/nova/tests
diff options
context:
space:
mode:
authorKashyap Chamarthy <kchamart@redhat.com>2023-01-17 11:15:37 +0100
committerKashyap Chamarthy <kchamart@redhat.com>2023-01-24 11:26:56 +0100
commit9caaaf1f221063a4329c72c8b67a6015648644a2 (patch)
tree13196b8d2dc003732ac918c67d74b439a4f9cad2 /nova/tests
parentba9d4c909beff4e9ab86911a35dd5db8d8ce08d6 (diff)
downloadnova-9caaaf1f221063a4329c72c8b67a6015648644a2.tar.gz
libvirt: At start-up rework compareCPU() usage with a workaround
In this patch: - Remove the first compareCPU() call (called via the wrapper _compare_cpu()) in _check_cpu_compatibility(), and let libvirt handle it. (QEMU >=2.9 and libvirt >= 4.4.0 are the mininum required versions, and upstream Nova satisfies them by a good margin.) - Validate the user-configured CPU models from _get_cpu_model_mapping(). And take into account all the CPU flags before calling _compare_cpu(). (Suggested-by: Sean Mooney -- thanks!) - Add a workaround to allow skipping the remaining compareCPU() call in _check_cpu_compatibility() as a potential future-proof (because we cannot test all possible CPU models and hardware). Unlike the removed first call, this call takes into account the extra CPU flags provided by the user into account when evaluating guest CPU model compatibility. As a follow up comes the patch[1] that replaces the older libvirt CPU API with the newer one. [1] https://review.opendev.org/c/openstack/nova/+/869950 -- libvirt: Replace usage of compareCPU() with compareHypervisorCPU() Change-Id: I8ef9db851b37c5249d2efbe09a15a1ddbae8205d Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/unit/virt/libvirt/test_driver.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index 1c5f79dc89..9d45ba017c 100644
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -1333,6 +1333,22 @@ class LibvirtConnTestCase(test.NoDBTestCase,
@mock.patch.object(libvirt_driver.LibvirtDriver,
'_register_all_undefined_instance_details',
new=mock.Mock())
+ @mock.patch('nova.virt.libvirt.host.libvirt.Connection.compareCPU')
+ def test__check_cpu_compatibility_skip_compare_at_init(
+ self, mocked_compare
+ ):
+ self.flags(group='workarounds', skip_cpu_compare_at_startup=True)
+ self.flags(cpu_mode="custom",
+ cpu_models=["Icelake-Server-noTSX"],
+ cpu_model_extra_flags = ["-mpx"],
+ group="libvirt")
+ drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
+ drvr.init_host("dummyhost")
+ mocked_compare.assert_not_called()
+
+ @mock.patch.object(libvirt_driver.LibvirtDriver,
+ '_register_all_undefined_instance_details',
+ new=mock.Mock())
def test__check_cpu_compatibility_with_flag(self):
self.flags(cpu_mode="custom",
cpu_models=["Penryn"],
@@ -1343,7 +1359,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
@mock.patch('nova.virt.libvirt.host.libvirt.Connection.compareCPU')
def test__check_cpu_compatibility_advance_flag(self, mocked_compare):
- mocked_compare.side_effect = (2, 0)
+ mocked_compare.side_effect = (-1, 0)
self.flags(cpu_mode="custom",
cpu_models=["qemu64"],
cpu_model_extra_flags = ["avx", "avx2"],
@@ -1356,7 +1372,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
def test__check_cpu_compatibility_wrong_flag(self, mocked_compare):
# here, and in the surrounding similar tests, the non-zero error
# code in the compareCPU() side effect indicates error
- mocked_compare.side_effect = (2, 0)
+ mocked_compare.side_effect = (-1, 0)
self.flags(cpu_mode="custom",
cpu_models=["Broadwell-noTSX"],
cpu_model_extra_flags = ["a v x"],
@@ -1369,7 +1385,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
def test__check_cpu_compatibility_enabled_and_disabled_flags(
self, mocked_compare
):
- mocked_compare.side_effect = (2, 0)
+ mocked_compare.side_effect = (-1, 0)
self.flags(
cpu_mode="custom",
cpu_models=["Cascadelake-Server"],