Change in vdsm[master]: core: generify "streamDownloadImage" related methods

laravot at redhat.com laravot at redhat.com
Mon Apr 14 13:39:44 UTC 2014


Liron Ar has uploaded a new change for review.

Change subject: core: generify "streamDownloadImage" related methods
......................................................................

core: generify "streamDownloadImage" related methods

This patch generifies the related "streamDownloadImage" methods in
image/imageSharing to be have more generic name as they could be used
with any passed fileObj.

Change-Id: I1c73374681b5a5fc9fd0cb81020138fb5c8bfe69
Signed-off-by: Liron Aravot <laravot at redhat.com>
---
M vdsm/storage/image.py
M vdsm/storage/imageSharing.py
M vdsm/storage/sp.py
3 files changed, 9 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/26761/1

diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index 63dc56a..7d5f78d 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -1174,14 +1174,14 @@
         finally:
             domain.deactivateImage(imgUUID)
 
-    def downloadFromStream(self, methodArgs, sdUUID, imgUUID, volUUID=None):
+    def copyToImage(self, methodArgs, sdUUID, imgUUID, volUUID=None):
         domain = sdCache.produce(sdUUID)
 
         vol = self._activateVolumeForImportExport(domain, imgUUID, volUUID)
         try:
             # Extend the volume (if relevant) to the image size
             vol.extend(imageSharing.
-                       streamGetSize(methodArgs) / volume.BLOCK_SIZE)
-            imageSharing.streamDownloadImage(vol.getVolumePath(), methodArgs)
+                       getLengthFromArgs(methodArgs) / volume.BLOCK_SIZE)
+            imageSharing.copyToImage(vol.getVolumePath(), methodArgs)
         finally:
             domain.deactivateImage(imgUUID)
diff --git a/vdsm/storage/imageSharing.py b/vdsm/storage/imageSharing.py
index 8f150f3..47d2bb1 100644
--- a/vdsm/storage/imageSharing.py
+++ b/vdsm/storage/imageSharing.py
@@ -60,7 +60,7 @@
     return size
 
 
-def streamGetSize(methodArgs):
+def getLengthFromArgs(methodArgs):
     return methodArgs['contentLength']
 
 
@@ -74,21 +74,16 @@
                        methodArgs.get("headers", {}))
 
 
-def streamDownloadImage(dstImgPath, methodArgs):
-    bytes_left = streamGetSize(methodArgs)
-    stream = methodArgs['fileObj']
+def copyToImage(dstImgPath, methodArgs):
+    bytes_left = getLengthFromArgs(methodArgs)
+    fileObj = methodArgs['fileObj']
 
     cmd = [constants.EXT_DD, "of=%s" % dstImgPath, "bs=%s" % constants.MEGAB]
     p = utils.execCmd(cmd, sudo=False, sync=False,
                       deathSignal=signal.SIGKILL)
     try:
-        _copyData(stream, p.stdin, bytes_left)
+        _copyData(fileObj, p.stdin, bytes_left)
         _ensureProcessSucceded(p, constants.EXT_DD, se.StorageException)
-    except Exception:
-        if p.returncode is None:
-            p.kill()
-        raise
-
     except Exception:
         if p.returncode is None:
             p.kill()
diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py
index 4de27d9..40feda3 100644
--- a/vdsm/storage/sp.py
+++ b/vdsm/storage/sp.py
@@ -1641,7 +1641,7 @@
         with imgResourceLock:
             try:
                 return image.Image(self.poolPath) \
-                    .downloadFromStream(methodArgs, sdUUID, imgUUID, volUUID)
+                    .copyToImage(methodArgs, sdUUID, imgUUID, volUUID)
             finally:
                 callback()
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c73374681b5a5fc9fd0cb81020138fb5c8bfe69
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Liron Ar <laravot at redhat.com>


More information about the vdsm-patches mailing list