Signed-off-by: Yu Mingfei<[email protected]>
---
 client/tests/libvirt/tests/virsh_schedinfo.py |  133 +++++++++++++++++++++++++
 1 files changed, 133 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..196d6bf
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_schedinfo.py
@@ -0,0 +1,133 @@
+import re, logging
+from autotest.client.shared import utils, error
+from autotest.client.virt import virt_remote, libvirt_vm as 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 libvirt's state.
+    2) Run test case according schedinfo's configration.
+    3) Recover libvirt.
+    4) 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.virsh_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 = virt_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
+
+    vm_name = params.get("main_vm", "vm1")
+    vm = env.get_vm(params["main_vm"])
+    domid = virsh.virsh_domid(vm_name).strip()
+    domuuid = virsh.virsh_uuid(vm_name).strip()
+
+    #prepare libvirtd service
+    libvirt = params.get("libvirt", "on")
+    if libvirt == "off":
+        virsh.service_libvirtd_control("stop")
+
+    #run test case
+    vm_ref = params.get("vm_ref", "")
+    schedinfo_vm = params.get("schedinfo_vm", "%s")
+    options_ref = params.get("options_ref", "")
+    options_prefix = params.get("options_prefix", "")
+    options_suffix = params.get("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
+
+    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.virsh_schedinfo(schedinfo_vm, options_ref,
+                              ignore_status=True, print_info=True)
+        status = result.exit_status
+        output = result.stdout.strip()
+
+    #Recover libvirtd
+    if libvirt == "off":
+        virsh.service_libvirtd_control("start")
+
+    #check status_error
+    status_error = params.get("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.")
+
+            result_lines = output.splitlines()
+            scheduler = result_lines[0].split(":")[1].strip()
+            set_ref_value = result_lines[1].split(":")[1].strip()
+            logging.info("Scheduler: %s", scheduler)
+            logging.info("%s: %s", set_ref, set_ref_value)
+
+            if set_ref and value_is_expected == "yes":
+                if set_value != set_ref_value:
+                    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

Reply via email to