From a10cc7b15f943ba81f5fd50469d4c4d7faff0fd9 Mon Sep 17 00:00:00 2001 From: lcheng Date: Fri, 17 Jan 2025 11:04:56 +0800 Subject: [PATCH] migration: add case about migrate vm which have vmx-* cpu features XXX-303279 - [VM migration] migrate vm which have vmx-* cpu features Signed-off-by: lcheng --- .../migration_with_vmx_cpu_features.cfg | 40 ++++++++++++ .../migration_with_vmx_cpu_features.py | 62 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 libvirt/tests/cfg/migration/migration_misc/migration_with_vmx_cpu_features.cfg create mode 100644 libvirt/tests/src/migration/migration_misc/migration_with_vmx_cpu_features.py diff --git a/libvirt/tests/cfg/migration/migration_misc/migration_with_vmx_cpu_features.cfg b/libvirt/tests/cfg/migration/migration_misc/migration_with_vmx_cpu_features.cfg new file mode 100644 index 00000000000..79d144732cf --- /dev/null +++ b/libvirt/tests/cfg/migration/migration_misc/migration_with_vmx_cpu_features.cfg @@ -0,0 +1,40 @@ +- migration.migration_misc.migration_with_vmx_cpu_features: + type = migration_with_vmx_cpu_features + 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}" + status_error = "no" + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + virsh_migrate_desturi = "qemu+tcp://${migrate_dest_host}/system" + start_vm = "no" + variants: + - p2p: + virsh_migrate_options = '--live --p2p --verbose' + - non_p2p: + virsh_migrate_options = '--live --verbose' + variants migration_option: + - with_xml: + - without_xml: + variants cpu_mode: + - host_model: + numa_cell = "'numa_cell': [{'cpus': '0-1', 'memory': '2097152', 'unit': 'KiB'}]" + vm_attrs = {'cpu': {'mode': 'host-model', 'check': 'partial', ${numa_cell}}} + - custom: + cpu_mode = "custom" diff --git a/libvirt/tests/src/migration/migration_misc/migration_with_vmx_cpu_features.py b/libvirt/tests/src/migration/migration_misc/migration_with_vmx_cpu_features.py new file mode 100644 index 00000000000..1949c91be68 --- /dev/null +++ b/libvirt/tests/src/migration/migration_misc/migration_with_vmx_cpu_features.py @@ -0,0 +1,62 @@ +import os + +from avocado.utils import process + +from virttest import data_dir +from virttest import virsh +from virttest.libvirt_xml import vm_xml + +from provider.migration import base_steps + + +def run(test, params, env): + """ + Verify that migration can succeed when host and guest have vmx-* cpu + features. + + :param test: test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + def setup_test(): + """ + Setup steps + + """ + cpu_mode = params.get("cpu_mode") + migration_option = params.get("migration_option") + + test.log.info("Setup steps.") + migration_obj.setup_connection() + vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) + if cpu_mode == "host_model": + vm_attrs = eval(params.get('vm_attrs', '{}')) + vmxml.setup_attrs(**vm_attrs) + vmxml.sync() + else: + base_steps.sync_cpu_for_mig(params) + + if not vm.is_alive(): + vm.start() + vm.wait_for_login().close() + + if migration_option == "with_xml": + xmlfile = os.path.join(data_dir.get_tmp_dir(), '%s.xml' % vm_name) + virsh.dumpxml(vm_name, extra="--migratable", to_file=xmlfile, ignore_status=False) + params.update({"virsh_migrate_extra": f"--xml {xmlfile}"}) + + vm_name = params.get("migrate_main_vm") + + vm = env.get_vm(vm_name) + migration_obj = base_steps.MigrationBase(test, vm, params) + + cmd = "virsh domcapabilities |grep vmx- |wc -l" + ret = process.run(cmd, shell=True).stdout_text.strip() + if int(ret) == 0: + test.cancel("Please use the host with vmx-* cpu features to test.") + try: + setup_test() + migration_obj.run_migration() + migration_obj.verify_default() + finally: + migration_obj.cleanup_connection()