Skip to content

Commit c5ea19f

Browse files
committed
testscript: Test that setting a function ID in a BDF fails
We need a negative test that shows, that adding a function ID when entering a BDF result in libvirt generating a failure and CHV not crashing. Signed-off-by: Pascal Scholz <[email protected]> On-behalf-of: SAP [email protected]
1 parent bfc41ed commit c5ea19f

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

tests/common.nix

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ let
2727
serial ? "pty",
2828
# Whether all device will be assigned a static BDF through the XML or only some
2929
all_static_bdf ? false,
30+
# Whether we add a function ID to specific BDFs or not
31+
use_bdf_function ? false,
3032
}:
3133
''
3234
<domain type='kvm' id='21050'>
@@ -136,9 +138,14 @@ let
136138
${
137139
# Assign a fixed BDF that would normally be acquired by the implicit RNG device
138140
if all_static_bdf then
139-
''
140-
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
141-
''
141+
if use_bdf_function then
142+
''
143+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
144+
''
145+
else
146+
''
147+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
148+
''
142149
else
143150
""
144151
}
@@ -569,6 +576,14 @@ in
569576
})}";
570577
};
571578
};
579+
"/etc/domain-chv-static-bdf-with-function.xml" = {
580+
"C+" = {
581+
argument = "${pkgs.writeText "domain-chv-static-bdf-with-function.xml" (virsh_ch_xml {
582+
all_static_bdf = true;
583+
use_bdf_function = true;
584+
})}";
585+
};
586+
};
572587
"/etc/new_interface.xml" = {
573588
"C+" = {
574589
argument = "${pkgs.writeText "new_interface.xml" (new_interface { })}";

tests/testscript.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

18541890
def 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

Comments
 (0)