qemu_img testing is used frequently, add them
to kvm_vm.py and kvm_preprocessing.py

example:

- snapshot:
    snapshot_name = snapshot1
    snapshot_format = qcow2
    variants:
        - snapshot:
            create_snapshot = yes
        - commit:
            commit_image = yes
            images = "snapshot"
            image_name_snapshot = snapshot1
            image_format_snapshot = qcow2

Signed-off-by: Suqin Huang <[email protected]>
---
 client/tests/kvm/kvm_preprocessing.py |    9 +++++++++
 client/tests/kvm/kvm_vm.py            |   30 ++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_preprocessing.py 
b/client/tests/kvm/kvm_preprocessing.py
index bc80713..12b47c0 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -84,6 +84,15 @@ def preprocess_vm(test, params, env, name):
     if rebase_image and not kvm_vm.rebase_image(params, test.bindir):
         raise error.TestFail("Could not rebase snapshot to base image")
 
+    # Commit vm
+    commit_image = Fale
+
+    if params.get("commit_image") == "yes":
+        logging.debug("Commit snapshot to backing image...")
+        commit_image = True
+    if commit_image and not kvm_vm.commit_image(params, test.bindir):
+        raise error.TestFail("Could not commmit snapshot to backing image")
+
     # Start vm
     start_vm = False
 
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 6727a6d..ffbfc87 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -335,6 +335,36 @@ def rebase_image(params, root_dir):
     return base_filename
 
 
+def commit_image(params, root_dir):
+    """
+    Commit snapshot to base file
+
+    @param params: A dict
+    @param root_dir: Base directory for relative filenames.
+
+    @note: params should contain:
+           image_name -- the name of the snapshot
+           image_format -- the format of the snapshot
+    """
+    qemu_img_cmd = kvm_utils.get_path(root_dir, params.get("qemu_img_binary",
+                                                            "qemu-img"))
+    qemu_img_cmd += " commit"
+    image_format = params.get("image_format", "qcow2")
+    image_filename = get_image_filename(params, root_dir)
+
+    qemu_img_cmd += " -f %s %s" % (image_format, image_filename)
+
+    try:
+        utils.system(qemu_img_cmd)
+    except error.CmdError, e:
+        logging.error("Commit image failed\n%s", str(e))
+        return None
+
+    logging.info("Image commit to backing file")
+
+    return image_filename
+
+
 def remove_image(params, root_dir):
     """
     Remove an image file.

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to