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

diff --git a/libvirt/tests/virsh_domjobabort.py b/libvirt/tests/virsh_domjobabort.py
new file mode 100644
index 0000000..50e1976
--- /dev/null
+++ b/libvirt/tests/virsh_domjobabort.py
@@ -0,0 +1,95 @@
+import os, subprocess
+from autotest.client.shared import error
+from virttest import libvirt_vm, virsh
+
+def run_virsh_domjobabort(test, params, env):
+    """
+    Test command: virsh domjobabort.
+
+    The command can abort the currently running domain job.
+    1.Prepare test environment,destroy or suspend a VM.
+    2.Do action to get a subprocess(dump, save, managedsave).
+    3.Perform virsh domjobabort operation to abort VM's job.
+    4.Recover the VM's status and wait for the subprocess over.
+    5.Confirm the test result.
+    """
+
+    vm_name = params.get("main_vm", "vm1")
+    vm = env.get_vm(vm_name)
+    start_vm = params.get("start_vm")
+    pre_vm_state = params.get("pre_vm_state", "start")
+    if start_vm == "no" and vm.is_alive():
+        vm.destroy()
+
+    # Instead of "paused_after_start_vm", use "pre_vm_state".
+    # After start the VM, wait for some time to make sure the job
+    # can be created on this domain.
+    if start_vm == "yes":
+        vm.wait_for_login()
+        if params.get("pre_vm_state") == "suspend":
+            vm.pause()
+
+    domid = vm.get_id()
+    domuuid = vm.get_uuid()
+
+    def get_subprocess(action, vm_name, file):
+        """
+ Execute background virsh command, return subprocess w/o waiting for exit()
+
+        @param: cmd : virsh command.
+        @param: guest_name : VM's name
+        @param: file_source : virsh command's file option.
+        """
+        if action == "managedsave":
+            file = ""
+        command = "virsh %s %s %s" % (action, vm_name, file)
+        p = subprocess.Popen(command,shell=True, stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+        return p
+
+
+    action = params.get("jobabort_action","dump")
+    status_error = params.get("status_error", "no")
+    job = params.get("jobabort_job", "yes")
+    tmp_file = os.path.join(test.tmpdir, "domjobabort.tmp")
+    vm_ref = params.get("jobabort_vm_ref")
+
+    if action == "restore":
+        virsh.save(vm_name, tmp_file, ignore_status=True)
+
+
+    if vm_ref == "id":
+       vm_ref = domid
+    elif vm_ref == "hex_id":
+       vm_ref = hex(int(domid))
+    elif  vm_ref == "uuid":
+        vm_ref = domuuid
+    elif vm_ref.find("invalid") != -1:
+       vm_ref = params.get(vm_ref)
+    elif vm_ref == "name":
+       vm_ref = vm_name
+
+    # Get the subprocess of VM.
+    # The command's effect is to abort the currently running domain job.
+ # So before do "domjobabort" action, we must create a job on the domain.
+    process = None
+    if job == "yes" and start_vm == "yes":
+        process = get_subprocess(action, vm_name, tmp_file)
+
+    ret = virsh.domjobabort(vm_ref, ignore_status=True)
+    status = ret.exit_status
+
+    # Recover the environment.
+    if pre_vm_state == "suspend":
+        vm.resume()
+    if process:
+        if process.poll():
+            process.kill()
+
+    #check 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")
--
1.7.1



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



_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to