From 575ff86a4f1572786d66639f774405fbc074fdb1 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 3 May 2024 08:55:50 -0700 Subject: [PATCH] Avoid setting serial on raw LUN devices Libvirt now enforces that device="lun" (i.e. raw device passthrough) disks must not have the property set. We recently enabled the ability to manage devices by alias instead of serial, but to fully enable this use-case we need to avoid putting serial in the XML to appease libvirt. Related-Bug: #2065084 Change-Id: Ifa2df89f27e58e1e64ce046edeaf6e49a7c89490 --- nova/tests/unit/virt/libvirt/test_config.py | 42 +++++++++++++++++++++ nova/virt/libvirt/config.py | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/nova/tests/unit/virt/libvirt/test_config.py b/nova/tests/unit/virt/libvirt/test_config.py index b91c685571..5d728a1761 100644 --- a/nova/tests/unit/virt/libvirt/test_config.py +++ b/nova/tests/unit/virt/libvirt/test_config.py @@ -1089,6 +1089,48 @@ class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest): """) + def test_config_block_serial(self): + obj = config.LibvirtConfigGuestDisk() + obj.source_type = "block" + obj.source_path = "/tmp/hello" + obj.source_device = "cdrom" + obj.driver_name = "qemu" + obj.target_dev = "/dev/hdc" + obj.target_bus = "ide" + obj.alias = "ua-this-is-my-disk" + obj.serial = "123" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + + + + + 123 + """) + + def test_config_block_lun_no_serial(self): + obj = config.LibvirtConfigGuestDisk() + obj.source_type = "block" + obj.source_path = "/tmp/hello" + obj.source_device = "lun" + obj.driver_name = "qemu" + obj.target_dev = "/dev/sda" + obj.target_bus = "scsi" + obj.alias = "ua-this-is-my-disk" + # This should not be included in the XML because source_device=lun + obj.serial = "123" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + + + + + """) + def test_config_block_parse(self): xml = """ diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index ff1eb925b2..bd5b8cef0f 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -1308,7 +1308,7 @@ class LibvirtConfigGuestDisk(LibvirtConfigGuestDevice): dev.append(etree.Element("target", dev=self.target_dev, bus=self.target_bus)) - if self.serial is not None: + if self.serial is not None and self.source_device != 'lun': dev.append(self._text_node("serial", self.serial)) self._format_iotune(dev)