diff --git a/qemu/tests/block_hotplug_passthrough.py b/qemu/tests/block_hotplug_passthrough.py new file mode 100644 index 0000000000000000000000000000000000000000..67ae10bf111c82ef92aa8032f2850e81fdcb6d39 --- /dev/null +++ b/qemu/tests/block_hotplug_passthrough.py @@ -0,0 +1,92 @@ +import logging + +from virttest import error_context +from virttest import utils_test +from virttest import utils_disk +from avocado.utils import process +from provider.storage_benchmark import generate_instance +from provider.block_devices_plug import BlockDevicesPlug + + +@error_context.context_aware +def run(test, params, env): + """ + Hotplug/unplug passthrough disk test: + 1) Create passthrough disk with scsi_debug tool. + 2) Start the guest. + 3) Hotplug this passthrough disk. + 4) Create partition on this disk and format it. + 5) Do iozone/dd test on this disk. + 6) Reboot the guest. + 7) Unplug this passthrough disk. + + :param test: QEMU test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + + def create_path_disk(): + """Create a passthrough disk with scsi_debug """ + process.getoutput(params["pre_command"], shell=True) + disks_old = process.getoutput("ls -1d /dev/sd*", shell=True).split() + process.system_output(params["create_command"], timeout=300, + shell=True, verbose=False) + disks_new = process.getoutput("ls -1d /dev/sd*", shell=True).split() + return list(set(disks_new) - set(disks_old))[0] + + def hotplug_path_disk(vm, path_dev): + """Hotplug passthrough disk.""" + error_context.context("Hotplug passthrough device", logging.info) + vm.params["image_name_stg0"] = path_dev + plug = BlockDevicesPlug(vm) + plug.hotplug_devs_serial() + return plug[0] + + def format_plug_disk(session, did): + """Format new hotpluged disk.""" + stg_image_size = params["stg_image_size"] + ostype = params["os_type"] + if ostype == "windows": + if not utils_disk.update_windows_disk_attributes(session, did): + test.fail("Failed to clear readonly for all disks and online " + "them in guest") + partition = utils_disk.configure_empty_disk(session, did, + stg_image_size, ostype) + if not partition: + test.fail("Fail to format disks.") + return partition[0] + + def run_io_test(session, partition): + """ Run io test on the hot plugged disk. """ + iozone_options = params.get('iozone_options') + dd_test = params.get('dd_test') + if iozone_options: + error_context.context( + "Run iozone test on the plugged disk.", logging.info) + iozone = generate_instance(params, vm, 'iozone') + iozone.run(iozone_options.format(partition[0])) + if dd_test: + error_context.context( + "Do dd test on the plugged disk", logging.info) + partition = partition.split("/")[-1] + session.cmd(dd_test.format(partition)) + + def unplug_path_disk(vm): + """Unplug passthrough disk.""" + error_context.context("Unplug passthrouth device", logging.info) + plug = BlockDevicesPlug(vm) + plug.unplug_devs_serial() + + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + session = vm.wait_for_login() + + if params["os_type"] == "windows": + session = utils_test.qemu.windrv_check_running_verifier( + session, vm, test, params["driver_name"]) + + drive_index = hotplug_path_disk(vm, create_path_disk()) + run_io_test(session, format_plug_disk(session, drive_index)) + session = vm.reboot(session) + unplug_path_disk(vm) + session.close() diff --git a/qemu/tests/cfg/block_hotplug_passthrough.cfg b/qemu/tests/cfg/block_hotplug_passthrough.cfg new file mode 100644 index 0000000000000000000000000000000000000000..2c9967fa3cbb0f5199c0346a8066035afbe89ff1 --- /dev/null +++ b/qemu/tests/cfg/block_hotplug_passthrough.cfg @@ -0,0 +1,18 @@ +- block_hotplug_passthrough: + type = block_hotplug_passthrough + only virtio_scsi + pre_command = "modprobe -r scsi_debug; modprobe sg" + post_command = "modprobe -r sg" + create_command = "modprobe scsi_debug add_host=1 dev_size_mb=2048" + images += " stg0" + boot_drive_stg0 = no + drive_bus_stg0 = 1 + drive_format_stg0 = scsi-block + image_raw_device_stg0 = yes + image_format_stg0 = raw + stg_image_size = 2G + Linux: + dd_test = "dd if=/dev/zero of=/dev/{0} bs=1M count=40 oflag=direct&& dd if=/dev/{0} of=/dev/null bs=1M count=40 iflag=direct" + Windows: + driver_name = vioscsi + iozone_options = '-az -b c:\{0}_iozone.xls -g 1g -y 32k -i 0 -i 1 -I -f {0}:\test-data'