@samitouri / QOSamiQemu / commits / e579bb528c

tests/functional: Add hotplug_scsi test to hotplug virtio-scsi disk

Signed-off-by: Siddhi Katage <siddhi.katage@oracle.com> Message-ID: <20260210113135.771697-1-siddhi.katage@oracle.com> [thuth: Add the new .py file to the MAINTAINERS file] Signed-off-by: Thomas Huth <th.huth@posteo.eu>

Siddhi Katage committed Feb 10, 2026 at 11:31 UTC e579bb528c7bfeeb4b509e1cfeea6153af7295ed
3 files changed +88
MAINTAINERS
+1
@@ -2338,6 +2338,7 @@ F: tests/qtest/virtio-scsi-test.c
2338 F: tests/qtest/fuzz-virtio-scsi-test.c
2339 F: tests/qtest/am53c974-test.c
2340 F: tests/qtest/fuzz-lsi53c895a-test.c
2341 +F: tests/functional/x86_64/test_hotplug_scsi.py
2342 T: git https://github.com/bonzini/qemu.git scsi-next
2343
2344 SSI
tests/functional/x86_64/meson.build
+1
@@ -31,6 +31,7 @@ endif
31 tests_x86_64_system_thorough = [
32 'acpi_bits',
33 'hotplug_blk',
34 + 'hotplug_scsi',
35 'hotplug_cpu',
36 'intel_iommu',
37 'kvm_xen',
tests/functional/x86_64/test_hotplug_scsi.py new
+86
@@ -0,0 +1,86 @@
1 +#!/usr/bin/env python3
2 +#
3 +# Functional test that hotplugs a virtio scsi disk and checks it on a Linux
4 +# guest
5 +#
6 +# SPDX-License-Identifier: GPL-2.0-or-later
7 +
8 +from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern
9 +
10 +class HotPlugScsi(LinuxKernelTest):
11 + ASSET_KERNEL = Asset(
12 + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases'
13 + '/31/Server/x86_64/os/images/pxeboot/vmlinuz'),
14 + 'd4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129')
15 +
16 + ASSET_INITRD = Asset(
17 + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases'
18 + '/31/Server/x86_64/os/images/pxeboot/initrd.img'),
19 + '277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b')
20 +
21 + def blockdev_add(self) -> None:
22 + self.vm.cmd('blockdev-add', **{
23 + 'driver': 'null-co',
24 + 'size': 1073741824,
25 + 'node-name': 'disk0'
26 + })
27 +
28 + def add_scsi_controller(self) -> None:
29 + self.vm.cmd('device_add', {
30 + 'driver': 'virtio-scsi-pci',
31 + 'id': 'scsi0',
32 + 'bus': 'pci.1',
33 + 'addr': '1',
34 + })
35 +
36 + def assert_sda(self) -> None:
37 + exec_command_and_wait_for_pattern(self, 'while ! test -e /sys/block/sda ;'
38 + ' do sleep 0.2 ; done', '# ')
39 +
40 + def assert_no_sda(self) -> None:
41 + exec_command_and_wait_for_pattern(self, 'while test -e /sys/block/sda ;'
42 + ' do sleep 0.2 ; done', '# ')
43 +
44 + def plug(self) -> None:
45 + args = {
46 + 'driver':'scsi-hd',
47 + 'drive':'disk0',
48 + 'bus':'scsi0.0',
49 + 'id':'scsi-disk0',
50 + }
51 +
52 + self.assert_no_sda()
53 + self.vm.cmd('device_add', args)
54 + self.wait_for_console_pattern('[sda] Attached SCSI disk')
55 + self.assert_sda()
56 +
57 + def unplug(self) -> None:
58 + self.vm.cmd('device_del', id='scsi-disk0')
59 +
60 + self.vm.event_wait('DEVICE_DELETED', 1.0,
61 + match={'data': {'device': 'scsi-disk0'}})
62 +
63 + self.assert_no_sda()
64 +
65 + def test(self) -> None:
66 + self.require_accelerator('kvm')
67 + self.set_machine('q35')
68 + self.vm.add_args('-accel', 'kvm')
69 + self.vm.add_args('-device', 'pcie-pci-bridge,id=pci.1,bus=pcie.0')
70 + self.vm.add_args('-m', '1G')
71 + self.vm.add_args('-append', 'console=ttyS0 rd.rescue')
72 +
73 + self.launch_kernel(self.ASSET_KERNEL.fetch(),
74 + self.ASSET_INITRD.fetch(),
75 + wait_for='Entering emergency mode.')
76 + self.wait_for_console_pattern('# ')
77 +
78 + self.blockdev_add()
79 + self.add_scsi_controller()
80 + self.plug()
81 + self.unplug()
82 +
83 +
84 +if __name__ == '__main__':
85 + LinuxKernelTest.main()
86 +