From 3f0ab3e355d49a55d021aa40bb72b9bc4ac640c6 Mon Sep 17 00:00:00 2001 From: cliping Date: Mon, 29 May 2023 17:20:12 +0800 Subject: [PATCH] migration: Add case for offline migration VIRT-XXXX - VM definition migration(offline migration) Signed-off-by: cliping --- .../offline_migration/offline_migration.cfg | 52 +++++++++++++++ .../offline_migration/offline_migration.py | 65 +++++++++++++++++++ provider/migration/base_steps.py | 8 ++- 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 libvirt/tests/cfg/migration/offline_migration/offline_migration.cfg create mode 100644 libvirt/tests/src/migration/offline_migration/offline_migration.py diff --git a/libvirt/tests/cfg/migration/offline_migration/offline_migration.cfg b/libvirt/tests/cfg/migration/offline_migration/offline_migration.cfg new file mode 100644 index 0000000000..54223d1d88 --- /dev/null +++ b/libvirt/tests/cfg/migration/offline_migration/offline_migration.cfg @@ -0,0 +1,52 @@ +- migration.offline_migration: + type = offline_migration + 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' + virsh_migrate_dest_state = "shut off" + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + status_error = "no" + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + virsh_migrate_desturi = "qemu+tcp://${migrate_dest_host}/system" + + variants: + - p2p: + virsh_migrate_options = '--p2p --verbose --offline --persistent' + - non_p2p: + virsh_migrate_options = '--verbose --offline --persistent' + variants: + - src_vm_running: + start_vm = "yes" + virsh_migrate_src_state = "running" + variants: + - with_undefinesource: + virsh_migrate_extra = "--undefinesource" + src_vm_persistency_state = "nonexist" + - without_undefinesource: + src_vm_persistency_state = "running" + - src_vm_shutoff: + start_vm = "no" + variants: + - with_undefinesource: + virsh_migrate_extra = "--undefinesource" + virsh_migrate_src_state = "failed to get domain" + src_vm_persistency_state = "nonexist" + - without_undefinesource: + virsh_migrate_src_state = "shut off" + src_vm_persistency_state = "shut off" diff --git a/libvirt/tests/src/migration/offline_migration/offline_migration.py b/libvirt/tests/src/migration/offline_migration/offline_migration.py new file mode 100644 index 0000000000..7eed62e4fe --- /dev/null +++ b/libvirt/tests/src/migration/offline_migration/offline_migration.py @@ -0,0 +1,65 @@ +from virttest import virsh + +from virttest.utils_test import libvirt + +from provider.migration import base_steps + + +def run(test, params, env): + """ + Test offline migration. + + :param test: test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + def verify_test(): + """ + Verify steps + + """ + desturi = params.get("virsh_migrate_desturi") + virsh_migrate_extra = params.get("virsh_migrate_extra") + virsh_migrate_src_state = params.get("virsh_migrate_src_state") + src_vm_persistency_state = params.get("src_vm_persistency_state") + + test.log.info("Verify steps.") + if virsh_migrate_src_state and "failed to get domain" in virsh_migrate_src_state: + func_returns = dict(migration_obj.migration_test.func_ret) + migration_obj.migration_test.func_ret.clear() + test.log.debug("Migration returns function results:%s", func_returns) + if int(migration_obj.migration_test.ret.exit_status) == 0: + migration_obj.migration_test.post_migration_check([vm], params, + dest_uri=desturi) + result = virsh.domstate(vm_name, extra="--reason", uri=migration_obj.src_uri, debug=True) + libvirt.check_result(result, expected_fails=virsh_migrate_src_state) + else: + migration_obj.verify_default() + + if src_vm_persistency_state: + src_vm_persistency = virsh.dom_list(options="--all --persistent", debug=True) + if src_vm_persistency_state == "nonexist": + if vm_name in src_vm_persistency.stdout.strip(): + test.fail("%s should not exist." % vm_name) + else: + pat_str = "%s.*%s" % (vm_name, src_vm_persistency_state) + libvirt.check_result(src_vm_persistency, expected_match=pat_str) + + dest_vm_xml = virsh.dumpxml(vm_name, extra="--migratable --inactive", debug=True, uri=desturi).stdout.strip() + test.log.debug("dest vm xml: %s", dest_vm_xml) + if dest_vm_xml != src_vm_xml: + test.fail("Check source and target vm xml failed.") + + 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() + src_vm_xml = virsh.dumpxml(vm_name, extra="--migratable --inactive", debug=True).stdout.strip() + test.log.debug("src vm xml: %s", src_vm_xml) + migration_obj.run_migration() + verify_test() + finally: + migration_obj.cleanup_connection() diff --git a/provider/migration/base_steps.py b/provider/migration/base_steps.py index 8589f54f30..b9aac41f82 100644 --- a/provider/migration/base_steps.py +++ b/provider/migration/base_steps.py @@ -58,15 +58,19 @@ def setup_default(self): """ set_remote_libvirtd_log = "yes" == self.params.get("set_remote_libvirtd_log", "no") + start_vm = self.params.get("start_vm", "yes") self.test.log.info("Setup steps by default.") if set_remote_libvirtd_log: self.set_remote_log() libvirt.set_vm_disk(self.vm, self.params) - if not self.vm.is_alive(): + if start_vm == "no" and self.vm.is_alive(): + self.vm.destroy() + + if start_vm == "yes" and not self.vm.is_alive(): self.vm.start() - self.vm.wait_for_login().close() + self.vm.wait_for_login().close() def run_migration(self): """