Merge "libvirt: At start-up rework compareCPU() usage with a workaround" into stable/zed

This commit is contained in:
Zuul
2023-09-01 10:23:55 +00:00
committed by Gerrit Code Review
3 changed files with 46 additions and 30 deletions

View File

@@ -410,6 +410,13 @@ with the destination host. When using QEMU >= 2.9 and libvirt >=
4.4.0, libvirt will do the correct thing with respect to checking CPU
compatibility on the destination host during live migration.
"""),
cfg.BoolOpt('skip_cpu_compare_at_startup',
default=False,
help="""
This will skip the CPU comparison call at the startup of Compute
service and lets libvirt handle it.
"""),
cfg.BoolOpt(
'skip_hypervisor_version_check_on_lm',
default=False,

View File

@@ -1331,6 +1331,22 @@ class LibvirtConnTestCase(test.NoDBTestCase,
self.assertRaises(exception.InvalidCPUInfo,
drvr.init_host, "dummyhost")
@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())
@@ -1344,7 +1360,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"],
@@ -1357,7 +1373,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"],
@@ -1370,7 +1386,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"],

View File

@@ -984,33 +984,26 @@ class LibvirtDriver(driver.ComputeDriver):
msg = _("The cpu_models option is required when cpu_mode=custom")
raise exception.Invalid(msg)
cpu = vconfig.LibvirtConfigGuestCPU()
for model in models:
cpu.model = self._get_cpu_model_mapping(model)
try:
self._compare_cpu(cpu, self._get_cpu_info(), None)
except exception.InvalidCPUInfo as e:
msg = (_("Configured CPU model: %(model)s is not "
"compatible with host CPU. Please correct your "
"config and try again. %(e)s") % {
'model': model, 'e': e})
raise exception.InvalidCPUInfo(msg)
# Use guest CPU model to check the compatibility between guest CPU and
# configured extra_flags
cpu = vconfig.LibvirtConfigGuestCPU()
cpu.model = self._host.get_capabilities().host.cpu.model
for flag in set(x.lower() for x in CONF.libvirt.cpu_model_extra_flags):
cpu_feature = self._prepare_cpu_flag(flag)
cpu.add_feature(cpu_feature)
try:
self._compare_cpu(cpu, self._get_cpu_info(), None)
except exception.InvalidCPUInfo as e:
msg = (_("Configured extra flag: %(flag)s it not correct, or "
"the host CPU does not support this flag. Please "
"correct the config and try again. %(e)s") % {
'flag': flag, 'e': e})
raise exception.InvalidCPUInfo(msg)
if not CONF.workarounds.skip_cpu_compare_at_startup:
# Use guest CPU model to check the compatibility between
# guest CPU and configured extra_flags
for model in models:
cpu = vconfig.LibvirtConfigGuestCPU()
cpu.model = self._get_cpu_model_mapping(model)
for flag in set(x.lower() for
x in CONF.libvirt.cpu_model_extra_flags):
cpu_feature = self._prepare_cpu_flag(flag)
cpu.add_feature(cpu_feature)
try:
self._compare_cpu(cpu, self._get_cpu_info(), None)
except exception.InvalidCPUInfo as e:
msg = (_("Configured CPU model: %(model)s "
"and CPU Flags %(flags)s ar not "
"compatible with host CPU. Please correct your "
"config and try again. %(e)s") % {
'model': model, 'e': e,
'flags': CONF.libvirt.cpu_model_extra_flags})
raise exception.InvalidCPUInfo(msg)
def _check_vtpm_support(self) -> None:
# TODO(efried): A key manager must be configured to create/retrieve