Change in vdsm[master]: ImageManifest: introduce ImageManifest class

alitke at redhat.com alitke at redhat.com
Mon Jul 13 19:45:55 UTC 2015


Adam Litke has uploaded a new change for review.

Change subject: ImageManifest: introduce ImageManifest class
......................................................................

ImageManifest: introduce ImageManifest class

In order to safely share storage code between the traditional SPM verbs
and the new SDM verbs we must refactor the code from the Image class.
We want to share the parts which deal with image "metadata" (ie. the
repoPath and imageDir, volumeChain, etc).  These elements will be moved
into a new ImageManifest class while the SPM operations will remain in
the Image class.

As a first step, create the new class and add repoPath and getImageDir.
Many of the other candidate functions rely on the VolumeMetadata
refactoring and will be added later.

Change-Id: Ic7a78aef10902b9baf6f88d2e053e2232e2a1267
Signed-off-by: Adam Litke <alitke at redhat.com>
---
A tests/image_manifest_tests.py
M tests/manifest_tests.py
M vdsm/storage/image.py
3 files changed, 53 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/51/43551/1

diff --git a/tests/image_manifest_tests.py b/tests/image_manifest_tests.py
new file mode 100644
index 0000000..a2ac1c0
--- /dev/null
+++ b/tests/image_manifest_tests.py
@@ -0,0 +1,35 @@
+# Copyright 2015 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 uuid
+import os
+
+from testlib import VdsmTestCase, namedTemporaryDir
+
+from storage import sd, image
+
+
+class ImageManifestTests(VdsmTestCase):
+    def test_getimagedir(self):
+        with namedTemporaryDir() as tmpdir:
+            sduuid = str(uuid.uuid4())
+            imguuid = str(uuid.uuid4())
+            manifest = image.ImageManifest(tmpdir)
+            expected = os.path.join(tmpdir, sduuid, sd.DOMAIN_IMAGES, imguuid)
+            self.assertEquals(expected, manifest.getImageDir(sduuid, imguuid))
diff --git a/tests/manifest_tests.py b/tests/manifest_tests.py
index 2051fb0..a22d7cf 100644
--- a/tests/manifest_tests.py
+++ b/tests/manifest_tests.py
@@ -580,7 +580,7 @@
                 manifest = make_blocksd_manifest()
                 make_vg(lvm, manifest)
                 lvs = get_uuid_list(2)
-                for lv, offset in zip(lvs, [4,7]):
+                for lv, offset in zip(lvs, [4, 7]):
                     lvm.createLV(manifest.sdUUID, lv, VOLSIZE)
                     tag = blockVolume.TAG_PREFIX_MD + str(offset)
                     lvm.addtag(manifest.sdUUID, lv, tag)
diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index 791b48c..81b2043 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -87,6 +87,17 @@
         dom.deleteImage(dom.sdUUID, imgUUID, imgVols)
 
 
+class ImageManifest(object):
+    def __init__(self, repoPath):
+        self.repoPath = repoPath
+
+    def getImageDir(self, sdUUID, imgUUID):
+        """
+        Return image directory
+        """
+        return os.path.join(self.repoPath, sdUUID, sd.DOMAIN_IMAGES, imgUUID)
+
+
 class Image:
     """ Actually represents a whole virtual disk.
         Consist from chain of volumes.
@@ -108,7 +119,11 @@
                               "folder %s" % (imageDir))
 
     def __init__(self, repoPath):
-        self.repoPath = repoPath
+        self.manifest = ImageManifest(repoPath)
+
+    @property
+    def repoPath(self):
+        return self.manifest.repoPath
 
     def create(self, sdUUID, imgUUID):
         """Create placeholder for image's volumes
@@ -128,10 +143,7 @@
         return imageDir
 
     def getImageDir(self, sdUUID, imgUUID):
-        """
-        Return image directory
-        """
-        return os.path.join(self.repoPath, sdUUID, sd.DOMAIN_IMAGES, imgUUID)
+        return self.manifest.getImageDir(sdUUID, imgUUID)
 
     def deletedVolumeName(self, uuid):
         """


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7a78aef10902b9baf6f88d2e053e2232e2a1267
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>


More information about the vdsm-patches mailing list