From: Satheesh Rajendran <sathn...@linux.vnet.ibm.com> libvirt autotest patch to test virsh vcpupin command which in turn covers vcpuinfo,vcpucount commands This test covers the following git hub issue https://github.com/autotest/autotest/issues/464
Signed-off-by: Satheesh Rajendran <sathn...@linux.vnet.ibm.com> --- client/tests/libvirt/tests/virsh_vcpupin.py | 86 +++++++++++++++++++++++++++ client/virt/libvirt_vm.py | 28 +++++++++ client/virt/subtests.cfg.sample | 3 + 3 files changed, 117 insertions(+), 0 deletions(-) create mode 100644 client/tests/libvirt/tests/virsh_vcpupin.py diff --git a/client/tests/libvirt/tests/virsh_vcpupin.py b/client/tests/libvirt/tests/virsh_vcpupin.py new file mode 100644 index 0000000..bae0596 --- /dev/null +++ b/client/tests/libvirt/tests/virsh_vcpupin.py @@ -0,0 +1,86 @@ +import logging, re, os, commands, string +from autotest.client.shared import utils, error +from autotest.client.virt import libvirt_vm + +def run_virsh_vcpupin(test, params, env): + """ + Test the command virsh hostname + + (1) Get the host and guest cpu count + (2) Call virsh vcpupin for each vcpu with pinning of each cpu + (3) Check whether the virsh vcpupin has pinned the respective vcpu to cpu + (4) TODO: Right now it the testcase covers the pinning one cpu at a time + this can be improved by a random number of cpus + """ + + # Initialize the variables + expected_affinity = [] + total_affinity = [] + actual_affinity = [] + d = {} + + def build_actual_info(domname,vcpu): + """ + This function returns list of the vcpu's affinity from + virsh vcpuinfo output + + @param: domname: VM Name to operate on + @param: vcpu: vcpu number for which the affinity is required + """ + output = libvirt_vm.virsh_vcpuinfo(domname) + cmd = re.findall('[^Affinity:][-y]+', str(output)) + total_affinity = cmd[vcpu].lstrip() + actual_affinity = list(total_affinity) + return actual_affinity + + def build_expected_info(vcpu,cpu): + """ + This function returns the list of vcpu's expected affinity build + + @param: vcpu: vcpu number for which the affinity is required + @param: cpu: cpu details for the affinity + """ + expected_affinity = [] + for i in range(int(host_cpu_count)): + expected_affinity.append('y') + for i in range(int(host_cpu_count)): + if cpu != i: + expected_affinity[i] = '-' + d[vcpu] = expected_affinity + return d + + def virsh_check_vcpupin(domname,vcpu,cpu): + """ + This function checks the actual and the expected affinity of given vcpu + and raises error if not matchs + + @param: domname: VM Name to operate on + @param: vcpu: vcpu number for which the affinity is required + @param: cpu: cpu details for the affinity + """ + expected_output = build_expected_info(vcpu,cpu) + actual_output = build_actual_info(domname,vcpu) + if expected_output[vcpu] == actual_output: + logging.info("successfully pinned cpu:%s --> vcpu:%s", cpu,vcpu) + else: + raise error.TestFail("Command 'virsh vcpupin %s %s %s' not succeeded " + % (vm_name,vcpu,cpu)) + + # Get the vm name + vm_name = params.get("main_vm") + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + # Get the host cpu count + cmd = "cat /proc/cpuinfo |grep processor|wc -l" + host_cpu_count_result = utils.run(cmd, ignore_status=False) + host_cpu_count = host_cpu_count_result.stdout.strip() + + # Get the guest vcpu count + guest_vcpu_count = libvirt_vm.virsh_vcpucount_live(vm_name) + + # Run test case + for vcpu in range(int(guest_vcpu_count)): + for cpu in range(int(host_cpu_count)): + libvirt_vm.virsh_vcpupin(vm_name,vcpu,cpu) + virsh_check_vcpupin(vm_name,vcpu,cpu) diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py index 9a06f05..d6f1c76 100644 --- a/client/virt/libvirt_vm.py +++ b/client/virt/libvirt_vm.py @@ -116,6 +116,34 @@ def virsh_cmd(cmd, uri="", ignore_status=False, print_info=False): return ret +def virsh_vcpupin(domname,vcpu,cpu,uri="",ignore_status=False,print_info=False): + """ + Changes the cpu affinity for respective vcpu. + """ + try: + cmd_vcpupin = "vcpupin %s %s %s" % (domname,vcpu,cpu) + virsh_cmd(cmd_vcpupin,uri) + except error.CmdError, detail: + logging.error("Virsh vcpupin VM %s failed:\n%s", name, detail) + return False + + +def virsh_vcpuinfo(domname,uri="",ignore_status=False,print_info=False): + """ + Prints the vcpuinfo of a given domain. + """ + cmd_vcpuinfo = "vcpuinfo %s" % domname + return virsh_cmd(cmd_vcpuinfo,uri).stdout.strip() + + +def virsh_vcpucount_live(domname,uri="",ignore_status=False,print_info=False): + """ + Prints the vcpucount of a given domain. + """ + cmd_vcpucount = "vcpucount --live --active %s" % domname + return virsh_cmd(cmd_vcpucount,uri).stdout.strip() + + def virsh_freecell(uri = "", ignore_status=False, extra = ""): """ Prints the available amount of memory on the machine or within a NUMA cell. diff --git a/client/virt/subtests.cfg.sample b/client/virt/subtests.cfg.sample index 45b6277..1162178 100644 --- a/client/virt/subtests.cfg.sample +++ b/client/virt/subtests.cfg.sample @@ -212,6 +212,9 @@ variants: status_error = "yes" libvirtd = "off" + - virsh_vcpupin: install setup image_copy unattended_install.cdrom + type = virsh_vcpupin + - virsh_version: install setup image_copy unattended_install.cdrom type = virsh_version vms = '' -- 1.7.5.4 _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest