libvirt: Make `cpu_model_extra_flags` case-insensitive for real

When we introduced `cpu_model_extra_flags` config attribute (in
commit: 6b601b7 -- "libvirt: Allow to specify granular CPU feature
flags"), we said it was case-insensitive; but unfortunately I missed to
_really_ make it so (despite proposing code for it in one of the
revisions).

Address that mistake by making `cpu_model_extra_flags` case-insensitive
for real, from Nova's point of view.

NB: Internally, this patch is normalizing 'extra_flags' to _lower_
casing -- because CPU flags _must_ be lower case from libvirt's point of
view.  Nova must honour that; otherwise, launching instances with an
upper case CPU flag, 'FOO', will fail with: "libvirtError: internal
error: Unknown CPU feature FOO".

Related-Bug: #1750829
Change-Id: Ia7ff0566a5109c76c009f3a0c6199c4ba419cfb1
Reported-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
This commit is contained in:
Kashyap Chamarthy 2018-04-28 18:55:25 +02:00 committed by Matt Riedemann
parent 19dd4eb883
commit 8e438eda9b
2 changed files with 31 additions and 1 deletions

View File

@ -6342,6 +6342,35 @@ class LibvirtConnTestCase(test.NoDBTestCase,
self.assertEqual(conf.cpu.threads, 1)
self.assertFalse(mock_warn.called)
@mock.patch.object(libvirt_driver.LOG, 'warning')
def test_get_guest_cpu_config_custom_with_extra_flags_upper_case(self,
mock_warn):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
instance_ref = objects.Instance(**self.test_instance)
image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
self.flags(cpu_mode="custom",
cpu_model="IvyBridge",
cpu_model_extra_flags="PCID",
group='libvirt')
disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type,
instance_ref,
image_meta)
conf = drvr._get_guest_config(instance_ref,
_fake_network_info(self, 1),
image_meta, disk_info)
self.assertIsInstance(conf.cpu,
vconfig.LibvirtConfigGuestCPU)
self.assertEqual("custom", conf.cpu.mode)
self.assertEqual("IvyBridge", conf.cpu.model)
# At this point the upper case CPU flag is normalized to lower
# case, so assert for that
self.assertEqual("pcid", conf.cpu.features.pop().name)
self.assertEqual(instance_ref.flavor.vcpus, conf.cpu.sockets)
self.assertEqual(1, conf.cpu.cores)
self.assertEqual(1, conf.cpu.threads)
mock_warn.assert_not_called()
@mock.patch.object(libvirt_driver.LOG, 'warning')
def test_get_guest_cpu_config_host_model_with_extra_flags(self,
mock_warn):

View File

@ -3771,7 +3771,8 @@ class LibvirtDriver(driver.ComputeDriver):
def _get_guest_cpu_model_config(self):
mode = CONF.libvirt.cpu_mode
model = CONF.libvirt.cpu_model
extra_flags = CONF.libvirt.cpu_model_extra_flags
extra_flags = set([flag.lower() for flag in
CONF.libvirt.cpu_model_extra_flags])
if (CONF.libvirt.virt_type == "kvm" or
CONF.libvirt.virt_type == "qemu"):