Federico Simoncelli has uploaded a new change for review.
Change subject: image: unify the getChainTemplate method
......................................................................
image: unify the getChainTemplate method
Change-Id: I32fedf40e8c05d4ef7d26cb9172c22d7ee6e9086
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
M vdsm/storage/image.py
1 file changed, 11 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/68/12868/1
diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index 92021ff..4c6047e 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -260,7 +260,7 @@
"""
chain = self.getChain(sdUUID, imgUUID, volUUID)
newsize = 0
- template = chain[0].getParentVolume()
+ template = self.getChainTemplate(chain)
if template:
newsize = template.getVolumeSize()
for vol in chain:
@@ -327,27 +327,22 @@
self.log.info("sdUUID=%s imgUUID=%s chain=%s ", sdUUID, imgUUID,
chain)
return chain
- def getTemplate(self, sdUUID, imgUUID):
+ def getChainTemplate(self, chain):
"""
- Return template of the image
+ Return the template of a volume chain. None if not present.
"""
- tmpl = None
- # Find all volumes of image (excluding template)
- chain = self.getChain(sdUUID, imgUUID)
- # check if the chain is build above a template, or it is a standalone
- pvol = chain[0].getParentVolume()
- if pvol:
- tmpl = pvol
- elif chain[0].isShared():
- tmpl = chain[0]
+ try:
+ templateVolume = chain[0].getParentVolume()
+ except IndexError:
+ raise se.ImageValidationError("The chain has no volumes")
- return tmpl
+ return templateVolume
def prepare(self, sdUUID, imgUUID, volUUID=None):
chain = self.getChain(sdUUID, imgUUID, volUUID)
# Adding the image template to the chain
- tmplVolume = chain[0].getParentVolume()
+ tmplVolume = self.getChainTemplate(chain)
if tmplVolume:
chain.insert(0, tmplVolume)
@@ -489,7 +484,7 @@
fakeTemplate = False
pimg = volume.BLANK_UUID # standalone chain
# check if the chain is build above a template, or it is a standalone
- pvol = srcChain[0].getParentVolume()
+ pvol = self.getChainTemplate(srcChain)
if pvol:
# find out parent volume parameters
volParams = pvol.getVolumeParams()
@@ -790,7 +785,7 @@
raise se.ImageIsNotLegalChain(imgUUID)
chain = self.getChain(sdUUID, imgUUID)
# check if the chain is build above a template, or it is a standalone
- pvol = chain[0].getParentVolume()
+ pvol = self.getChainTemplate(chain)
if pvol:
if not pvol.isLegal() or pvol.isFake():
raise se.ImageIsNotLegalChain(imgUUID)
--
To view, visit
http://gerrit.ovirt.org/12868
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I32fedf40e8c05d4ef7d26cb9172c22d7ee6e9086
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>