Signed-off-by: Li Yang <[email protected]>
---
client/tests/libvirt/tests/virsh_managedsave.py | 75 +++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/libvirt/tests/virsh_managedsave.py

diff --git a/client/tests/libvirt/tests/virsh_managedsave.py b/client/tests/libvirt/tests/virsh_managedsave.py
new file mode 100644
index 0000000..01d3977
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_managedsave.py
@@ -0,0 +1,75 @@
+import re, os, logging, shutil
+from autotest.client.shared import  error
+from autotest.client.virt import  libvirt_vm
+
+
+def run_virsh_managedsave(test, params, env):
+    """
+    Test command: virsh managedsave.
+
+    This command can save and destroy a
+    running domain, so it can be restarted
+    from the same state at a later time.
+    """
+
+    vm_name = params.get("main_vm", "vm1")
+    vm = env.get_vm(params["main_vm"])
+
+    #define function
+    def vm_recover_check(guest_name):
+        """
+        Check if the vm can be recovered correctly.
+
+        @param: guest_name : Checked vm's name.
+        """
+        ret = libvirt_vm.virsh_list()
+        #This time vm should not be in the list
+        if re.search(guest_name, ret.stdout):
+            raise error.TestFail("virsh list output invalid")
+        libvirt_vm.virsh_start(guest_name)
+        if params.get("paused_after_start_vm") == "yes":
+           libvirt_vm.virsh_resume(guest_name)
+        #This time vm should be in the list
+        ret = libvirt_vm.virsh_list()
+        if  not re.search(guest_name, ret.stdout):
+            raise error.TestFail("virsh list output invalid")
+
+    domid = libvirt_vm.virsh_domid(vm_name).strip()
+    domuuid = libvirt_vm.virsh_uuid(vm_name).strip()
+
+    libvirtd = params.get("libvirtd","on")
+
+    #run test case
+    vm_ref = params.get("vm_ref")
+    if vm_ref == "id":
+        vm_ref = domid
+    elif vm_ref == "uuid":
+        vm_ref = domuuid
+    elif vm_ref == "hex_id":
+        vm_ref = hex(int(domid))
+    elif vm_ref == "invalid_id" or  vm_ref == "invalid_uuid":
+        vm_ref = params.get(vm_ref)
+    elif vm_ref == "name" or vm_ref == "extra_parame":
+        vm_ref = "%s %s" % (vm_name, params.get("extra_parame"))
+
+    #stop the libvirtd service
+    if libvirtd == "off":
+        libvirt_vm.libvirtd_stop()
+
+    #Ignore exception with "ignore_status=True"
+    ret = libvirt_vm.virsh_managedsave(vm_ref, ignore_status=True)
+    status = ret.exit_status
+
+    #recover libvirtd service start
+    if libvirtd == "off":
+        libvirt_vm.libvirtd_start()
+
+    #check status_error
+    status_error = params.get("status_error")
+    if status_error == "yes":
+        if status == 0:
+            raise error.TestFail("Run successfully with wrong command!")
+    elif status_error == "no":
+        if status != 0:
+            raise error.TestFail("Run failed with right command")
+        vm_recover_check(vm_name)
--
1.7.1


--
Regards,
--------------------------------------------------
Li Yang
TEL:+86+25-86630566-8526
EMail:[email protected]
--------------------------------------------------



_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to