This patch adds test for virsh list command.
Signed-off-by: Yu Mingfei <[email protected]>
---
client/tests/libvirt/tests/virsh_list.py | 130 ++++++++++++++++++++++++++++++
1 files changed, 130 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..28aad50
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_list.py
@@ -0,0 +1,130 @@
+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.
+
+ 1) Prepare domain's exist state:transient,managed-save.
+ 2) Prepare libvirt's status.
+ 3) Execute list command.
+ 4) Result check.
+ """
+ def list_local_domains_on_remote(options_ref, remote_ip, remote_passwd,
local_ip):
+ """
+ Create a virsh list command and execute it on remote host.
+ It will list local domains on remote host.
+
+ @param options_ref:options in virsh list command.
+ @param remote_ip:remote host's ip.
+ @param remote_passwd:remote host's password.
+ @param local_ip:local ip, to create uri in virsh list.
+ @return:return status and output of the virsh list command.
+ """
+ command_on_remote = "virsh -c qemu+ssh://%s/system list %s" %
(local_ip, options_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)
+
+ options_ref = params.get("options_ref", "")
+ list_ref = params.get("list_ref", "table")
+ vm_ref = params.get("vm_ref", "")
+ status_error = params.get("status_error", "no")
+ addition_status_error = params.get("addition_status_error", "no")
+ domuuid = vm.get_uuid().strip()
+ # If a transient domain is destroyed, it will disappear.
+ if vm_ref == "transient" and options_ref == "inactive":
+ logging.info("Set addition_status_error to yes")
+ logging.info("because transient domain will disappear after
destroyed.")
+ addition_status_error = "yes"
+
+ if vm_ref == "transient":
+ tmp_xml = vm.backup_xml()
+ vm.undefine()
+ elif vm_ref == "managed-save":
+ libvirt_vm.virsh_managedsave(vm_name, ignore_status=True,
print_info=True)
+
+ #Prepare libvirtd status
+ libvirtd = params.get("libvirtd", "on")
+ if libvirtd == "off":
+ libvirt_vm.service_libvirtd_control("stop")
+
+ #run test case
+ if list_ref == "uuid":
+ result_expected = domuuid
+ logging.info("%s's uuid is: %s", vm_name, domuuid)
+ else:
+ result_expected = vm_name
+ logging.info("domain's name is: %s", vm_name)
+
+ if options_ref == "vm_id":
+ domid = vm.get_id().strip()
+ logging.info("%s's running-id is: %s", vm_name, domid)
+ options_ref = "%s --%s" % (domid, list_ref)
+ elif options_ref == "vm_uuid":
+ logging.info("%s's uuid is: %s", vm_name, domuuid)
+ options_ref = "%s --%s" % (domuuid, list_ref)
+ elif options_ref == "inactive":
+ vm.destroy()
+ options_ref = "--inactive --%s" % list_ref
+ elif options_ref == "vm_name":
+ options_ref = "%s --%s" % (vm_name, list_ref)
+ elif options_ref == "all":
+ options_ref = "--all --%s" % list_ref
+ elif options_ref == "":
+ options_ref = "--%s" % list_ref
+
+ 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_domains_on_remote(options_ref, remote_ip,
remote_passwd, local_ip)
+ logging.info("Status:%s", status)
+ logging.info("Output:\n%s", output)
+ else:
+ if vm_ref:
+ options_ref = "%s --%s" % (options_ref, vm_ref)
+ result = libvirt_vm.virsh_list(options_ref, ignore_status=True,
print_info=True)
+ status = result.exit_status
+ output = result.stdout.strip()
+
+ #Recover libvirtd service status
+ if libvirtd == "off":
+ libvirt_vm.service_libvirtd_control("start")
+
+ #Recover of domain
+ if vm_ref == "transient":
+ vm.define(tmp_xml)
+ elif vm_ref == "managed-save":
+ utils.run("rm -f /var/lib/libvirt/qemu/save/%s.save" % vm_name,
ignore_status=True)
+
+ #Check result
+ status_error = (status_error == "no") and (addition_status_error == "no")
+ if vm_ref == "managed-save":
+ saved_output = re.search(vm_name+" +saved", output)
+ if saved_output:
+ output = saved_output.group(0)
+ else:
+ output = ""
+
+ if not status_error:
+ if status == 0 and re.search(result_expected, output):
+ raise error.TestFail("Run successful with wrong command!")
+ else:
+ if status != 0:
+ raise error.TestFail("Run failed with right command.")
+ if not re.search(result_expected, output):
+ raise error.TestFail("Run successful but result is not expected.")
--
1.7.1
--
Best Regards
Yu Mingfei
_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel