From 462199ba1bfc9009305a01025fcb2eb7568c6e98 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 | 53 +++++++++++++++++ .../migration_bandwidth_limit.py | 59 +++++++++++++++++++ provider/migration/migration_base.py | 14 +++++ 3 files changed, 126 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 00000000000..5c76e010e8e --- /dev/null +++ b/libvirt/tests/cfg/migration_with_copy_storage/migration_bandwidth_limit.cfg @@ -0,0 +1,53 @@ +- 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}" + action_during_mig = '[{"func": "check_bandwidth_by_blockjob", "after_event": "block-job", "before_event": "migration-iteration", "func_param": "params", "wait_for_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_event_timeout": "600"}, {"func": "check_bandwidth_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 00000000000..4083c6533b8 --- /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 8e3c473edba..fa5e23fc381 100644 --- a/provider/migration/migration_base.py +++ b/provider/migration/migration_base.py @@ -70,6 +70,7 @@ def parse_funcs(action_during_mig, test, params): 'before_event': one_action.get('before_event'), 'before_pause': one_action.get('before_pause'), 'need_sleep_time': one_action.get('need_sleep_time'), + 'wait_for_event_timeout': one_action.get('wait_for_event_timeout'), 'func_param': func_param}) action_during_mig.append(act_dict) return action_during_mig @@ -726,3 +727,16 @@ def get_vm_serial_session_on_dest(params): vm_session = migration_obj.vm.wait_for_serial_login(timeout=120) params.update({"vm_session": vm_session}) migration_obj.vm.connect_uri = backup_uri + + +def check_bandwidth_by_blockjob(params): + """ + Check bandwidth by blockjob + + :param params: dictionary with the test parameter, get vm name and bandwidth + """ + vm_name = params.get("main_vm") + bandwidth = params.get("bandwidth") + + if not utils_misc.wait_for(lambda: libvirt.check_blockjob(vm_name, 'vda', "bandwidth", str(int(bandwidth)*1024*1024)), 10, step=2): + raise exceptions.TestFail("Check bandwidth failed.")