From: Satheesh Rajendran <[email protected]>
Signed-off-by: Satheesh Rajendran <[email protected]> --- client/tests/libvirt/tests/virsh_nodecpustats.py | 170 ++++++++++++++++++++++ 1 files changed, 170 insertions(+), 0 deletions(-) create mode 100644 client/tests/libvirt/tests/virsh_nodecpustats.py diff --git a/client/tests/libvirt/tests/virsh_nodecpustats.py b/client/tests/libvirt/tests/virsh_nodecpustats.py new file mode 100644 index 0000000..0ac131b --- /dev/null +++ b/client/tests/libvirt/tests/virsh_nodecpustats.py @@ -0,0 +1,170 @@ +import logging +from autotest.client.shared import utils, error +from autotest.client.virt import libvirt_vm +from autotest.client import * + +def run_virsh_nodecpustats(test, params, env): + """ + Test the command virsh nodecpustats + + (1) Call the virsh nodecpustats command for all cpu host cpus + separately + (2) Get the output + (3) Check the against /proc/stats output(o) for respective cpu + user: o[0] + o[1] + system: o[2] + o[5] + o[6] + idle: o[3] + iowait: o[4] + (4) Call the virsh nodecpustats command with an unexpected option + (5) Call the virsh nodecpustats command with libvirtd service stop + """ + + # Initialize the variables + deltas = [] + delta_all = [] + name_stats = ['user', 'system', 'idle', 'io_wait'] + itr = int(params.get("itr")) + + def get_cpu_stat(key): + """ + Get load per cpu from /proc/stat + @param _stats: previous values + @return: list of values of CPU times + """ + + stats = [] + stat_file = open('/proc/stat', 'r') + line = stat_file.readline() + while line: + if line.startswith(key): + stats = line.split()[1:] + break + line = stat_file.readline() + return stats + + + def virsh_check_nodecpustats(actual_stats, expected_stats, delta): + """ + Check the acual nodecpustats output value with expected + /proc/stats output and measure the delta of the same and + return + """ + + delta_stats = [] + + for i in range(4): + delta_stats.append(abs(actual_stats[i] - expected_stats[i])) + if delta_stats[i] > delta: + raise error.TestFail("Command 'virsh nodecpustats' not succeeded" + "as the value for %s is deviated by %d" + % (name_stats[i], delta_stats[i])) + return delta_stats + + + # Prepare libvirtd service + check_libvirtd = params.has_key("libvirtd") + if check_libvirtd: + libvirtd = params.get("libvirtd") + if libvirtd == "off": + libvirt_vm.service_libvirtd_control("stop") + + # Get the host cpu count + host_cpu_count = utils.count_cpus() + + # Run test case for 5 iterations (default can be changed in subtests.cfg file) + # and print the final statistics + for i in range(itr): + # Check status_error + status_error = params.get("status_error") + if status_error == "yes": + option = params.get("virsh_cpunodestats_options") + output = libvirt_vm.virsh_nodecpustats(ignore_status=True, extra=option) + expected_stats = output.stdout.strip().split() + status = output.exit_status + if status == 0: + if libvirtd == "off": + raise error.TestFail("Command 'virsh nodecpustats' succeeded " + "with libvirtd service stopped, incorrect") + else: + raise error.TestFail("Command 'virsh nodecpustats %s' succeeded" + "(incorrect command)" % option) + + elif status_error == "no": + for cpu in range(host_cpu_count): + option = "--cpu %d" % cpu + output = libvirt_vm.virsh_nodecpustats(ignore_status=True, extra=option) + expected_stats = output.stdout.strip().split() + status = output.exit_status + + if status == 0: + ex_user = int(expected_stats[1]) / 10000000 + ex_system = int(expected_stats[3]) / 10000000 + ex_idle = int(expected_stats[5]) / 10000000 + ex_iowait = int(expected_stats[7]) / 10000000 + expected = [ex_user, ex_system, ex_idle, ex_iowait] + + key_value = "cpu%d" % cpu + actual_stats = get_cpu_stat(key_value) + at_user = int(actual_stats[0]) + int(actual_stats[1]) + at_system = int(actual_stats[2]) + int(actual_stats[5]) + int(actual_stats[6]) + at_idle = int(actual_stats[3]) + at_iowait = int(actual_stats[4]) + actual = [at_user, at_system, at_idle, at_iowait] + + # Currently the delta value is kept at 10 this can be tuned based on the accuracy + delta = int(params.get("delta")) + output = virsh_check_nodecpustats(actual, expected, delta) + deltas.append(key_value) + deltas.append(output) + else: + raise error.TestFail("Command 'virsh nodecpustats %s' not succeeded" % option) + + option = params.get("virsh_cpunodestats_options") + output = libvirt_vm.virsh_nodecpustats(ignore_status=True, extra=option) + expected_stats = output.stdout.strip().split() + status = output.exit_status + + if status == 0: + ex_user = int(expected_stats[1]) / 10000000 + ex_system = int(expected_stats[3]) / 10000000 + ex_idle = int(expected_stats[5]) / 10000000 + ex_iowait = int(expected_stats[7]) / 10000000 + expected = [ex_user, ex_system, ex_idle, ex_iowait] + + key_value = "cpu " + actual_stats = get_cpu_stat(key_value) + at_user = int(actual_stats[0]) + int(actual_stats[1]) + at_system = int(actual_stats[2]) + int(actual_stats[5]) + int(actual_stats[6]) + at_idle = int(actual_stats[3]) + at_iowait = int(actual_stats[4]) + actual = [at_user, at_system, at_idle, at_iowait] + + # Currently the delta value is kept at 10 this can be tuned based on the accuracy + delta = int(params.get("delta")) + output = virsh_check_nodecpustats(actual, expected, delta) + deltas.append("cpu ") + deltas.append(output) + + else: + raise error.TestFail("Command 'virsh nodecpustats %s' not succeeded" % option) + + delta_all.append(deltas) + deltas = [] + + # Recover libvirtd service start + if libvirtd == "off": + libvirt_vm.service_libvirtd_control("start") + + # The below details are not mandatory for the test + # It is given as additional details + if status_error == "no": + logging.info("The following is the deviations from the actual(/proc/stats)" + " and expected value(output of virsh nodecpustats)") + + for i in range(itr): + logging.info("iteration %d", i+1) + logging.info("cpu %s", name_stats) + temp = 0 + for cpu in range(host_cpu_count + 1): + logging.info("%s: %s", delta_all[i][temp], delta_all[i][temp+1]) + temp = (cpu+1) * 2 -- 1.7.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
