Change in vdsm[master]: [WIP] BZ#748386 - qemuConvert test cases

lyarwood at redhat.com lyarwood at redhat.com
Fri Nov 16 17:35:24 UTC 2012


Lee Yarwood has uploaded a new change for review.

Change subject: [WIP] BZ#748386 - qemuConvert test cases
......................................................................

[WIP] BZ#748386 - qemuConvert test cases

Adds some simple qemu-img tests against volume.qemuConvert() to ensure
volumes remain the correct format after being converted.

Change-Id: I1c9f302928c246f7ce195d169f8d5a533df1a344
Signed-off-by: Lee Yarwood <lyarwood at redhat.com>
---
A tests/qemuImgTests.py
A vdsm/storage/fakeVolume.py
2 files changed, 214 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/9290/1

diff --git a/tests/qemuImgTests.py b/tests/qemuImgTests.py
new file mode 100644
index 0000000..e1cc70c
--- /dev/null
+++ b/tests/qemuImgTests.py
@@ -0,0 +1,148 @@
+#
+# Copyright 2012 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from testrunner import VdsmTestCase as TestCase
+
+import tempfile
+import uuid
+import os
+
+
+from storage.threadLocal import vars
+from storage.fakeVolume import FakeFileVolume
+import storage.task as task
+import storage.volume as volume
+import storage.misc as misc
+
+EXT_QEMUIMG = '/bin/qemu-img'
+EXT_DD = '/bin/dd'
+VOL_SIZE = "10M"
+VOL_ALLOC = "20"
+
+class FileVolumes():
+
+    def __init__(self):
+        self.dir = tempfile.mkdtemp()
+        self.sduuid = str(uuid.uuid4())
+        self.imguuid = str(uuid.uuid4())
+        self.repo = self.dir + "/" + self.sduuid + "/images/" + self.imguuid
+        os.makedirs(self.repo)
+
+    def genPathUUID(self):
+        u = str(uuid.uuid4())
+        p = self.repo + "/" + u
+        return p, u
+
+
+    def createCOW(self):
+        path, voluuid = self.genPathUUID()
+        misc.execCmd([EXT_QEMUIMG, "create", "-f", "qcow2", path, VOL_SIZE],sync=False)
+        return FakeFileVolume(repoPath=self.dir, sdUUID=self.sduuid, imgUUID=self.imguuid, volUUID=voluuid,
+                          volFormat=volume.COW_FORMAT, volPath=path)
+
+    def createRAW(self):
+        path, voluuid = self.genPathUUID()
+        misc.execCmd([EXT_QEMUIMG, "create", "-f", "raw", path, VOL_SIZE],sync=False)
+        return FakeFileVolume(repoPath=self.dir, sdUUID=self.sduuid, imgUUID=self.imguuid, volUUID=voluuid,
+                          volFormat=volume.RAW_FORMAT, volPath=path)
+
+    def createCOWPrealloc(self):
+        v = self.createCOW()
+        misc.execCmd([EXT_DD, "if=/dev/zero", "of=%s" % v.getVolumePath(), "bs=512"])
+        return v
+
+
+    def createCOWChild(self,parent):
+        path, voluuid = self.genPathUUID()
+        misc.execCmd([EXT_QEMUIMG, "create", "-f", "qcow2", "-o", "backing_file=%s/%s,backing_fmt=raw" %
+                    (self.repo,parent.volUUID), self.repo + "/" + voluuid, VOL_SIZE],sync=False)
+        fake = FakeFileVolume(repoPath=self.dir, sdUUID=self.sduuid, imgUUID=self.imguuid, volUUID=voluuid,
+                        volFormat=volume.COW_FORMAT, volPath=path)
+        # Hack to avoid a call to sdc.produce() later when we try to find the parent.
+        fake.setParent(parent.volUUID)
+        fake.setParentVolume(parent)
+        return fake
+
+    def cleanUp(self):
+        os.rmdir(self.dir)
+
+
+class qemuImgRebaseTestCase(TestCase):
+    """
+
+    """
+
+class qemuImgCreateTestCase(TestCase):
+    """
+
+    """
+
+class qemuImgConvertTestCase(TestCase):
+
+
+    def runQemuConvert(self, src, dst):
+
+        vars.task = task.Task(id=None, name='qemuImgTests')
+        try:
+            (rc, out, err) = volume.qemuConvert(src, dst, vars.task.aborting)
+            self.assertFalse(rc)
+        except Exception:
+             self.fail()
+
+
+    def testFileQemuConvert(self):
+        # create the repo
+        t = FileVolumes()
+
+        # RAW to RAW
+        src = t.createRAW()
+        dst = t.createRAW()
+        self.runQemuConvert(src, dst)
+
+        # QCOW2 to RAW
+        #src = t.createCOW()
+        #dst = t.createRAW()
+        #self.runQemuConvert(src, dst)
+
+        # RAW to QCOW2
+        #src = t.createRAW()
+        #dst = t.createCOW()
+        #self.runQemuConvert(src, dst)
+
+        # RAW<-QCOW2 to RAW<-QCOW2
+        parent = t.createRAW()
+        src = t.createCOWChild(parent)
+        dst = t.createCOW()
+        self.runQemuConvert(src, dst)
+
+        # Convert a COW parent child to another COW
+        # RAW<-QCOW2<-QCOW2 to RAW<-QCOW2<-QCOW2
+        rawParent = t.createRAW()
+        src = t.createCOWChild(rawParent)
+        cowChild = t.createCOWChild(src)
+        dst = t.createCOW()
+        self.runQemuConvert(src,dst)
+
+
+
+
+    def testBlockQemuConvert(self):
+        pass
+
diff --git a/vdsm/storage/fakeVolume.py b/vdsm/storage/fakeVolume.py
new file mode 100644
index 0000000..72516b7
--- /dev/null
+++ b/vdsm/storage/fakeVolume.py
@@ -0,0 +1,66 @@
+#
+# Copyright 2012 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import volume
+import misc
+
+class FakeFileVolume(volume.Volume):
+    """
+    A fake file volume class to aid with testing.
+    """
+
+    def __init__(self, repoPath, sdUUID, imgUUID, volUUID, volFormat, volPath):
+        volume.Volume.__init__(self, repoPath, sdUUID, imgUUID, volUUID)
+
+        self.md = {"SIZE": None,"TYPE":None,"FORMAT":None,"DISKTYPE":None,"VOLTYPE":None,
+                   "PUUID":None,"DOMAIN":None,"CTIME":None,"IMAGE":None,"DESCRIPTION":None,
+                   "LEGALITY":None,"MTIME":None,"ILLEGAL":None,"LEGAL":None,"FAKE":None}
+
+        self.setFormat(volFormat)
+        self.setVolumePath(volPath)
+        self.parentVolume = None
+
+    def validateImagePath(self):
+        pass
+
+    def validateVolumePath(self):
+        pass
+
+    def setVolumePath(self,volPath):
+        self.volumePath = volPath
+
+    def setParent(self, puuid):
+        self.setMetaParam(volume.PUUID, puuid)
+
+    def getParent(self):
+        return self.getMetaParam(volume.PUUID)
+
+    def setParentVolume(self,parent):
+        self.parentVolume = parent
+
+    def getParentVolume(self):
+        return self.parentVolume
+
+    def setMetadata(self,  m, mid=None):
+        for k,v in m.iteritems():
+            self.md[k] = v
+
+    def getMetadata(self):
+        return self.md


--
To view, visit http://gerrit.ovirt.org/9290
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c9f302928c246f7ce195d169f8d5a533df1a344
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Lee Yarwood <lyarwood at redhat.com>


More information about the vdsm-patches mailing list