From f63029b461b81ad93e0681973ed9b5bfca405d5a Mon Sep 17 00:00:00 2001 From: melanie witt Date: Tue, 6 Aug 2024 20:29:22 +0000 Subject: [PATCH] libvirt: Remove node device XML validate flags Node device XML validation flags [1]: VIR_NODE_DEVICE_(CREATE|DEFINE)_XML_VALIDATE were added in libvirt 8.10.0 but we support older libvirt versions which will raise an AttributeError when flag access is attempted. We are not currently using the flags (nothing calling with validate=True) so this removes the flags from the code entirely. If the flags are needed in the future, they can be added again at that time. Closes-Bug: #2076163 [1] https://github.com/libvirt/libvirt/commit/d8791c3c7caa6e3cadaf98a5a2c94b232ac30fed Change-Id: I015d9b7cad413986058da4d29ca7711c844bfa84 --- nova/tests/fixtures/libvirt.py | 6 ------ nova/tests/unit/virt/libvirt/test_host.py | 12 ++++++++++++ nova/virt/libvirt/host.py | 14 ++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/nova/tests/fixtures/libvirt.py b/nova/tests/fixtures/libvirt.py index 099ea39450..fce0086ad3 100644 --- a/nova/tests/fixtures/libvirt.py +++ b/nova/tests/fixtures/libvirt.py @@ -202,12 +202,6 @@ VIR_DOMAIN_METADATA_DESCRIPTION = 0 VIR_DOMAIN_METADATA_TITLE = 1 VIR_DOMAIN_METADATA_ELEMENT = 2 -# virNodeDeviceCreateXML flags -VIR_NODE_DEVICE_CREATE_XML_VALIDATE = 4 - -# virNodeDeviceDefineXML flags -VIR_NODE_DEVICE_DEFINE_XML_VALIDATE = 5 - # Libvirt version to match MIN_LIBVIRT_VERSION in driver.py FAKE_LIBVIRT_VERSION = versionutils.convert_version_to_int( libvirt_driver.MIN_LIBVIRT_VERSION) diff --git a/nova/tests/unit/virt/libvirt/test_host.py b/nova/tests/unit/virt/libvirt/test_host.py index a3fcddfdee..111b4fad8c 100644 --- a/nova/tests/unit/virt/libvirt/test_host.py +++ b/nova/tests/unit/virt/libvirt/test_host.py @@ -1168,6 +1168,18 @@ Active: 8381604 kB self.host.device_lookup_by_name("foo") mock_nodeDeviceLookupByName.assert_called_once_with("foo") + @mock.patch.object(fakelibvirt.virConnect, 'nodeDeviceCreateXML') + def test_device_create(self, mock_create): + node_dev = vconfig.LibvirtConfigNodeDevice() + self.host.device_create(node_dev) + mock_create.assert_called_once_with(node_dev.to_xml(), flags=0) + + @mock.patch.object(fakelibvirt.virConnect, 'nodeDeviceDefineXML') + def test_device_define(self, mock_define): + node_dev = vconfig.LibvirtConfigNodeDevice() + self.host.device_define(node_dev) + mock_define.assert_called_once_with(node_dev.to_xml(), flags=0) + def test_get_pcinet_info(self): dev_name = "net_enp2s2_02_9a_a1_37_be_54" parent_address = "pci_0000_04_11_7" diff --git a/nova/virt/libvirt/host.py b/nova/virt/libvirt/host.py index a0511c7649..b89748b1ca 100644 --- a/nova/virt/libvirt/host.py +++ b/nova/virt/libvirt/host.py @@ -1254,35 +1254,29 @@ class Host(object): """ return self.get_connection().nodeDeviceLookupByName(name) - def device_create(self, conf, validate=False): + def device_create(self, conf): """Create a node device from specified device XML This creates the device as transient. :param conf: A LibvirtConfigObject of the device to create - :param validate: whether to validate the XML document against schema :returns: a virNodeDevice instance if successful, else None """ - flag = libvirt.VIR_NODE_DEVICE_CREATE_XML_VALIDATE - flags = validate and flag or 0 device_xml = conf.to_xml() - return self.get_connection().nodeDeviceCreateXML(device_xml, flags) + return self.get_connection().nodeDeviceCreateXML(device_xml, flags=0) - def device_define(self, conf, validate=False): + def device_define(self, conf): """Define a node device from specified device XML This defines the device to make it persistent. :param conf: A LibvirtConfigObject of the device to create - :param validate: whether to validate the XML document against schema :returns: a virNodeDevice instance if successful, else None """ - flag = libvirt.VIR_NODE_DEVICE_DEFINE_XML_VALIDATE - flags = validate and flag or 0 device_xml = conf.to_xml() - return self.get_connection().nodeDeviceDefineXML(device_xml, flags) + return self.get_connection().nodeDeviceDefineXML(device_xml, flags=0) def device_start(self, dev): """Start a defined node device