Skip to content

Commit

Permalink
migration: Add case for offline migration
Browse files Browse the repository at this point in the history
VIRT-XXXX - VM definition migration(offline migration)

Signed-off-by: cliping <[email protected]>
  • Loading branch information
cliping committed Jun 21, 2023
1 parent 536c5ab commit 3f0ab3e
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 <domain> <desturi>
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"
65 changes: 65 additions & 0 deletions libvirt/tests/src/migration/offline_migration/offline_migration.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 6 additions & 2 deletions provider/migration/base_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 3f0ab3e

Please sign in to comment.