By using the serial console instead of ssh for executing commands in the guest, we can convert this test to the functional framework.
Signed-off-by: Thomas Huth <th...@redhat.com> --- MAINTAINERS | 1 + tests/functional/meson.build | 1 + .../test_x86_64_hotplug_blk.py} | 50 ++++++++++++------- 3 files changed, 35 insertions(+), 17 deletions(-) rename tests/{avocado/hotplug_blk.py => functional/test_x86_64_hotplug_blk.py} (47%) mode change 100644 => 100755 diff --git a/MAINTAINERS b/MAINTAINERS index 414b6f35fe..1aa519da57 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2273,6 +2273,7 @@ F: hw/block/virtio-blk.c F: hw/block/dataplane/* F: include/hw/virtio/virtio-blk-common.h F: tests/qtest/virtio-blk-test.c +F: tests/functional/test_x86_64_hotplug_blk.py T: git https://github.com/stefanha/qemu.git block virtio-ccw diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 257c7e8182..a14e10124b 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -283,6 +283,7 @@ tests_x86_64_system_thorough = [ 'multiprocess', 'netdev_ethtool', 'virtio_gpu', + 'x86_64_hotplug_blk', 'x86_64_hotplug_cpu', 'x86_64_kvm_xen', 'x86_64_tuxrun', diff --git a/tests/avocado/hotplug_blk.py b/tests/functional/test_x86_64_hotplug_blk.py old mode 100644 new mode 100755 similarity index 47% rename from tests/avocado/hotplug_blk.py rename to tests/functional/test_x86_64_hotplug_blk.py index b36bca02ec..7ddbfefc21 --- a/tests/avocado/hotplug_blk.py +++ b/tests/functional/test_x86_64_hotplug_blk.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# # Functional test that hotplugs a virtio blk disk and checks it on a Linux # guest # @@ -7,12 +9,21 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -import time +from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern + -from avocado_qemu.linuxtest import LinuxTest +class HotPlugBlk(LinuxKernelTest): + ASSET_KERNEL = Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' + '/31/Server/x86_64/os/images/pxeboot/vmlinuz'), + 'd4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129') + + ASSET_INITRD = Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' + '/31/Server/x86_64/os/images/pxeboot/initrd.img'), + '277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b') -class HotPlug(LinuxTest): def blockdev_add(self) -> None: self.vm.cmd('blockdev-add', **{ 'driver': 'null-co', @@ -21,11 +32,12 @@ def blockdev_add(self) -> None: }) def assert_vda(self) -> None: - self.ssh_command('test -e /sys/block/vda') + exec_command_and_wait_for_pattern(self, 'while ! test -e /sys/block/vda ;' + ' do sleep 0.2 ; done', '# ') def assert_no_vda(self) -> None: - with self.assertRaises(AssertionError): - self.assert_vda() + exec_command_and_wait_for_pattern(self, 'while test -e /sys/block/vda ;' + ' do sleep 0.2 ; done', '# ') def plug(self) -> None: args = { @@ -38,11 +50,8 @@ def plug(self) -> None: self.assert_no_vda() self.vm.cmd('device_add', args) - try: - self.assert_vda() - except AssertionError: - time.sleep(1) - self.assert_vda() + self.wait_for_console_pattern('virtio_blk virtio0: [vda]') + self.assert_vda() def unplug(self) -> None: self.vm.cmd('device_del', id='virtio-disk0') @@ -53,17 +62,24 @@ def unplug(self) -> None: self.assert_no_vda() def test(self) -> None: - """ - :avocado: tags=arch:x86_64 - :avocado: tags=machine:q35 - :avocado: tags=accel:kvm - """ self.require_accelerator('kvm') + self.set_machine('q35') + self.vm.add_args('-accel', 'kvm') self.vm.add_args('-device', 'pcie-pci-bridge,id=pci.1,bus=pcie.0') + self.vm.add_args('-m', '1G') + self.vm.add_args('-append', 'console=ttyS0 rd.rescue') + + self.launch_kernel(self.ASSET_KERNEL.fetch(), + self.ASSET_INITRD.fetch(), + wait_for='Entering emergency mode.') + self.wait_for_console_pattern('# ') - self.launch_and_wait() self.blockdev_add() self.plug() self.unplug() + + +if __name__ == '__main__': + LinuxKernelTest.main() -- 2.48.1