Ala Hino has uploaded a new change for review.

Change subject: [WIP] core: Expose API for qemu-img commit
......................................................................

[WIP] core: Expose API for qemu-img commit

Change-Id: If7a13be40541fb268541bd8614a642263b96b487
Signed-off-by: Ala Hino <ah...@redhat.com>
---
M lib/vdsm/qemuimg.py
M tests/qemuimg_test.py
2 files changed, 35 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/22/64222/1

diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 61ebec3..4ad7073 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -185,6 +185,16 @@
     return QemuImgOperation(cmd, cwd=cwdPath)
 
 
+def commit(top, base=None):
+    cmd = [_qemuimg.cmd, "commit", "-p"]
+    if base:
+        cmd.extend(("-b", base))
+    else:
+        cmd.append("-d")
+
+    return QemuImgOperation(cmd)
+
+
 class QemuImgOperation(object):
     REGEXPR = re.compile(r'\s*\(([\d.]+)/100%\)\s*')
 
diff --git a/tests/qemuimg_test.py b/tests/qemuimg_test.py
index d7d9fab..3fd97ea 100644
--- a/tests/qemuimg_test.py
+++ b/tests/qemuimg_test.py
@@ -23,6 +23,7 @@
 from functools import partial
 
 from monkeypatch import MonkeyPatch, MonkeyPatchScope
+from storagetestlib import qemu_pattern_write, qemu_pattern_verify
 from testlib import VdsmTestCase as TestCaseBase
 from testlib import permutations, expandPermutations
 from testlib import make_config
@@ -329,3 +330,27 @@
 
         p.poll()
         self.assertEquals(p.finished, True)
+
+class TestCommit(TestCaseBase):
+
+    @MonkeyPatch(qemuimg, 'config', CONFIG)
+    def test_commit(self):
+        with namedTemporaryDir() as tmpdir:
+            base = os.path.join(tmpdir, 'base.img')
+            top = os.path.join(tmpdir, 'top.img')
+            size = 1048576
+            qemuimg.create(base, size=size, format=qemuimg.FORMAT.RAW)
+            qemu_pattern_write(base, qemuimg.FORMAT.RAW, '0', 0xf0)
+
+            qemuimg.create(top, format=qemuimg.FORMAT.QCOW2, backing=base)
+            qemu_pattern_write(top, qemuimg.FORMAT.QCOW2, '1024', 0xf1)
+
+            op = qemuimg.commit(top=top)
+            op.wait_for_completion()
+
+            # top should not change after commit
+            qemu_pattern_verify(top, qemuimg.FORMAT.RAW, '0', 0xf1)
+
+            # base now should include original data and top's data
+            qemu_pattern_verify(base, qemuimg.FORMAT.RAW, '0', 0xf0)
+            qemu_pattern_verify(base, qemuimg.FORMAT.RAW, '1024', 0xf1)


-- 
To view, visit https://gerrit.ovirt.org/64222
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If7a13be40541fb268541bd8614a642263b96b487
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ala Hino <ah...@redhat.com>
_______________________________________________
vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org
To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org

Reply via email to