Prem has committed a patch for geting cgroup controller mount points from /etc/cgconfig.conf, and it should be shared with other apps, I expect Prem's v2 patch for this:
https://www.redhat.com/archives/autotest-kernel/2012-September/msg00036.html BTW, you CC a error autotest-kernel mail address, please remove useless 'u' from '[email protected]'. -- Regards, Alex ----- Original Message ----- From: "Yu Mingfei" <[email protected]> To: "Chris Evich" <[email protected]> Cc: [email protected], "Alex Jia" <[email protected]>, "Lucas Meneghel Rodrigues" <[email protected]> Sent: Thursday, September 6, 2012 5:51:11 PM Subject: [PATCH 3/3 v2] client/tests/libvirt: add testcases for virsh schedinfo test. Signed-off-by: Yu Mingfei<[email protected]> --- client/tests/libvirt/tests/virsh_schedinfo.py | 187 +++++++++++++++++++++++++ 1 files changed, 187 insertions(+), 0 deletions(-) create mode 100644 client/tests/libvirt/tests/virsh_schedinfo.py diff --git a/client/tests/libvirt/tests/virsh_schedinfo.py b/client/tests/libvirt/tests/virsh_schedinfo.py new file mode 100644 index 0000000..f248126 --- /dev/null +++ b/client/tests/libvirt/tests/virsh_schedinfo.py @@ -0,0 +1,187 @@ +import re, logging +from autotest.client.shared import utils, error +from autotest.client.virt import libvirt_vm, remote, virsh + + +def run_virsh_schedinfo(test, params, env): + """ + Test command: virsh schedinfo. + + This version provide base test of virsh schedinfo command: + virsh schedinfo<vm> [--set<set_ref>] + TODO:to support more parameters... + + 1) Prepare vm test environment. + 2) Prepare test options. + 3) Prepare libvirt status. + 4) Run testcase. + 5) Recover libvirt status. + 6) Check result. + """ + def schedinfo_local_on_remote_host(schedinfo_vm, options_ref, + remote_host_ip, remote_host_passwd, + local_host_ip): + """ + Execute virsh schedinfo on remote host, and get local schedinfo. + + @param schedinfo_vm: the vm to get schedinfo. + @param options_ref: the options of virsh schedinfo<vm>. + @param remote_host_ip: remote host's ip. + @param remote_host_passwd: remote host's password. + @param local_host_ip: local host's ip. + """ + host_uri = virsh.canonical_uri() + if host_uri == "qemu:///system": + cmd = "virsh -c qemu+ssh://%s/system schedinfo %s %s" \ + % (local_host_ip, schedinfo_vm, options_ref) + elif host_uri == "xen:///": + cmd = "virsh -c xen+ssh://%s/ schedinfo %s %s" \ + % (local_host_ip, schedinfo_vm, options_ref) + session = remote.remote_login("ssh", remote_host_ip, "22", + "root", remote_host_passwd, "#") + status, output = session.cmd_status_output(cmd, internal_timeout=5) + session.close() + return int(status), output + + + def get_cgroup_controller_mount(controller="cpu"): + """ + Get controller's mounted path. + + @return: False if expected controller is not mounted. + else return mounted path. + """ + cmd = "cat /proc/mounts | awk {'print $2'} | grep cgroup" + ctl_mounts = utils.run(cmd, ignore_status=True).stdout.strip() + ctl_mount = re.findall(r"/cgroup/%s[^a-z]" % controller, ctl_mounts) + if ctl_mount: + return ctl_mount[0].strip() + else: + return False + + + def get_parameter_of_vm_in_cgroup(domname, controller="cpu", + parameter="cpu.shares", + libvirt_cgroup_path="/libvirt/qemu/"): + """ + Get vm's cgroup value. + + @Param domname: vm's name + @Param controller: the controller which parameter is in. + @Param parameter: the cgroup parameter of vm which we need to get. + @Param libvirt_cgroup_path: the path of libvirt in cgroup + @return: False if expected controller is not mounted. + else return value's result object. + """ + ctl_mount = get_cgroup_controller_mount(controller) + if ctl_mount is not False: + get_value_cmd = "cat %s/%s/%s/%s" % (ctl_mount, + libvirt_cgroup_path, domname, parameter) + result = utils.run(get_value_cmd, ignore_status=True) + return result + else: + return False + + + #Prepare vm test environment + vm_name = params.get("main_vm", "vm1") + vm = env.get_vm(params["main_vm"]) + domid = virsh.domid(vm_name).strip() + domuuid = virsh.domuuid(vm_name).strip() + + #Prepare test options + vm_ref = params.get("schedinfo_vm_ref", "") + schedinfo_vm = params.get("schedinfo_vm", "%s") + options_ref = params.get("schedinfo_options_ref", "") + options_prefix = params.get("schedinfo_options_prefix", "") + options_suffix = params.get("schedinfo_options_suffix", "") + + if vm_ref == "domid": + if domid == "-": + vm_ref = domid + else: + vm_ref = int(domid) + elif vm_ref == "domname": + vm_ref = vm_name + elif vm_ref == "domuuid": + vm_ref = domuuid + + schedinfo_vm = (schedinfo_vm % vm_ref) + + set_ref = params.get("set_ref", "") + set_value = params.get("set_value", "") + if set_ref: + if set_value: + options_ref = "--set %s=%s" % (set_ref, set_value) + else: + options_ref = "--set" + options_ref = options_prefix + options_ref + options_suffix + + #prepare libvirtd status + libvirt = params.get("schedinfo_libvirt", "on") + if libvirt == "off": + libvirt_vm.service_libvirtd_control("stop") + + #Run testcase + remote_ref = params.get("remote_ref", "") + if remote_ref == "remote": + remote_host_ip = params.get("remote_host_ip", "127.0.0.1") + local_host_ip = params.get("local_host_ip", "127.0.0.1") + remote_host_passwd = params.get("remote_host_passwd", "") + status, output = schedinfo_local_on_remote_host(schedinfo_vm, + options_ref, remote_host_ip, remote_host_passwd, + local_host_ip) + logging.info("Status:%s", status) + logging.info("Output:\n%s", output) + else: + result = virsh.schedinfo(schedinfo_vm, options_ref, + ignore_status=True, debug=True) + status = result.exit_status + output = result.stdout.strip() + + #Recover libvirtd status + if libvirt == "off": + libvirt_vm.service_libvirtd_control("start") + + #Check result + status_error = params.get("schedinfo_status_error", "no") + addition_status_error = params.get("addition_status_error", "no") + status_error = (status_error == "no") and (addition_status_error == "no") + value_is_expected = params.get("value_is_expected", "yes") + scheduler_value = params.get("scheduler_value", "posix") + if status_error: + if status != 0: + raise error.TestFail("Run failed with right command.") + else: + if (not re.search("Scheduler", output)) \ + or (not re.search(set_ref, output)): + raise error.TestFail("Run failed with right command.") + + #Get Scheduler value and set value + result_lines = output.strip().splitlines() + scheduler = "" + set_ref_value = "" + for line in result_lines: + key_value = line.split(":") + key = key_value[0].strip() + value = key_value[1].strip() + if key == "Scheduler": + scheduler = value + elif key == set_ref: + set_ref_value = value + cgroup_value_of_set = get_parameter_of_vm_in_cgroup(vm_name) + + if set_ref and value_is_expected == "yes": + if set_value != set_ref_value: + raise error.TestFail("Run successful but result is not expected.") + if set_value != cgroup_value_of_set.stdout.strip(): + raise error.TestFail("Run successful but result is not expected.") + elif set_ref and value_is_expected == "no": + if set_value == set_ref_value: + raise error.TestFail("Run successful but result is not expected.") + elif set_ref == "" and params.get("start_vm") == "yes": + if scheduler != scheduler_value: + raise error.TestFail("Test Scheduler type is wrong.") + else: + if status == 0: + raise error.TestFail("Run successfully with wrong command!") -- 1.7.1 -- Best Regards Yu Mingfei _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
