]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
fetch_repo(): Call rmtree() when all attempts fail 708/head
authorZack Cerza <zack@redhat.com>
Tue, 17 Nov 2015 17:46:22 +0000 (10:46 -0700)
committerZack Cerza <zack@redhat.com>
Tue, 17 Nov 2015 17:46:22 +0000 (10:46 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/repo_utils.py

index 5dd95e4adf1b4c24ce33306f96ff3a846b1fc4f8..fe228a99517d0dab13342c06d5b85dff44dbdd9f 100644 (file)
@@ -6,7 +6,7 @@ import subprocess
 import time
 
 from .config import config
-from .contextutil import safe_while
+from .contextutil import safe_while, MaxWhileTries
 from .exceptions import BootstrapError, BranchNotFoundError, GitError
 
 log = logging.getLogger(__name__)
@@ -178,17 +178,20 @@ def fetch_repo(url, branch, bootstrap=None, lock=True):
     lock_path = dest_path.rstrip('/') + '.lock'
     with FileLock(lock_path, noop=not lock):
         with safe_while(sleep=10, tries=60) as proceed:
-            while proceed():
-                try:
-                    enforce_repo_state(url, dest_path,
-                                       branch)
-                    if bootstrap:
-                        bootstrap(dest_path)
-                    break
-                except GitError:
-                    log.exception("Git error encountered; retrying")
-                except BootstrapError:
-                    log.exception("Bootstrap error encountered; retrying")
+            try:
+                while proceed():
+                    try:
+                        enforce_repo_state(url, dest_path, branch)
+                        if bootstrap:
+                            bootstrap(dest_path)
+                        break
+                    except GitError:
+                        log.exception("Git error encountered; retrying")
+                    except BootstrapError:
+                        log.exception("Bootstrap error encountered; retrying")
+            except MaxWhileTries:
+                shutil.rmtree(dest_path, ignore_errors=True)
+                raise
     return dest_path