|
| 1 | +from virttest import error_context, qemu_qtree |
| 2 | + |
| 3 | +from provider import disk_utils |
| 4 | +from provider.block_devices_plug import BlockDevicesPlug |
| 5 | + |
| 6 | + |
| 7 | +@error_context.context_aware |
| 8 | +def run(test, params, env): |
| 9 | + """ |
| 10 | + Test the disk non-default options. |
| 11 | +
|
| 12 | + Steps: |
| 13 | + 1. Boot a VM with packed=true and page-per-vq=true |
| 14 | + 2. Verify the packed and page-per-vq values |
| 15 | + 3. Do some basic I/O operation in the VM |
| 16 | + 4. Unplug and hotplug the disk |
| 17 | + 5. Do again a basic I/O operation |
| 18 | +
|
| 19 | + :param test: QEMU test object. |
| 20 | + :param params: Dictionary with the test parameters. |
| 21 | + :param env: Dictionary with test environment. |
| 22 | + """ |
| 23 | + |
| 24 | + def verify_non_default_options(option_key, expected_value): |
| 25 | + """Verify the non-default values. |
| 26 | + :param option_key: the QEMU option to be checked. |
| 27 | + :param expected_value: the QEMU option expected value. |
| 28 | + """ |
| 29 | + error_context.context(f"Verify {option_key} from monitor.", test.log.info) |
| 30 | + qtree = qemu_qtree.QtreeContainer() |
| 31 | + qtree_option_value = False |
| 32 | + try: |
| 33 | + qtree.parse_info_qtree(vm.monitor.info("qtree")) |
| 34 | + except AttributeError: |
| 35 | + test.cancel("Monitor doesn't support qtree skip this test") |
| 36 | + error_msg = ( |
| 37 | + f"'{option_key}' value mismatch: expected %s but report from monitor is: %s" |
| 38 | + ) |
| 39 | + |
| 40 | + for node in qtree.get_nodes(): |
| 41 | + if ( |
| 42 | + isinstance(node, qemu_qtree.QtreeDev) |
| 43 | + and node.qtree.get(option_key) == expected_value |
| 44 | + ): |
| 45 | + qtree_option_value = node.qtree.get(option_key) |
| 46 | + error_context.context( |
| 47 | + f"The qtree_option_value: {qtree_option_value}", test.log.debug |
| 48 | + ) |
| 49 | + |
| 50 | + if qtree_option_value != expected_value: |
| 51 | + error_msg = error_msg % (str(expected_value), qtree_option_value) |
| 52 | + test.fail(error_msg) |
| 53 | + |
| 54 | + vm = env.get_vm(params["main_vm"]) |
| 55 | + vm.verify_alive() |
| 56 | + |
| 57 | + qtree_check_images = params.get_list("qtree_check_images", "stg0") |
| 58 | + |
| 59 | + serial = params.object_params(qtree_check_images[0])["image_serial"] |
| 60 | + |
| 61 | + fstype = params.get("fstype", None) |
| 62 | + io_cmd = params.get("io_cmd", "") |
| 63 | + clean_env = params.get_boolean("clean_env", True) |
| 64 | + |
| 65 | + # To be configured by the user in the cfg |
| 66 | + dst_dir = params.get("dst_dir", None) |
| 67 | + disk_utils.execute_io_test( |
| 68 | + params, |
| 69 | + vm, |
| 70 | + qtree_check_images[0], |
| 71 | + serial, |
| 72 | + fstype, |
| 73 | + dst_dir=dst_dir, |
| 74 | + io_command=io_cmd, |
| 75 | + clean=clean_env, |
| 76 | + ignore_all_errors=False, |
| 77 | + ) |
| 78 | + |
| 79 | + for image in qtree_check_images: |
| 80 | + qtree_check_image = params.get_dict(f"qtree_check_{image}", "{}") |
| 81 | + if qtree_check_image: |
| 82 | + for option_key in qtree_check_image: |
| 83 | + error_context.base_context( |
| 84 | + f"Options to verify: {option_key} {qtree_check_image[option_key]}", |
| 85 | + test.log.debug, |
| 86 | + ) |
| 87 | + verify_non_default_options(option_key, qtree_check_image[option_key]) |
| 88 | + else: |
| 89 | + test.log.warning("There are no options to be checked in the qtree") |
| 90 | + |
| 91 | + plug = BlockDevicesPlug(vm) |
| 92 | + plug.unplug_devs_serial(qtree_check_images[0]) |
| 93 | + plug.hotplug_devs_serial(qtree_check_images[0]) |
| 94 | + disk_utils.execute_io_test( |
| 95 | + params, |
| 96 | + vm, |
| 97 | + qtree_check_images[0], |
| 98 | + serial, |
| 99 | + fstype, |
| 100 | + dst_dir=dst_dir, |
| 101 | + io_command=io_cmd, |
| 102 | + clean=clean_env, |
| 103 | + ignore_all_errors=False, |
| 104 | + ) |
0 commit comments