diff --git a/qemu/tests/cfg/insert_media.cfg b/qemu/tests/cfg/insert_media.cfg new file mode 100644 index 0000000000000000000000000000000000000000..078eb32ec5c76d6f03ad92477c8c17e3ca0adba0 --- /dev/null +++ b/qemu/tests/cfg/insert_media.cfg @@ -0,0 +1,20 @@ +- insert_media: + only Linux + only virtio_scsi + type = insert_media + virt_test_type = qemu + kill_vm = yes + start_vm = no + not_preprocess = yes + monitor_type = qmp + pre_command = "dd if=/dev/zero of=/tmp/new bs=10M count=1 && " + pre_command += "mkisofs -o /tmp/new.iso /tmp/new" + post_command = "rm -rf /tmp/new.iso /tmp/new" + cdrom_cd1 = /tmp/new.iso + tray_move_event = DEVICE_TRAY_MOVED + paused_after_start_vm = yes + force_drive_format_cd1 = scsi-cd + # disable iothread + iothread_scheme ?= + image_iothread ?= + iothreads ?= diff --git a/qemu/tests/insert_media.py b/qemu/tests/insert_media.py new file mode 100644 index 0000000000000000000000000000000000000000..7da4f88c7432de27a122f7bd2486359fbaf7606b --- /dev/null +++ b/qemu/tests/insert_media.py @@ -0,0 +1,57 @@ +from virttest import env_process +from virttest import utils_misc + +from virttest.qemu_capabilities import Flags +from virttest.qemu_devices import qdevices + + +def run(test, params, env): + """ + Steps: + 1. Boot guest with scsi-cd without file, not dummy image. + 2. Add drive layer and insert media. + + :param test: QEMU test object. + :param params: Dictionary with the test parameters. + :param env: Dictionary with test environment. + """ + def move_tary(action, dev_id): + getattr(vm.monitor, 'blockdev_%s_tray' % action)(dev_id) + if not utils_misc.wait_for( + lambda: vm.monitor.get_event(tray_move_event), 60, 0, 3): + test.fail('Failed to get event %s after %s tray.' % + (tray_move_event, action)) + + tray_move_event = params.get('tray_move_event') + dev_id = params.get('cdroms').split()[0] + params["start_vm"] = "yes" + vm_name = params.get('main_vm') + env_process.preprocess_vm(test, params, env, vm_name) + vm = env.get_vm(vm_name) + + if not vm.check_capability(Flags.BLOCKDEV): + test.cancel("Unsupported the insertion media.") + vm.verify_alive() + + drive = vm.devices[dev_id] + format_node = vm.devices[drive.get_param('drive')] + nodes = [format_node] + nodes.extend((n for n in format_node.get_child_nodes())) + for node in nodes: + vm.devices.remove(node, True if isinstance( + node, qdevices.QBlockdevFormatNode) else False) + if not isinstance(node, qdevices.QBlockdevFormatNode): + format_node.del_child_node(node) + drive.set_param('drive', None) + + vm.destroy(False) + vm = vm.clone(copy_state=True) + vm.create() + + move_tary('open', dev_id) + vm.monitor.blockdev_remove_medium(dev_id) + for node in reversed(nodes): + vm.devices.simple_hotplug(node, vm.monitor) + vm.monitor.blockdev_insert_medium(dev_id, format_node.get_qid()) + move_tary('close', dev_id) + vm.destroy()