Skip to content

Commit

Permalink
Guestvcpus: enable/disable max vcpu by guest agent
Browse files Browse the repository at this point in the history
  • Loading branch information
rh-jugraham committed Sep 17, 2024
1 parent 2baf67c commit ac9c73e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
11 changes: 11 additions & 0 deletions libvirt/tests/cfg/virsh_cmd/domain/virsh_guestvcpus.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
take_regular_screendumps="no"
vcpus_num = "20"
vcpus_placement = "static"
max_test = ""
option = ""
combine = ""
error_msg = []
Expand All @@ -26,6 +27,16 @@
option = "--enable"
- combine:
combine = "yes"
- max_test:
status_error = "no"
max_test = "yes"
variants:
- disable:
option = "--disable"
- enable:
option = "--enable"
- combine:
combine = "yes"
- error_test:
status_error = "yes"
variants:
Expand Down
39 changes: 31 additions & 8 deletions libvirt/tests/src/virsh_cmd/domain/virsh_guestvcpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def run(test, params, env):
vm = env.get_vm(vm_name)
vcpus_num = int(params.get("vcpus_num", "20"))
vcpus_placement = params.get("vcpus_placement", "static")
max_test = params.get("max_test", "")
option = params.get("option", "")
combine = params.get("combine", "")
invalid_domain = params.get("invalid_domain", "")
Expand All @@ -40,6 +41,13 @@ def run(test, params, env):
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
vmxml_bakup = vmxml.copy()

# Max test: set vcpus_num to the host online cpu number
if max_test == "yes":
host_cpu_info = cpuutil.get_cpu_info()
host_online_cpus = int(host_cpu_info["On-line CPU(s) list"].split("-")[1]) + 1
logging.debug("Host online CPU number: %s" % str(host_online_cpus))
vcpus_num = host_online_cpus

try:
# Modify vm with static vcpus
if vm.is_alive():
Expand All @@ -51,17 +59,28 @@ def run(test, params, env):
# Start guest agent in vm
vm.prepare_guest_agent()

# Normal test: disable/ enable guest vcpus
# Disable/enable guest vcpus
if option and status_error == "no":
for cpu in range(1, vcpus_num):
virsh.guestvcpus(vm_name, str(cpu), option, debug=True)
if max_test == "yes":
# Max test
vcpus_list = '1' + '-' + str(vcpus_num - 1)
virsh.guestvcpus(vm_name, vcpus_list, option, debug=True)
else:
# Normal test
for cpu in range(1, vcpus_num):
virsh.guestvcpus(vm_name, str(cpu), option, debug=True)

# Normal test: combine: --disable 1-max then --enable 1
# Combine: --disable 1-max then --enable
if combine == "yes" and status_error == "no":
vcpus_list = '1' + '-' + str(vcpus_num - 1)
option = "--disable"
virsh.guestvcpus(vm_name, vcpus_list, option, debug=True)
vcpus_list = '1'

# Max test: --enable 1-max (no change to vcpus_list)
# Normal test: --enable 1
if max_test != "yes":
vcpus_list = '1'

option = "--enable"
virsh.guestvcpus(vm_name, vcpus_list, option, debug=True)

Expand All @@ -87,28 +106,32 @@ def run(test, params, env):
# Check the test result of query
ret_output = dict([item.strip() for item in line.split(":")]
for line in output.split("\n"))
if combine == "yes":
if combine == "yes" and max_test != "yes":
online_vcpus = '0-1'
elif option == "--disable":
online_vcpus = '0'
else:
# either normal --enable test or max --enable test or max combine test
online_vcpus = '0' + '-' + str(vcpus_num - 1)

if ret_output["online"] != online_vcpus:
test.fail("Query result is different from"
" the '%s' command." % option)
" the '%s' command."
" Expected %s "
" but query result is %s." % (option, online_vcpus, ret_output["online"]))

# Check the cpu in guest
session = vm.wait_for_login()
vm_cpu_info = cpuutil.get_cpu_info(session)
session.close()

if combine == "yes":
if combine == "yes" and max_test != "yes":
online_vcpus = '0,1'
elif option == "--disable":
online_vcpus = '0'
offline_vcpus = '1' + '-' + str(vcpus_num - 1)
else:
# either normal --enable test or max --enable test or max combine test
online_vcpus = '0' + '-' + str(vcpus_num - 1)

if offline_vcpus:
Expand Down

0 comments on commit ac9c73e

Please sign in to comment.