Ala Hino has uploaded a new change for review.

Change subject: qemuimg: Add wrapper to execute command
......................................................................

qemuimg: Add wrapper to execute command

Add wrapper to execute qemuimg command and raise QImgError if error
encountered.

Change-Id: I3483a202f9543098ad75e8be8bf4b398d26c8e4a
Signed-off-by: Ala Hino <ah...@redhat.com>
---
M lib/vdsm/qemuimg.py
1 file changed, 11 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/65178/1

diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index ef98149..c9e72ec 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -71,9 +71,7 @@
         cmd.extend(("-f", format))
 
     cmd.append(image)
-    rc, out, err = commands.execCmd(cmd, raw=True)
-    if rc != 0:
-        raise QImgError(rc, out, err)
+    out = _run_cmd(cmd)
 
     try:
         qemu_info = _parse_qemuimg_json(out)
@@ -125,10 +123,7 @@
     if size is not None:
         cmd.append(str(size))
 
-    rc, out, err = commands.execCmd(cmd, cwd=cwdPath)
-
-    if rc != 0:
-        raise QImgError(rc, out, err)
+    _run_cmd(cmd, cwd=cwdPath)
 
 
 def check(image, format=None):
@@ -138,11 +133,7 @@
         cmd.extend(("-f", format))
 
     cmd.append(image)
-    rc, out, err = commands.execCmd(cmd, raw=True)
-
-    # FIXME: handle different error codes and raise errors accordingly
-    if rc != 0:
-        raise QImgError(rc, out, err)
+    out = _run_cmd(cmd)
 
     try:
         qemu_check = _parse_qemuimg_json(out)
@@ -300,10 +291,7 @@
         cmd.extend(("-f", format))
 
     cmd.extend((image, str(newSize)))
-    rc, out, err = commands.execCmd(cmd)
-
-    if rc != 0:
-        raise QImgError(rc, out, err)
+    _run_cmd(cmd)
 
 
 def rebase(image, backing, format=None, backingFormat=None, unsafe=False,
@@ -351,3 +339,10 @@
     if value not in _QCOW2_COMPAT_SUPPORTED:
         raise ValueError("Invalid compat version %r" % value)
     return value
+
+
+def _run_cmd(cmd, cwd=None):
+    rc, out, err = commands.execCmd(cmd, raw=True, cwd=cwd)
+    if rc != 0:
+        raise QImgError(rc, out, err)
+    return out


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3483a202f9543098ad75e8be8bf4b398d26c8e4a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ala Hino <ah...@redhat.com>
_______________________________________________
vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org
To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org

Reply via email to