From 344cdb23f6d2e153af0d4e1ad4841189f64fc4db Mon Sep 17 00:00:00 2001 From: lcheng Date: Wed, 6 Sep 2023 10:59:47 +0800 Subject: [PATCH] migration: Add case to test migrate-setspeed/getspeed VIRT-298170 - [migrate-s(g)etspeed] set/get migration bandwidth limit Signed-off-by: lcheng --- .../migration_cmd/setspeed_and_getspeed.cfg | 56 +++++++++++ .../migration_cmd/setspeed_and_getspeed.py | 95 +++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 libvirt/tests/cfg/migration/migration_cmd/setspeed_and_getspeed.cfg create mode 100644 libvirt/tests/src/migration/migration_cmd/setspeed_and_getspeed.py diff --git a/libvirt/tests/cfg/migration/migration_cmd/setspeed_and_getspeed.cfg b/libvirt/tests/cfg/migration/migration_cmd/setspeed_and_getspeed.cfg new file mode 100644 index 0000000000..26473bd91e --- /dev/null +++ b/libvirt/tests/cfg/migration/migration_cmd/setspeed_and_getspeed.cfg @@ -0,0 +1,56 @@ +- migration.migration_cmd.setspeed_and_getspeed: + type = setspeed_and_getspeed + migration_setup = 'yes' + storage_type = 'nfs' + setup_local_nfs = 'yes' + disk_type = "file" + disk_source_protocol = "netfs" + mnt_path_name = ${nfs_mount_dir} + # 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 + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + status_error = "no" + + variants vm_status: + - vm_running: + start_vm = "yes" + - vm_shutoff: + start_vm = "no" + variants: + - speed_10: + bandwidth = "10" + - speed_0: + bandwidth = "0" + - speed_-1: + status_error = "yes" + bandwidth = "-1" + err_msg = "numerical overflow: bandwidth must be less than" + - speed_8796093022207: + only precopy + bandwidth = "8796093022207" + - speed_17592186044415: + only postcopy + bandwidth = "17592186044415" + - speed_8796093022208: + only precopy + bandwidth = "8796093022208" + status_error = "yes" + err_msg = "numerical overflow: bandwidth must be less than" + - speed_17592186044416: + only postcopy + bandwidth = "17592186044416" + status_error = "yes" + err_msg = "numerical overflow: bandwidth must be less than" + variants: + - precopy: + - postcopy: + postcopy_options = '--postcopy' + err_msg_1 = "Requested operation is not valid: domain is not running" diff --git a/libvirt/tests/src/migration/migration_cmd/setspeed_and_getspeed.py b/libvirt/tests/src/migration/migration_cmd/setspeed_and_getspeed.py new file mode 100644 index 0000000000..9e42944777 --- /dev/null +++ b/libvirt/tests/src/migration/migration_cmd/setspeed_and_getspeed.py @@ -0,0 +1,95 @@ +from virttest import virsh + +from virttest.utils_test import libvirt + +from provider.migration import base_steps + + +def get_bandwidth(vm_name, vm_status, postcopy_options, error_msg, extra, test): + """ + Get bandwidth + + :param vm_name: vm name + :param vm_status: vm status + :param postcopy_options: postcopy options + :param error_msg: error message + :param extra: extra options + :param test: test object + :return: return bandwidth or None + """ + ret = virsh.migrate_getspeed(vm_name, extra=extra) + if ret.exit_status: + if postcopy_options and vm_status == "vm_shutoff": + libvirt.check_result(ret, error_msg) + return None + else: + test.fail("Get bandwidth fail.") + return int(ret.stdout_text.strip()) + + +def run_test(params, vm_name, test): + """ + Run test for setspeed/getspeed + + :param params: Dictionary with the test parameters + :param vm_name: vm name + :param test: test object + """ + bandwidth = params.get("bandwidth") + status_error = "yes" == params.get('status_error', 'no') + error_msg = params.get("err_msg") + vm_status = params.get("vm_status") + postcopy_options = params.get("postcopy_options") + error_msg_1 = params.get("err_msg_1") + + test.log.info("Run test for migrate-setspeed/migrate-getspeed.") + if postcopy_options: + extra = postcopy_options + else: + extra = None + + orig_bandwidth = get_bandwidth(vm_name, vm_status, postcopy_options, + error_msg_1, extra, test) + ret = virsh.migrate_setspeed(vm_name, bandwidth, extra=extra, debug=True) + if ret.exit_status: + if postcopy_options and vm_status == "vm_shutoff": + if bandwidth in ["-1", "8796093022208", "17592186044416"]: + libvirt.check_result(ret, error_msg) + else: + libvirt.check_result(ret, error_msg_1) + return + else: + if status_error: + libvirt.check_result(ret, error_msg) + else: + test.fail("Set bandwidth fail.") + + new_bandwidth = get_bandwidth(vm_name, vm_status, postcopy_options, + error_msg_1, extra, test) + if bandwidth in ["-1", "8796093022208", "17592186044416"]: + if orig_bandwidth and new_bandwidth and orig_bandwidth != new_bandwidth: + test.fail("For bandwidth=%s, bandwidth should keep its original value." % bandwidth) + else: + if int(bandwidth) != new_bandwidth: + test.fail("Set bandwidth fail: %s" % new_bandwidth) + + +def run(test, params, env): + """ + To verify that migration bandwidth limit can be set/got by + migrate-setspeed/getspeed. + + :param test: test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + vm_name = params.get("migrate_main_vm") + + vm = env.get_vm(vm_name) + migration_obj = base_steps.MigrationBase(test, vm, params) + migration_obj.setup_default() + + try: + run_test(params, vm_name, test) + finally: + migration_obj.cleanup_default()