[libvirt] [libvirt-test-api][PATCH 0/2]Fix issues in the method of getting vcpu thread id of vcpupin_live and cpu_affinity

Hongming Zhang (2): Fix the issues in checking method of vcpupin_live Modify the checking method via passing the vcpu thread id repos/domain/cpu_affinity.py | 16 +++++++++------- repos/setVcpus/vcpupin_live.py | 36 ++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 23 deletions(-) -- 1.9.3

The new method will get the vcpu thread id via qemu-monitor. Then get the Cpus_allowed_list value from /proc using the vcpu's thread id modified: repos/setVcpus/vcpupin_live.py --- repos/setVcpus/vcpupin_live.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/repos/setVcpus/vcpupin_live.py b/repos/setVcpus/vcpupin_live.py index c3dfe8e..9f21583 100644 --- a/repos/setVcpus/vcpupin_live.py +++ b/repos/setVcpus/vcpupin_live.py @@ -13,30 +13,34 @@ from utils import utils required_params = ('guestname', 'vcpu', 'cpulist',) optional_params = {} -def vcpupin_check(guestname, vcpu, cpumap): +def vcpupin_check(guestname, vcpu, cpulist): """check vcpu subprocess status of the running virtual machine grep Cpus_allowed_list /proc/PID/task/*/status """ - tmp_str = '' - cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname - status, pid = utils.exec_cmd(cmd, shell=True) + cmd_pid = "cat /var/run/libvirt/qemu/%s.pid" % guestname + status, pid = utils.exec_cmd(cmd_pid, shell=True) if status: logger.error("failed to get the pid of domain %s" % guestname) return 1 - cmd = "grep Cpus_allowed_list /proc/%s/task/*/status" % pid[0] - status, output = utils.exec_cmd(cmd, shell=True) - logger.debug("command '%s' output is:" % cmd) - for i in range(len(output)): - tmp_str += ''.join(output[i]) + '\n' - logger.debug(tmp_str) + cmd_vcpu_task_id = "virsh qemu-monitor-command %s --hmp info cpus|grep '#%s'|cut -d '=' -f3"\ + % (guestname,vcpu) + status, vcpu_task_id = utils.exec_cmd(cmd_vcpu_task_id, shell=True) + if status: + logger.error("failed to get the threadid of domain %s" % guestname) + return 1 + + logger.debug("vcpu id %s:" % vcpu_task_id[0]) + cmd_cpus_allowed_list = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid[0] , vcpu_task_id[0]) + status, output = utils.exec_cmd(cmd_cpus_allowed_list, shell=True) + if status: + logger.error("failed to get the cpu_allowed_list of vcpu %s") + return 1 - task_list = output[1:] - vcpu_task = task_list[int(vcpu)] - cpulist = vcpu_task.split('\t')[1] - ret = utils.param_to_tuple(cpulist, maxcpu) + logger.debug("the output of command 'grep Cpus_allowed_list \ + /proc/%s/task/%s/status' is %s" % (pid[0],vcpu_task_id[0],output)) - if ret == cpumap: + if output[0].split('\t')[1] == cpulist: logger.info("vcpu process cpus allowed list is expected") return 0 else: @@ -92,7 +96,7 @@ def vcpupin_live(params): return 1 logger.info("check vcpu pin status on host") - ret = vcpupin_check(guestname, vcpu, cpumap) + ret = vcpupin_check(guestname, vcpu, cpulist) if ret: logger.error("domain vcpu pin failed") return 1 -- 1.9.3

modified: repos/domain/cpu_affinity.py --- repos/domain/cpu_affinity.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/repos/domain/cpu_affinity.py b/repos/domain/cpu_affinity.py index e710968..8246938 100644 --- a/repos/domain/cpu_affinity.py +++ b/repos/domain/cpu_affinity.py @@ -142,16 +142,18 @@ def vcpu_affinity_check(domain_name, vcpu, expected_pinned_cpu, hypervisor): logger.error("failed to get the pid of \ the running virtual machine process") return 1 - if 'el6' in host_kernel_version: - cmd_get_task_list = "grep Cpus_allowed_list /proc/%s/task/*/status" % pid + if 'el6' or 'el7' in host_kernel_version: + cmd_vcpu_task_id = "virsh qemu-monitor-command %s --hmp info cpus|grep '#%s'|cut -d '=' -f3"\ + % (domain_name,vcpu) + status, output = commands.getstatusoutput(cmd_vcpu_task_id) + vcpu_task_id = output[:output.find("^")] + logger.debug("vcpu id %s:" % vcpu_task_id) + cmd_get_task_list = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid , vcpu_task_id) status, output = commands.getstatusoutput(cmd_get_task_list) - logger.debug("the output of command 'grep Cpus_allowed_list \ - /proc/%s/task/*/status' is %s" % (pid, output)) + /proc/%s/task/%s/status' is %s" % (pid,vcpu_task_id,output)) + actual_pinned_cpu = int(output.split('\t')[1]) - task_list = output.split('\n')[1:] - vcpu_task = task_list[int(vcpu)] - actual_pinned_cpu = int(vcpu_task.split('\t')[1]) elif 'el5' in host_kernel_version: cmd_get_task_list = "grep Cpus_allowed /proc/%s/task/*/status" % pid status, output = commands.getstatusoutput(cmd_get_task_list) -- 1.9.3

ACK to all of them BR, Luyao ----- Original Message ----- From: "Hongming Zhang" <honzhang@redhat.com> To: libvir-list@redhat.com Sent: Thursday, October 29, 2015 3:19:29 PM Subject: [libvirt] [libvirt-test-api][PATCH 0/2]Fix issues in the method of getting vcpu thread id of vcpupin_live and cpu_affinity Hongming Zhang (2): Fix the issues in checking method of vcpupin_live Modify the checking method via passing the vcpu thread id repos/domain/cpu_affinity.py | 16 +++++++++------- repos/setVcpus/vcpupin_live.py | 36 ++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 23 deletions(-) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Hongming Zhang
-
Luyao Huang