]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
error handling
authorRobin Wittler <robin.wittler@profitbricks.com>
Thu, 4 Aug 2011 11:59:20 +0000 (13:59 +0200)
committerRobin Wittler <robin.wittler@profitbricks.com>
Thu, 4 Aug 2011 11:59:20 +0000 (13:59 +0200)
testgit_build.py

index 99656ac0c5e16ba2ec9756169060ae85c766032d..03f4668eacc5a57591bf2610ca25c9204e68192f 100755 (executable)
@@ -105,52 +105,40 @@ def read_file(path):
 
 def remove_git_target_workspace():
     try:
-        shutil.rmtree(GIT_TARGET_WORKSPACE)
-    except IOError, error:
-        logger.debug('IOError happend. errno is: %s' %(error.errno))
-        if error.errno == errno.ENOENT:
-            logger.debug(
-                    '"%s" does not exists - and can be ignored'
-                    %(GIT_TARGET_WORKSPACE)
-            )
-        elif error.errno == errno.EACCES:
-            logger.debug(
-                    'Unsufficient rights to delete "%s"'
-                    %(GIT_TARGET_WORKSPACE)
-            )
-            cmd = [BIN_SUDO, BIN_RM, '-rvf', GIT_TARGET_WORKSPACE]
-            cmdobj = subprocess.Popen(
-                    cmd,
-                    shell=False,
-                    cwd='/',
-                    close_fds=True,
-                    stdout=subprocess.PIPE,
-                    stderr=subprocess.PIPE,
-                    env={'':''}
-            )
-
-            logger.debug(
-                    'Trying to call "%s" to delete "%s"'
-                    %(cmd, GIT_TARGET_WORKSPACE)
-            )
+        cmd = [BIN_SUDO, BIN_RM, '-rvf', GIT_TARGET_WORKSPACE]
+        cmdobj = subprocess.Popen(
+                cmd,
+                shell=False,
+                cwd='/',
+                close_fds=True,
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                env={'':''}
+        )
 
-            ret = cmdobj.wait()
+        logger.debug(
+                'Trying to call "%s" to delete "%s"'
+                %(cmd, GIT_TARGET_WORKSPACE)
+        )
 
-            if ret:
-                stderr_msg = cmdobj.stderr.read()
-                stdout_msg = cmdobj.stdout.read()
-                _str = (
-                        'Cmd "%s" returned non-zero (exitcode: %s). '
-                        %(cmd, ret) +
-                        'Output was: stdout="%s", stderr="%s"'
-                        %(stdout_msg, stderr_msg)
-                )
-                logger.debug(_str)
-                raise Exception(_str)
-            return cmdobj
-        else:
-            raise
-    logger.info('deleted %s' %(GIT_TARGET_WORKSPACE))
+        ret = cmdobj.wait()
+        if ret:
+            stderr_msg = cmdobj.stderr.read()
+            stdout_msg = cmdobj.stdout.read()
+            _str = (
+                    'Cmd "%s" returned non-zero (exitcode: %s). '
+                    %(cmd, ret) +
+                    'Output was: stdout="%s", stderr="%s"'
+                    %(stdout_msg, stderr_msg)
+            )
+            logger.debug(_str)
+            raise Exception(_str)
+        return cmdobj
+    except Exception, error:
+        logger.exception(error)
+        raise
+    else:
+        logger.info('deleted %s' %(GIT_TARGET_WORKSPACE))
 
 def exit_ok():
     send_email(SMTP_BUILD_SUCCESS)