Skip to content

Commit

Permalink
Merge pull request #1905 from sathnaga/domstats_vcpu_check
Browse files Browse the repository at this point in the history
Add vcpu hotplug validation on domstats output
  • Loading branch information
Satheesh Rajendran authored Jan 28, 2019
2 parents b03a35e + 81d2858 commit f31b634
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions virttest/utils_hotplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f31b634

Please sign in to comment.