|
| 1 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2 | +# |
| 3 | +# Copyright Redhat |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: GPL-2.0 |
| 6 | +# |
| 7 | +# Author: Liping Cheng <[email protected]> |
| 8 | +# |
| 9 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 | + |
| 11 | +from virttest import virsh |
| 12 | +from virttest.utils_test import libvirt |
| 13 | +from virttest.libvirt_xml import vm_xml |
| 14 | + |
| 15 | +from provider.migration import base_steps |
| 16 | + |
| 17 | + |
| 18 | +def run(test, params, env): |
| 19 | + """ |
| 20 | + To test target vm name, live xml and persistent xml can be changed via virsh |
| 21 | + migrate options during migration. |
| 22 | +
|
| 23 | + :param test: test object |
| 24 | + :param params: Dictionary with the test parameters |
| 25 | + :param env: Dictionary with test environment. |
| 26 | + """ |
| 27 | + def setup_test(): |
| 28 | + """ |
| 29 | + Setup steps |
| 30 | + """ |
| 31 | + persistent_option = params.get("persistent_option") |
| 32 | + dname = params.get("dname") |
| 33 | + xml_title = params.get("xml_title") |
| 34 | + xml_path = params.get("xml_path") |
| 35 | + persistent_xml_path = params.get("persistent_xml_path") |
| 36 | + extra = params.get("virsh_migrate_extra") |
| 37 | + |
| 38 | + test.log.info("Setup test.") |
| 39 | + migration_obj.setup_connection() |
| 40 | + if persistent_option: |
| 41 | + extra = "%s %s" % (extra, persistent_option) |
| 42 | + if dname: |
| 43 | + extra = "%s --dname %s" % (extra, dname) |
| 44 | + if xml_path: |
| 45 | + if xml_path == "xml_exist": |
| 46 | + mig_xml = vm_xml.VMXML.new_from_dumpxml(vm_name, options="--migratable") |
| 47 | + graphic_xml = mig_xml.get_devices(device_type="graphics")[0] |
| 48 | + mig_xml.del_device(graphic_xml) |
| 49 | + graphic_xml["autoport"] = "no" |
| 50 | + graphic_xml["port"] = "6666" |
| 51 | + mig_xml.add_device(graphic_xml) |
| 52 | + mig_xml.sync() |
| 53 | + extra = "%s --xml %s" % (extra, mig_xml.xml) |
| 54 | + else: |
| 55 | + extra = "%s --xml /var/tmp/xml_non_exist_test" % extra |
| 56 | + if persistent_xml_path: |
| 57 | + if persistent_xml_path == "persistent_xml_exist": |
| 58 | + persistent_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) |
| 59 | + persistent_xml.title = xml_title |
| 60 | + extra = "%s --persistent-xml %s" % (extra, persistent_xml.xml) |
| 61 | + else: |
| 62 | + extra = "%s --persistent-xml /var/tmp/persistent_xml_non_exist_test" % extra |
| 63 | + params.update({"virsh_migrate_extra": extra}) |
| 64 | + vm.start() |
| 65 | + vm.wait_for_login().close() |
| 66 | + |
| 67 | + def verify_test(): |
| 68 | + """ |
| 69 | + Verify steps |
| 70 | + """ |
| 71 | + desturi = params.get("virsh_migrate_desturi") |
| 72 | + persistent_option = params.get("persistent_option") |
| 73 | + dname = params.get("dname") |
| 74 | + xml_title = params.get("xml_title") |
| 75 | + xml_path = params.get("xml_path") |
| 76 | + persistent_xml_path = params.get("persistent_xml_path") |
| 77 | + src_vm_state = params.get("virsh_migrate_src_state") |
| 78 | + dest_vm_state = params.get("virsh_migrate_dest_state") |
| 79 | + status_error = "yes" == params.get("status_error", "no") |
| 80 | + |
| 81 | + test.log.info("Verify test.") |
| 82 | + if status_error: |
| 83 | + migration_obj.verify_default() |
| 84 | + else: |
| 85 | + if dname: |
| 86 | + migration_obj.migration_test.ping_vm(vm, params, uri=desturi) |
| 87 | + if not libvirt.check_vm_state(vm_name, src_vm_state, uri=migration_obj.src_uri, debug=True): |
| 88 | + test.fail("When with '--dname', check source vm state failed.") |
| 89 | + if not libvirt.check_vm_state(dname, dest_vm_state, uri=desturi, debug=True): |
| 90 | + test.fail("When with '--dname', check dest vm state failed.") |
| 91 | + else: |
| 92 | + migration_obj.verify_default() |
| 93 | + vm.name = dname if dname else vm_name |
| 94 | + new_xml = virsh.dumpxml(vm.name, debug=True, uri=desturi) |
| 95 | + if dname: |
| 96 | + if dname not in new_xml.stdout_text.strip(): |
| 97 | + test.fail(f"Not found {dname} in vm xml.") |
| 98 | + |
| 99 | + if xml_path: |
| 100 | + if xml_path == "xml_exist": |
| 101 | + libvirt.check_result(new_xml, expected_match="autoport='no'") |
| 102 | + else: |
| 103 | + libvirt.check_result(new_xml, expected_match="autoport='yes'") |
| 104 | + virsh.destroy(vm.name, debug=True, uri=desturi) |
| 105 | + if persistent_option: |
| 106 | + if not libvirt.check_vm_state(vm.name, "shut off", uri=desturi): |
| 107 | + test.fail("When migration with '--persistent', check dest vm state failed.") |
| 108 | + if dname: |
| 109 | + if dname not in virsh.dom_list("--all", debug=True, uri=desturi).stdout_text: |
| 110 | + test.fail(f"When migration with '--persistent --dname', not found {dname} in vm list.") |
| 111 | + if persistent_xml_path: |
| 112 | + remote_virsh = virsh.Virsh(uri=desturi) |
| 113 | + vmxml_inactive = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name, "--security-info", remote_virsh) |
| 114 | + if vmxml_inactive.title != xml_title: |
| 115 | + test.fail("'--persistent-xml' didn't take effect in live migration.") |
| 116 | + else: |
| 117 | + if virsh.domain_exists(vm.name, uri=desturi): |
| 118 | + test.fail("The domain is found on the target host, but expected not.") |
| 119 | + |
| 120 | + vm_name = params.get("migrate_main_vm") |
| 121 | + vm = env.get_vm(vm_name) |
| 122 | + migration_obj = base_steps.MigrationBase(test, vm, params) |
| 123 | + |
| 124 | + try: |
| 125 | + setup_test() |
| 126 | + migration_obj.run_migration() |
| 127 | + verify_test() |
| 128 | + finally: |
| 129 | + migration_obj.cleanup_connection() |
0 commit comments