def check_vcpupin(vm_name, vcpu, cpu_list, pid, vcpu_pid): """ This function checks the actual and the expected affinity of given vcpu and raises error if not matchs :param vm_name: VM Name to operate on :param vcpu: vcpu number for which the affinity is required :param cpu: cpu details for the affinity :param pid: VM pid :param vcpu: VM cpu pid """ total_cpu = process.run( "ls -d /sys/devices/system/cpu/cpu[0-9]* |wc -l", shell=True).stdout_text.strip() logging.debug("Debug: cpulist %s", cpu_list) expected_output = cpu.cpus_string_to_affinity_list( cpu_list, int(total_cpu)) logging.debug("Expected affinity: %s", expected_output) # Check for affinity value from vcpuinfo output actual_output = affinity_from_vcpuinfo(vm_name, vcpu) logging.debug("Actual affinity in vcpuinfo output: %s", actual_output) if expected_output == actual_output: logging.info("successfully pinned cpu_list: %s --> vcpu: %s", cpu_list, vcpu) else: test.fail("Cpu pinning details not updated properly in" " virsh vcpuinfo command output") # Check for affinity value from vcpupin output actual_output_vcpupin = affinity_from_vcpupin(vm_name, vcpu) logging.debug("Actual affinity in vcpupin output: %s", actual_output_vcpupin) if expected_output == actual_output_vcpupin: logging.info("successfully pinned cpu_list: %s --> vcpu: %s", cpu_list, vcpu) else: test.fail("Cpu pinning details not updated properly in" " virsh vcpupin command output") if pid is None: return # Get the actual cpu affinity value in the proc entry output = utils_test.libvirt.cpu_allowed_list_by_task(pid, vcpu_pid) actual_output_proc = cpu.cpus_string_to_affinity_list( output, int(total_cpu)) logging.debug("Actual affinity in guest proc: %s", actual_output_proc) if expected_output == actual_output_proc: logging.info( "successfully pinned vcpu: %s --> cpu: %s" " in respective proc entry", vcpu, cpu_list) else: test.fail("Cpu pinning details are not " "updated properly in /proc/" "%s/task/%s/status" % (pid, vcpu_pid))
def check_vcpu_affinity(): """ check vcpu affinity defined by vcpu cpuset or cputune cpuset """ affinity = vcpu_cpuset if not cputune_cpuset else cputune_cpuset affinity = {vcpu: affinity} virsh.vcpuinfo(vm_name, debug=True) host_cpu_count = cpuutil.total_cpus_count() vmxml_live = vm_xml.VMXML.new_from_dumpxml(vm_name) logging.debug(vmxml_live) # if vcpu >= maxvcpu, the cputune should not exist in xml if int(vcpu) >= int(maxvcpu): try: if hasattr(vmxml_live, 'cputune'): test.fail("cputune tag is set when vcpu >= maxvcpu") except xcepts.LibvirtXMLError: pass elif "config" in vcpupin_option: vcpu_affinity = cpu.affinity_from_vcpupin(vm, vcpu, vcpupin_option) affinity = cpu.cpus_string_to_affinity_list( str(affinity[vcpu]), host_cpu_count) logging.debug("vcpu_affinity {}".format(vcpu_affinity)) logging.debug("affinity {}".format(affinity)) if vcpu_affinity[int(vcpu)] != affinity: test.fail("vcpu affinity check fail") # check the expected vcpu affinity with the one got from running vm elif not cpu.check_affinity(vm, affinity): test.fail("vcpu affinity check fail")
def affinity_from_vcpupin(vm_name, vcpu): """ This function returns list of vcpu's affinity from vcpupin output :param vm_name: VM Name :param vcpu: VM cpu pid :return : list of affinity to vcpus """ total_cpu = process.run("ls -d /sys/devices/system/cpu/cpu[0-9]* |wc -l", shell=True).stdout_text.strip() vcpus_affinity = {} output = virsh.vcpupin(vm_name).stdout for item in output.split('\n')[2:-2]: item = item.strip() split_key = ' ' if ':' in item: split_key = ':' vcpus_affinity[item.split(split_key)[0].strip()] = item.split(split_key)[-1].strip() return cpu.cpus_string_to_affinity_list( vcpus_affinity[str(vcpu)], int(total_cpu))