From: Zack Cerza Date: Tue, 17 Nov 2015 17:46:22 +0000 (-0700) Subject: fetch_repo(): Call rmtree() when all attempts fail X-Git-Tag: 1.1.0~754^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a604c67c3eec6df2a90882b2afd992d0d40a06e7;p=teuthology.git fetch_repo(): Call rmtree() when all attempts fail Signed-off-by: Zack Cerza --- diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index 5dd95e4adf..fe228a9951 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -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