From 62bfc21931a7e9c8b3d50a0851587df8b5fc6b2d Mon Sep 17 00:00:00 2001 From: lcheng Date: Thu, 26 Oct 2023 12:04:13 +0800 Subject: [PATCH] migration: Add bandwidth limit case VIRT-297906 - VM live migration with copy storage - bandwidth limit Signed-off-by: lcheng --- .../migration_bandwidth_limit.cfg | 54 +++++++++++++++++ .../migration_bandwidth_limit.py | 59 +++++++++++++++++++ provider/migration/migration_base.py | 3 + 3 files changed, 116 insertions(+) create mode 100644 libvirt/tests/cfg/migration_with_copy_storage/migration_bandwidth_limit.cfg create mode 100644 libvirt/tests/src/migration_with_copy_storage/migration_bandwidth_limit.py diff --git a/libvirt/tests/cfg/migration_with_copy_storage/migration_bandwidth_limit.cfg b/libvirt/tests/cfg/migration_with_copy_storage/migration_bandwidth_limit.cfg new file mode 100644 index 0000000000..b95c10945e --- /dev/null +++ b/libvirt/tests/cfg/migration_with_copy_storage/migration_bandwidth_limit.cfg @@ -0,0 +1,54 @@ +- migration_with_copy_storage.migration_bandwidth_limit: + type = migration_bandwidth_limit + migration_setup = 'yes' + # Console output can only be monitored via virsh console output + only_pty = True + take_regular_screendumps = no + # Extra options to pass after + virsh_migrate_extra = "" + # SSH connection time out + ssh_timeout = 60 + start_vm = "yes" + # Local URI + virsh_migrate_connect_uri = "qemu:///system" + virsh_migrate_dest_state = "running" + virsh_migrate_src_state = "shut off" + image_convert = "no" + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + client_ip = "${migrate_source_host}" + client_user = "root" + client_pwd = "${migrate_source_pwd}" + status_error = "no" + simple_disk_check_after_mig = "no" + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + virsh_migrate_desturi = "qemu+tcp://${migrate_dest_host}/system" + setup_nfs = "no" + nfs_mount_dir = + bandwidth = "20" + jobinfo_item = "Memory bandwidth:" + precopy_bandwidth = "${bandwidth}" + compare_to_value = "${bandwidth}" + check_item = "bandwidth" + check_item_value = "20971520" + action_during_mig = '[{"func": "libvirt_disk.check_item_by_blockjob", "after_event": "block-job", "before_event": "migration-iteration", "func_param": "params", "wait_for_after_event_timeout": "600"}, {"func": "check_domjobinfo_during_mig", "after_event": "migration-iteration", "func_param": "params"}]' + migrate_start_state = "running" + variants: + - p2p: + virsh_migrate_options = "--live --p2p --verbose" + - non_p2p: + virsh_migrate_options = "--live --verbose" + variants set_bandwidth: + - bandwidth: + virsh_migrate_extra = "--bandwidth ${bandwidth}" + - setspeed_before_migration: + - setspeed_during_migration: + virsh_migrate_extra = "--bandwidth 30" + action_during_mig = '[{"func": "set_bandwidth", "after_event": "block-job", "func_param": "params", "wait_for_after_event_timeout": "600"}, {"func": "libvirt_disk.check_item_by_blockjob", "func_param": "params"}, {"func": "check_domjobinfo_during_mig", "func_param": "params"}]' + variants: + - copy_storage_all: + copy_storage_option = "--copy-storage-all" + - copy_storage_inc: + copy_storage_option = "--copy-storage-inc" diff --git a/libvirt/tests/src/migration_with_copy_storage/migration_bandwidth_limit.py b/libvirt/tests/src/migration_with_copy_storage/migration_bandwidth_limit.py new file mode 100644 index 0000000000..85655ac5c7 --- /dev/null +++ b/libvirt/tests/src/migration_with_copy_storage/migration_bandwidth_limit.py @@ -0,0 +1,59 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright Redhat +# +# SPDX-License-Identifier: GPL-2.0 +# +# Author: Liping Cheng +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from virttest import virsh + +from provider.migration import base_steps + + +def run(test, params, env): + """ + To verify that bandwidth limit can take effect for storage copying during + migration. + + :param test: test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + def setup_setspeed_before_migration(): + """ + Setup for setspeed_before_migration + + """ + bandwidth = params.get("bandwidth") + + test.log.info("Setup bandwidth limit before migration.") + migration_obj.setup_connection() + virsh.migrate_setspeed(vm_name, bandwidth, debug=True) + + def cleanup_test(): + """ + Cleanup steps + + """ + migration_obj.cleanup_connection() + base_steps.cleanup_disks_remote(params, vm) + + set_bandwidth = params.get('set_bandwidth', '') + vm_name = params.get("migrate_main_vm") + + vm = env.get_vm(vm_name) + params.update({'vm_obj': vm}) + migration_obj = base_steps.MigrationBase(test, vm, params) + setup_test = eval("setup_%s" % set_bandwidth) if "setup_%s" % set_bandwidth in \ + locals() else migration_obj.setup_connection + + try: + setup_test() + base_steps.prepare_disks_remote(params, vm) + migration_obj.run_migration() + migration_obj.verify_default() + finally: + cleanup_test() diff --git a/provider/migration/migration_base.py b/provider/migration/migration_base.py index 8e3c473edb..b931545314 100644 --- a/provider/migration/migration_base.py +++ b/provider/migration/migration_base.py @@ -15,6 +15,7 @@ from virttest.libvirt_xml import vm_xml from virttest.migration import MigrationTest +from virttest.utils_libvirt import libvirt_disk # pylint: disable=W0611 from virttest.utils_libvirt import libvirt_memory from virttest.utils_libvirt import libvirt_monitor from virttest.utils_libvirt import libvirt_network # pylint: disable=W0611 @@ -71,6 +72,8 @@ def parse_funcs(action_during_mig, test, params): 'before_pause': one_action.get('before_pause'), 'need_sleep_time': one_action.get('need_sleep_time'), 'func_param': func_param}) + if one_action.get('wait_for_after_event_timeout'): + act_dict.update({'wait_for_after_event_timeout': one_action.get('wait_for_after_event_timeout')}) action_during_mig.append(act_dict) return action_during_mig else: