@@ -1850,13 +1850,50 @@ def test_bdf_invalid_device_id(self):
18501850 )
18511851 assert number_of_devices (controllerVM ) == num_before_expected_failure
18521852
1853+ def test_bdf_valid_device_id_with_function_id (self ):
1854+ """
1855+ Test that a BDFs containing a function ID leads to errors.
1856+
1857+ CHV currently doesn't support multi function devices. So we need
1858+ to checks that libvirt does not allow to attach such devices. We
1859+ check that instantiating a domain with function ID doesn't work.
1860+ Then we test that we cannot hotplug a device with a function ID
1861+ in its BDF definition.
1862+ """
1863+ # We don't support multi function devices currently. The config
1864+ # below defines a device with function ID, so instantiating it
1865+ # should fail.
1866+ controllerVM .fail ("virsh define /etc/domain-chv-static-bdf-with-function.xml" )
1867+
1868+ # Now create a VM from a definition that does not contain any
1869+ # function IDs in it device definition.
1870+ controllerVM .succeed ("virsh define /etc/domain-chv.xml" )
1871+ controllerVM .succeed ("virsh start testvm" )
1872+ assert wait_for_ssh (controllerVM )
1873+
1874+ # We need to check that no devices are added, so let's save how
1875+ # many devices are present in the VM after creating it.
1876+ num_before_expected_failure = number_of_devices (controllerVM )
1877+ # Now we create a disk that we hotplug to a BDF with a function
1878+ # ID. This should fail.
1879+ controllerVM .succeed (
1880+ "qemu-img create -f raw /var/lib/libvirt/storage-pools/nfs-share/vdb.img 5M"
1881+ )
1882+ controllerVM .fail (
1883+ "virsh attach-disk --domain testvm --target vdb --source /var/lib/libvirt/storage-pools/nfs-share/vdb.img --persistent --address pci:0.0.1f.5"
1884+ )
1885+ # Even though we only land here if the command above failed, we
1886+ # should still ensure that no new devices magically appeared.
1887+ assert number_of_devices (controllerVM ) == num_before_expected_failure
1888+
18531889
18541890def suite ():
18551891 # Test cases in alphabetical order
18561892 testcases = [
18571893 LibvirtTests .test_bdf_explicit_assignment ,
18581894 LibvirtTests .test_bdf_implicit_assignment ,
18591895 LibvirtTests .test_bdf_invalid_device_id ,
1896+ LibvirtTests .test_bdf_valid_device_id_with_function_id ,
18601897 LibvirtTests .test_bdfs_dont_conflict_after_transient_unplug ,
18611898 LibvirtTests .test_bdfs_implicitly_assgined_same_after_recreate ,
18621899 LibvirtTests .test_disk_is_locked ,
0 commit comments