Change in vdsm[master]: storage: sdm: consolidate create validation

alitke at redhat.com alitke at redhat.com
Tue Apr 26 13:39:41 UTC 2016


Adam Litke has uploaded a new change for review.

Change subject: storage: sdm: consolidate create validation
......................................................................

storage: sdm: consolidate create validation

The validation of VolumeArtifacts.create parameters can be shared
between the File and upcoming Block artifacts classes.  Move it to
VolumeArtifacts in order to share it.

Change-Id: I7ae29674917980d5d36f7455c177572e62d575b4
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M vdsm/storage/sdm/volume_artifacts.py
1 file changed, 20 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/56627/1

diff --git a/vdsm/storage/sdm/volume_artifacts.py b/vdsm/storage/sdm/volume_artifacts.py
index b0928a7..e969baa 100644
--- a/vdsm/storage/sdm/volume_artifacts.py
+++ b/vdsm/storage/sdm/volume_artifacts.py
@@ -107,6 +107,22 @@
         """
         raise NotImplementedError()
 
+    def _validate_create_params(self, vol_format, parent, prealloc):
+        # XXX: Remove these when support is added:
+        if vol_format != volume.RAW_FORMAT:
+            raise NotImplementedError("Only raw volumes are supported")
+        if parent:
+            raise NotImplementedError("parent_vol_id not supported")
+
+        if self.is_image() and not parent:
+            self.log.debug("parent not provided when creating a volume in an"
+                           "existing image.")
+            raise se.InvalidParameterException("parent", parent)
+
+        parent_vol_id = parent.vol_id if parent else volume.BLANK_UUID
+        self.sd_manifest.validateCreateVolumeParams(
+            vol_format, parent_vol_id, preallocate=prealloc)
+
 
 class FileVolumeArtifacts(VolumeArtifacts):
     """
@@ -194,27 +210,14 @@
         """
         Create metadata file artifact, lease file, and volume file on storage.
         """
-        # XXX: Remove these when support is added:
-        if vol_format != volume.RAW_FORMAT:
-            raise NotImplementedError("Only raw volumes are supported")
-        if parent:
-            raise NotImplementedError("parent not supported")
-
-        if self.is_image() and not parent:
-            self.log.debug("parent not provided when creating a volume in an"
-                           "existing image.")
-            raise se.InvalidParameterException("parent", parent)
-
-        parent_vol_id = parent.vol_id if parent else volume.BLANK_UUID
         prealloc = self._get_volume_preallocation(vol_format)
-        self.sd_manifest.validateCreateVolumeParams(
-            vol_format, parent_vol_id, preallocate=prealloc)
+        self._validate_create_params(vol_format, parent, prealloc)
 
         if not self.is_image():
             self._create_image_artifact()
 
         self._create_metadata_artifact(size, vol_format, prealloc, disk_type,
-                                       desc, parent_vol_id)
+                                       desc, parent)
         self._create_lease_file()
         self._create_volume_file(vol_format, size)
 
@@ -235,7 +238,7 @@
         return volume.SPARSE_VOL
 
     def _create_metadata_artifact(self, size, vol_format, prealloc, disk_type,
-                                  desc, parent_vol_id):
+                                  desc, parent):
         if self._oop.fileUtils.pathExists(self.meta_path):
             raise se.VolumeAlreadyExists("metadata exists: %r" %
                                          self.meta_path)
@@ -244,6 +247,7 @@
             raise se.DomainHasGarbage("metadata artifact exists: %r" %
                                       self.meta_volatile_path)
 
+        parent_vol_id = parent.vol_id if parent else volume.BLANK_UUID
         # Create the metadata artifact.  The metadata file is created with a
         # special extension to prevent these artifacts from being recognized as
         # a volume until FileVolumeArtifacts.commit() is called.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ae29674917980d5d36f7455c177572e62d575b4
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