Adam Litke has uploaded a new change for review.
Change subject: VolumeMetadata: Move imagePath and validation
......................................................................
VolumeMetadata: Move imagePath and validation
Change-Id: I5d03085f04c92c1be68be2c0873e0545d307bdfa
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M tests/sdm_indirection_tests.py
M vdsm/storage/blockVolume.py
M vdsm/storage/fileVolume.py
M vdsm/storage/volume.py
4 files changed, 45 insertions(+), 34 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/82/46382/1
diff --git a/tests/sdm_indirection_tests.py b/tests/sdm_indirection_tests.py
index d331b2f..6ce9df5 100644
--- a/tests/sdm_indirection_tests.py
+++ b/tests/sdm_indirection_tests.py
@@ -499,6 +499,7 @@
['imgUUID', 'e2a325e4-62be-4939-8145-72277c270e8e'],
['volUUID', '6aab5eb4-2a8b-4cb7-a0b7-bc6f61de3e18'],
['repoPath', '/rhev/data-center'],
+ ['imagePath', '/a/b'],
['voltype', None],
])
def test_property(self, prop, val):
diff --git a/vdsm/storage/blockVolume.py b/vdsm/storage/blockVolume.py
index df30084..2955f28 100644
--- a/vdsm/storage/blockVolume.py
+++ b/vdsm/storage/blockVolume.py
@@ -74,6 +74,20 @@
volume.VolumeMetadata.__init__(self, repoPath, sdUUID, imgUUID,
volUUID)
+ def validateImagePath(self):
+ """
+ Block SD supports lazy image dir creation
+ """
+ imageDir = image.ImageManifest(self.repoPath).getImageDir(self.sdUUID,
+ self.imgUUID)
+ if not os.path.isdir(imageDir):
+ try:
+ os.mkdir(imageDir, 0o755)
+ except Exception:
+ self.log.exception("Unexpected error")
+ raise se.ImagePathError(imageDir)
+ self._imagePath = imageDir
+
class BlockVolume(volume.Volume):
""" Actually represents a single volume (i.e. part of virtual disk).
@@ -336,7 +350,7 @@
"""
self.log.info("Rename volume %s as %s ", self.volUUID, newUUID)
if not self.imagePath:
- self.validateImagePath()
+ self.md.validateImagePath()
if os.path.lexists(self.getVolumePath()):
os.unlink(self.getVolumePath())
@@ -421,20 +435,6 @@
if pvolUUID != volume.BLANK_UUID:
cls.teardown(sdUUID=sdUUID, volUUID=pvolUUID, justme=False)
- def validateImagePath(self):
- """
- Block SD supports lazy image dir creation
- """
- imageDir = image.Image(self.repoPath).getImageDir(self.sdUUID,
- self.imgUUID)
- if not os.path.isdir(imageDir):
- try:
- os.mkdir(imageDir, 0o755)
- except Exception:
- self.log.error("Unexpected error", exc_info=True)
- raise se.ImagePathError(imageDir)
- self.imagePath = imageDir
-
def validateVolumePath(self):
"""
Block SD supports lazy volume link creation. Note that the volume can
@@ -442,7 +442,7 @@
An explicit prepare is required to validate that the volume is active.
"""
if not self.imagePath:
- self.validateImagePath()
+ self.md.validateImagePath()
volPath = os.path.join(self.imagePath, self.volUUID)
if not os.path.lexists(volPath):
srcPath = lvm.lvPath(self.sdUUID, self.volUUID)
diff --git a/vdsm/storage/fileVolume.py b/vdsm/storage/fileVolume.py
index 002f2c0..cfe40d0 100644
--- a/vdsm/storage/fileVolume.py
+++ b/vdsm/storage/fileVolume.py
@@ -60,6 +60,20 @@
def oop(self):
return oop.getProcessPool(self.sdUUID)
+ def validateImagePath(self):
+ """
+ Validate that the image dir exists and valid.
+ In the file volume repositories,
+ the image dir must exists after creation its first volume.
+ """
+ imageDir = image.ImageManifest(self.repoPath).getImageDir(self.sdUUID,
+ self.imgUUID)
+ if not self.oop.os.path.isdir(imageDir):
+ raise se.ImagePathError(imageDir)
+ if not self.oop.os.access(imageDir, os.R_OK | os.W_OK | os.X_OK):
+ raise se.ImagePathError(imageDir)
+ self._imagePath = imageDir
+
class FileVolume(volume.Volume):
""" Actually represents a single volume (i.e. part of virtual disk).
@@ -451,7 +465,7 @@
"""
self.log.info("Rename volume %s as %s ", self.volUUID, newUUID)
if not self.imagePath:
- self.validateImagePath()
+ self.md.validateImagePath()
volPath = os.path.join(self.imagePath, newUUID)
metaPath = self._getMetaVolumePath(volPath)
prevMetaPath = self._getMetaVolumePath()
@@ -488,20 +502,6 @@
raise
self.md.volUUID = newUUID
self.volumePath = volPath
-
- def validateImagePath(self):
- """
- Validate that the image dir exists and valid.
- In the file volume repositories,
- the image dir must exists after creation its first volume.
- """
- imageDir = image.Image(self.repoPath).getImageDir(self.sdUUID,
- self.imgUUID)
- if not self.oop.os.path.isdir(imageDir):
- raise se.ImagePathError(imageDir)
- if not self.oop.os.access(imageDir, os.R_OK | os.W_OK | os.X_OK):
- raise se.ImagePathError(imageDir)
- self.imagePath = imageDir
@classmethod
def __metaVolumePath(cls, volPath):
@@ -541,7 +541,7 @@
"""
self.log.debug("validate path for %s" % self.volUUID)
if not self.imagePath:
- self.validateImagePath()
+ self.md.validateImagePath()
volPath = os.path.join(self.imagePath, self.volUUID)
if not self.oop.fileUtils.pathExists(volPath):
raise se.VolumeDoesNotExist(self.volUUID)
diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py
index ec82c9b..26487bd 100644
--- a/vdsm/storage/volume.py
+++ b/vdsm/storage/volume.py
@@ -134,12 +134,19 @@
self.sdUUID = sdUUID
self.imgUUID = imgUUID
self.volUUID = volUUID
+ self._imagePath = None
self.voltype = None
if not imgUUID or imgUUID == BLANK_UUID:
raise se.InvalidParameterException("imgUUID", imgUUID)
if not volUUID or volUUID == BLANK_UUID:
raise se.InvalidParameterException("volUUID", volUUID)
+
+ @property
+ def imagePath(self):
+ if self._imagePath is None:
+ self.validateImagePath()
+ return self._imagePath
class Volume(object):
@@ -148,7 +155,6 @@
def __init__(self, md):
self.md = md
self.volumePath = None
- self.imagePath = None
self.validate()
@property
@@ -168,6 +174,10 @@
return self.md.repoPath
@property
+ def imagePath(self):
+ return self.md.imagePath
+
+ @property
def voltype(self):
return self.md.voltype
@@ -181,7 +191,7 @@
"""
Validate that the volume can be accessed
"""
- self.validateImagePath()
+ self.md.validateImagePath()
self.validateVolumePath()
def __str__(self):
--
To view, visit
https://gerrit.ovirt.org/46382
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d03085f04c92c1be68be2c0873e0545d307bdfa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>