Skip to content

Commit

Permalink
set topology is all cases and worked on checking if set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rh-jugraham committed Sep 25, 2024
1 parent a806093 commit 5ab358b
Showing 1 changed file with 64 additions and 34 deletions.
98 changes: 64 additions & 34 deletions libvirt/tests/src/cpu/vcpu_max_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from virttest import virsh
from virttest import cpu as cpuutil
from virttest.libvirt_xml import vm_xml
# from virttest.utils_test import libvirt


# Using as lower capital is not the best way to do, but this is just a
Expand Down Expand Up @@ -53,7 +52,8 @@ def run(test, params, env):

# many_clusters case
if clusters_param == "many":
clusters_list = [2, 4, 6]
# ensure that vcpus_num is evenly divisble by the number of clusters
clusters_list = [clusters for clusters in [2, 4, 6] if vcpus_num % clusters == 0]
cores_list = [vcpus_num // clusters for clusters in clusters_list]
# default_clusters case
else:
Expand All @@ -69,25 +69,25 @@ def run(test, params, env):
# many_clusters case
# sockets = vcpus_num // number of cores // number of clusters
if clusters_param == "many":
cores_list = [2, 2, 2] # defaulting to 2 cores
clusters_list = [2, 4, 6]
sockets_list = [(vcpus_num // 2) // clusters for clusters in clusters_list]
# defaulting to either 2 or 3 cores
cores = 2 if vcpus_num % 2 == 0 else 3
clusters_list = [clusters for clusters in [2, 4, 6] if (vcpus_num / cores) % clusters == 0]
cores_list = [cores] * (len(clusters_list))
sockets_list = [(vcpus_num // cores) // clusters for clusters in clusters_list]
# default_clusters case
# sockets * cores = vcpus_num
else:
cores_list = [2, 4, 6]
# ensure that vcpus_num is evenly divisble by the number of cores
sockets_list = [vcpus_num // cores for cores in cores_list if vcpus_num % cores == 0]
# remove any core amounts that are not evenly divisble by vcpus_num
cores_list = [cores for cores in cores_list if vcpus_num % cores == 0]
cores_list = [cores for cores in [2, 4, 6] if vcpus_num % cores == 0]
sockets_list = [vcpus_num // cores for cores in cores_list]

# note to self: ensure errors in edge cases
if not sockets_list or not cores_list:
# throw some error!
logging.debug("some error!!!")
elif (len(cores_list) == 1):
# len(sockets_list) will also be 1
set_and_check_topology(vm, vm_name, vmxml, vcpus_num, sockets_list[0], cores_list[0])
set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets_list[0], cores_list[0])
else:
for i, cores in enumerate(cores_list):
if (cores == 0):
Expand Down Expand Up @@ -120,32 +120,30 @@ def set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets, cores,
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)

logging.debug("Trying to define guest with '%s' vcpus, '%s' sockets, '%s' cores, and '%s' clusters",
str(vcpus_num), str(sockets), str(cores), str(clusters))
if clusters > 1:
# set manually
vmcpu_xml = vmxml["cpu"]
vmcpu_xml["topology"] = {
"sockets": str(sockets),
"clusters": str(clusters),
"cores":str(cores),
"threads":"1"}
vmxml["cpu"] = vmcpu_xml
vmxml["vcpu"] = vcpus_num
vmxml["current_vcpu"] = vcpus_num
vmxml["cpu"]["topology"] = {
"sockets": sockets,
"cores": cores,
"threads": 1,
"clusters": clusters
}
vmxml.sync()

else:
# set using set_vm_vcpus helper function
vmxml.set_vm_vcpus(
vm_name,
vcpus_num,
current=vcpus_num,
sockets=sockets,
cores=cores,
threads=1,
add_topology=True
)
logging.debug("Define guest with '%s' vcpus, '%s' sockets, and '%s' cores, and '%s' clusters",
logging.debug("Defined guest with '%s' vcpu(s), '%s' socket(s), and '%s' core(s), and '%s' cluster(s)",
str(vcpus_num), str(sockets), str(cores), str(clusters))
logging.debug("Full xml:\n %s", str(vmxml))

# Start guest agent in vm
try:
Expand All @@ -158,24 +156,56 @@ def set_and_check_topology(test, params, env, vmxml, vcpus_num, sockets, cores,


# from polarion: Check lscpu output within the vm is consistent with the topology configured

# Check the topology in the guest
# session = vm.wait_for_login()
# vm_topology_info = cpuutil.get_cpu_info(session)
# session.close()
session = vm.wait_for_login()
lscpu_output = cpuutil.get_cpu_info(session)
# get_cpu_info() should close the session
session.close()

logging.debug("lscpu output:\n%s", lscpu_output)

lscpu_check_fail = "The configured topology is not consistent with the lscpu output within the vm for "
if (str(vcpus_num) != lscpu_output["CPU(s)"]):
test.fail(lscpu_check_fail + "CPU(s)")
elif (('0' + '-' + str(vcpus_num - 1)) != lscpu_output["On-line CPU(s) list"]):
test.fail(lscpu_check_fail + "on-line CPU(s) list")
elif ("1" != lscpu_output["Thread(s) per core"]):
test.fail(lscpu_check_fail + "thread(s) per core")
elif (str(sockets) != lscpu_output["Socket(s)"]):
test.fail(lscpu_check_fail + "socket(s)")
elif (str(cores * clusters) != lscpu_output["Core(s) per socket"]):
test.fail(lscpu_check_fail + "core(s) per socket")

session = vm.wait_for_login()

# vm_cpus = vm_topology_info["CPU(s)"]
# vm_online_cpus = vm_topology_info["On-line CPU(s) list"]
# vm_threads_per_core = vm_topology_info["Thread(s) per core"]
# vm_cores_per_socket = vm_topology_info["Core(s) per socket"]
# vm_sockets = vm_topology_info["Socket(s)"]
# from polarion: Check kernel file for coreid for each vcpu in the vm

# notes = cpus, online cpus, and threads per core always the same --> only cores per socket and sockets change
for vcpu in range(vcpus_num):
cmd_coreid = f'cat /sys/devices/system/cpu/cpu{vcpu}/topology/core_id'
ret_coreid = session.cmd_output(cmd_coreid).strip()
if (str(vcpu) != ret_coreid):
test.fail("In the vm kernel file, the coreid for vcpu %s should not be %s" % (vcpu, ret_coreid))

# from polarion: Check vcpu cluster number

logging.debug("~~~ session info %s -- %s", session, type(session))

# from polarion: Check kernel file for coreid for each vcpu in the vm
cmd_clusterid = 'cat /sys/devices/system/cpu/cpu*/topology/cluster_id | sort | uniq -c | wc -l'
ret_clusterid = session.cmd_output(cmd_clusterid).strip()
logging.debug("ret cluster id: %s", ret_clusterid)
# The result should be equal to defined clusters's value
if (str(clusters) != ret_clusterid):
test.fail("In the vm kernel file, the vcpu cluster number should be %s, not %s" % (clusters, ret_clusterid))

# from polarion: Check cluster cpu list

# from polarion: Check vcpu cluster number
cmd_cluster_cpu_list = 'cat /sys/devices/system/cpu/cpu*/topology/cluster_cpus_list | sort | uniq -c | wc -l'
ret_cluster_cpu_list = session.cmd_output(cmd_cluster_cpu_list).strip()
logging.debug("ret cluster cpu list: %s", ret_cluster_cpu_list)
# The result should be equal to #sockets * #clusters
if (str(sockets * clusters) != ret_cluster_cpu_list):
test.fail("In the vm kernel file, the cluster cpu list should be %s, not %s" % (str(sockets * clusters), ret_cluster_cpu_list))

session.close()

# from polarion: Check cluster cpu list

0 comments on commit 5ab358b

Please sign in to comment.