From 4108cdc1bc5a07d20b1deac66e169fd85dd7617c Mon Sep 17 00:00:00 2001 From: lcheng Date: Wed, 20 Sep 2023 21:33:20 +0800 Subject: [PATCH] migration: Add case about abort migration VIRT-298383 - [VM migration][domjobabort] abort migration job with wrong API flag Signed-off-by: lcheng --- .../abort_migration_with_wrong_api_flag.cfg | 39 +++++++++++++++++++ .../src/migration/async_job/async_job.py | 22 +++++++++++ provider/migration/migration_base.py | 12 ++++-- 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 libvirt/tests/cfg/migration/async_job/abort_migration_with_wrong_api_flag.cfg create mode 100644 libvirt/tests/src/migration/async_job/async_job.py diff --git a/libvirt/tests/cfg/migration/async_job/abort_migration_with_wrong_api_flag.cfg b/libvirt/tests/cfg/migration/async_job/abort_migration_with_wrong_api_flag.cfg new file mode 100644 index 00000000000..e740f955ce2 --- /dev/null +++ b/libvirt/tests/cfg/migration/async_job/abort_migration_with_wrong_api_flag.cfg @@ -0,0 +1,39 @@ +- migration.async_job.abort_migration_with_wrong_api_flag: + type = async_job + 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 + # Local URI + virsh_migrate_connect_uri = 'qemu:///system' + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + check_network_accessibility_after_mig = "yes" + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + virsh_migrate_desturi = "qemu+tcp://${migrate_dest_host}/system" + status_error = "no" + virsh_migrate_dest_state = "running" + virsh_migrate_src_state = "shut off" + domjobabort_on_src = "yes" + variants: + - abort_postcopy_migration_by_domjobabort_without_postcopy: + virsh_migrate_options = '--live --p2p --verbose --postcopy --timeout 3 --timeout-postcopy --postcopy-bandwidth 10 --bandwidth 10' + domjobabort_err_msg = "cannot abort migration in post-copy mode" + action_during_mig = '[{"func": "libvirt_network.check_established", "after_event": "iteration: '1'", "func_param": "params"}, {"func": "do_domjobabort", "func_param": "params", "need_sleep_time": "3"}]' + - abort_precopy_migration_by_domjobabort_with_postcopy: + domjobabort_err_msg = "current job is not outgoing migration in post-copy mode" + virsh_migrate_options = '--live --p2p --verbose --bandwidth 10' + abort_with_postcopy = "yes" + action_during_mig = '[{"func": "libvirt_network.check_established", "after_event": "iteration: '1'", "func_param": "params"}, {"func": "do_domjobabort", "func_param": "params", "need_sleep_time": "3"}]' diff --git a/libvirt/tests/src/migration/async_job/async_job.py b/libvirt/tests/src/migration/async_job/async_job.py new file mode 100644 index 00000000000..023d74dbae2 --- /dev/null +++ b/libvirt/tests/src/migration/async_job/async_job.py @@ -0,0 +1,22 @@ +from provider.migration import base_steps + + +def run(test, params, env): + """ + Test async job + + :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) + + try: + migration_obj.setup_connection() + migration_obj.run_migration() + migration_obj.verify_default() + finally: + migration_obj.cleanup_connection() diff --git a/provider/migration/migration_base.py b/provider/migration/migration_base.py index 8e3c473edba..c6bc375fa23 100644 --- a/provider/migration/migration_base.py +++ b/provider/migration/migration_base.py @@ -703,11 +703,17 @@ def do_domjobabort(params): vm_name = params.get("main_vm") domjobabort_err_msg = params.get("domjobabort_err_msg") postcopy_options = params.get("postcopy_options") + abort_with_postcopy = "yes" == params.get("abort_with_postcopy", "no") + domjobabort_on_src = "yes" == params.get("domjobabort_on_src", "no") - if postcopy_options: - ret = virsh.domjobabort(vm_name, option="--postcopy", debug=True, uri=dest_uri) + if domjobabort_on_src: + uri = None else: - ret = virsh.domjobabort(vm_name, debug=True, uri=dest_uri) + uri = dest_uri + if postcopy_options or abort_with_postcopy: + ret = virsh.domjobabort(vm_name, option="--postcopy", debug=True, uri=uri) + else: + ret = virsh.domjobabort(vm_name, debug=True, uri=uri) libvirt.check_result(ret, expected_fails=domjobabort_err_msg, check_both_on_error=True)