This patch adds testcases to file client/tests/libvirt/tests/virsh_list.py.

Signed-off-by: Yu Mingfei <yuming...@cn.fujitsu.com>
---
  client/tests/libvirt/tests/virsh_list.py |  100 ++++++++++++++++++++++++++++++
  1 files changed, 100 insertions(+), 0 deletions(-)
  create mode 100644 client/tests/libvirt/tests/virsh_list.py

diff --git a/client/tests/libvirt/tests/virsh_list.py 
b/client/tests/libvirt/tests/virsh_list.py
new file mode 100644
index 0000000..4489e7c
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_list.py
@@ -0,0 +1,100 @@
+import re, logging, time, commands
+from autotest.client.shared import utils, error
+from autotest.client.virt import virt_remote, libvirt_vm
+
+
+def run_virsh_list(test, params, env):
+    """
+    Test command: virsh list.
+
+    There are 17 testcases according subtest.cfg:
+    1) local test with parameter "--inactive"
+    2) local test with parameter "--all"
+    3) local test with parameter ""
+    4) local test with parameter "xyz"
+    5) local test with parameter domid
+    6) local test with parameter domname
+    7) local test with parameter domuuid
+    8) virsh to local on remote host with parameter "--inactive"
+    9) virsh to local on remote host with parameter "--all"
+    10) virsh to local on remote host with parameter ""
+    11) virsh to local on remote host with parameter "xyz"
+    12) virsh to local on remote host with parameter domid
+    13) virsh to local on remote host with parameter domname
+    14) virsh to local on remote host with parameter domuuid
+    15) local test with parameter "--inactive" when libvirtd off
+    16) local test with parameter "--all" when libvirtd off
+    17) local test with parameter "" when libvirtd off
+    """
+    def list_local_on_remote(parameter_ref, remote_ip, remote_passwd, 
local_ip):
+        command_on_remote = "virsh -c qemu+ssh://%s/system list %s" % 
(local_ip, parameter_ref)
+        session = virt_remote.remote_login("ssh", remote_ip, "22", "root", 
remote_passwd, "#")
+        time.sleep(5)
+        status, output = session.cmd_status_output(command_on_remote, 
internal_timeout=5)
+        time.sleep(5)
+        session.close()
+        return int(status), output
+
+    vm_name = params.get("main_vm", "vm1")
+    vm = env.get_vm(params["main_vm"])
+    if not vm.is_alive():
+        vm.start()
+    time.sleep(5)
+
+    #Prepare libvirtd status
+    libvirtd = params.get("libvirtd", "on")
+    if libvirtd == "off":
+        libvirt_vm.service_libvirtd_control("stop")
+
+    #run test case
+    parameter_ref = params.get("parameter_ref", "")
+    if parameter_ref == "id":
+        domid = vm.get_id().strip()
+        logging.info("%s's running-id is: %s", vm_name, domid)
+        parameter_ref = domid
+    elif parameter_ref == "uuid":
+        domuuid = vm.get_uuid().strip()
+        logging.info("%s's uuid is: %s", vm_name, domuuid)
+        parameter_ref = domuuid
+    elif parameter_ref == "inactive":
+        vm.destroy()
+        parameter_ref = "--inactive"
+    elif parameter_ref == "name":
+        parameter_ref = vm_name
+    elif parameter_ref == "all":
+        parameter_ref = "--all"
+
+    remote_ref = params.get("remote_ref", "local")
+    if remote_ref == "remote":
+        remote_ip = params.get("remote_ip", "none")
+        remote_passwd = params.get("remote_passwd", "none")
+        local_ip = params.get("local_ip", "none")
+        logging.info("Execute virsh command on remote host %s.", remote_ip)
+        status, output = list_local_on_remote(parameter_ref, remote_ip, 
remote_passwd, local_ip)
+        logging.info("Status:%s", status)
+        logging.info("Output:\n%s", output)
+    else:
+        result = libvirt_vm.virsh_list(parameter_ref, ignore_status=True)
+        status = result.exit_status
+        output = result.stdout.strip()
+        logging.info("Status:%s", status)
+        logging.info("Output:\n%s", output)
+        if status:
+            logging.info("Error:\n%s", result.stderr.strip())
+
+    #Recover libvirtd service status
+    if libvirtd == "off":
+        libvirt_vm.service_libvirtd_control("start")
+
+    #Check result
+    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")
+    if not status_error:
+        if status == 0 and parameter_ref != "":
+            raise error.TestFail("Run successful with wrong command!")
+    else:
+        if status != 0:
+            raise error.TestFail("Run failed with right command.")
+        if not re.search(vm_name, output):
+            raise error.TestFail("Run successful but result is not expected.")
-- 
1.7.1

-- 
Best Regards
Yu Mingfei

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to