From 81d285889231b1f1ad95d5f227b35303cc50c074 Mon Sep 17 00:00:00 2001 From: Satheesh Rajendran Date: Thu, 10 Jan 2019 12:58:12 +0530 Subject: [PATCH] Add vcpu hotplug validation on domstats output domstats output provides guest vcpu details, this patch adds an method to test it for vcpu hotplug validation. Signed-off-by: Satheesh Rajendran --- virttest/utils_hotplug.py | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/virttest/utils_hotplug.py b/virttest/utils_hotplug.py index 5b5a61d7bc..22094cf13a 100644 --- a/virttest/utils_hotplug.py +++ b/virttest/utils_hotplug.py @@ -424,6 +424,45 @@ def get_cpustats(vm, cpu=None): return cpustats +def get_domstats(vm, key): + """ + Get VM's domstats output value for given keyword + :param vm: VM object + :param key: keyword for which value is needed + :return: value string + """ + domstats_output = virsh.domstats(vm.name) + for item in results_stdout_52lts(domstats_output).strip().split(): + if key in item: + return item.split("=")[1] + + +def check_vcpu_domstats(vm, exp_vcpu): + """ + Check the cpu values from domstats output + :param vm: VM object + :param exp_vcpu: dict of expected vcpus + :return: True if exp_vcpu matches the domstats output, False if not + """ + status = True + cur_vcpu = int(get_domstats(vm, "vcpu.current")) + max_vcpu = int(get_domstats(vm, "vcpu.maximum")) + if vm.is_alive(): + exp_cur_vcpu = exp_vcpu['cur_live'] + else: + exp_cur_vcpu = exp_vcpu['cur_config'] + if exp_cur_vcpu != cur_vcpu: + status = False + logging.error("Mismatch in current vcpu in domstats output, " + "Expected: %s Actual: %s", exp_cur_vcpu, cur_vcpu) + if exp_vcpu['max_config'] != max_vcpu: + status = False + logging.error("Mismatch in maximum vcpu in domstats output, Expected:" + " %s Actual: %s", exp_vcpu['max_config'], max_vcpu) + + return status + + def check_vcpu_value(vm, exp_vcpu, vcpupin=None, option="", guest_agent=False): """ Check domain vcpu, including vcpucount, vcpuinfo, vcpupin, vcpu number and @@ -470,6 +509,9 @@ def check_vcpu_value(vm, exp_vcpu, vcpupin=None, option="", guest_agent=False): # 1.6 Check guest numa if not guest_numa_check(vm, exp_vcpu): final_result = False + # 1.7 Check virsh domstats output + if not check_vcpu_domstats(vm, exp_vcpu): + final_result = False return final_result