Skip to content

Commit

Permalink
Merge pull request autotest#5159 from cliping/speed
Browse files Browse the repository at this point in the history
migration: Add case to test migrate-setspeed/getspeed
  • Loading branch information
dzhengfy authored Sep 18, 2023
2 parents 6b8c404 + 344cdb2 commit d1703e7
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
- migration.migration_cmd.setspeed_and_getspeed:
type = setspeed_and_getspeed
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
image_convert = 'no'
server_ip = "${migrate_dest_host}"
server_user = "root"
server_pwd = "${migrate_dest_pwd}"
status_error = "no"

variants vm_status:
- vm_running:
start_vm = "yes"
- vm_shutoff:
start_vm = "no"
variants:
- speed_10:
bandwidth = "10"
- speed_0:
bandwidth = "0"
- speed_-1:
status_error = "yes"
bandwidth = "-1"
err_msg = "numerical overflow: bandwidth must be less than"
- speed_8796093022207:
only precopy
bandwidth = "8796093022207"
- speed_17592186044415:
only postcopy
bandwidth = "17592186044415"
- speed_8796093022208:
only precopy
bandwidth = "8796093022208"
status_error = "yes"
err_msg = "numerical overflow: bandwidth must be less than"
- speed_17592186044416:
only postcopy
bandwidth = "17592186044416"
status_error = "yes"
err_msg = "numerical overflow: bandwidth must be less than"
variants:
- precopy:
- postcopy:
postcopy_options = '--postcopy'
err_msg_1 = "Requested operation is not valid: domain is not running"
95 changes: 95 additions & 0 deletions libvirt/tests/src/migration/migration_cmd/setspeed_and_getspeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from virttest import virsh

from virttest.utils_test import libvirt

from provider.migration import base_steps


def get_bandwidth(vm_name, vm_status, postcopy_options, error_msg, extra, test):
"""
Get bandwidth
:param vm_name: vm name
:param vm_status: vm status
:param postcopy_options: postcopy options
:param error_msg: error message
:param extra: extra options
:param test: test object
:return: return bandwidth or None
"""
ret = virsh.migrate_getspeed(vm_name, extra=extra)
if ret.exit_status:
if postcopy_options and vm_status == "vm_shutoff":
libvirt.check_result(ret, error_msg)
return None
else:
test.fail("Get bandwidth fail.")
return int(ret.stdout_text.strip())


def run_test(params, vm_name, test):
"""
Run test for setspeed/getspeed
:param params: Dictionary with the test parameters
:param vm_name: vm name
:param test: test object
"""
bandwidth = params.get("bandwidth")
status_error = "yes" == params.get('status_error', 'no')
error_msg = params.get("err_msg")
vm_status = params.get("vm_status")
postcopy_options = params.get("postcopy_options")
error_msg_1 = params.get("err_msg_1")

test.log.info("Run test for migrate-setspeed/migrate-getspeed.")
if postcopy_options:
extra = postcopy_options
else:
extra = None

orig_bandwidth = get_bandwidth(vm_name, vm_status, postcopy_options,
error_msg_1, extra, test)
ret = virsh.migrate_setspeed(vm_name, bandwidth, extra=extra, debug=True)
if ret.exit_status:
if postcopy_options and vm_status == "vm_shutoff":
if bandwidth in ["-1", "8796093022208", "17592186044416"]:
libvirt.check_result(ret, error_msg)
else:
libvirt.check_result(ret, error_msg_1)
return
else:
if status_error:
libvirt.check_result(ret, error_msg)
else:
test.fail("Set bandwidth fail.")

new_bandwidth = get_bandwidth(vm_name, vm_status, postcopy_options,
error_msg_1, extra, test)
if bandwidth in ["-1", "8796093022208", "17592186044416"]:
if orig_bandwidth and new_bandwidth and orig_bandwidth != new_bandwidth:
test.fail("For bandwidth=%s, bandwidth should keep its original value." % bandwidth)
else:
if int(bandwidth) != new_bandwidth:
test.fail("Set bandwidth fail: %s" % new_bandwidth)


def run(test, params, env):
"""
To verify that migration bandwidth limit can be set/got by
migrate-setspeed/getspeed.
: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)
migration_obj.setup_default()

try:
run_test(params, vm_name, test)
finally:
migration_obj.cleanup_default()

0 comments on commit d1703e7

Please sign in to comment.