From 264be71ebe66f499fe71c8018a35f59a584f46c0 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 3 Jul 2017 11:34:32 +0200 Subject: [PATCH] libkas: Terminate kas on _repo_fetch_async errors This behavior got lost through 0bdd7a8d523e. Specifically, errors during git clone no longer shut down kas. Fix this by reporting back an error code from _repo_fetch_async and terminate in repos_fetch if it's non-zero. Drop the return value of repos_fetch - no caller expects any. Signed-off-by: Jan Kiszka --- kas/libkas.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/kas/libkas.py b/kas/libkas.py index b3137db..dea799b 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -157,7 +157,7 @@ def _repo_fetch_async(config, repo): Start asynchronous repository fetch. """ if repo.git_operation_disabled: - return + return 0 if not os.path.exists(repo.path): os.makedirs(os.path.dirname(repo.path), exist_ok=True) @@ -173,7 +173,7 @@ def _repo_fetch_async(config, repo): cwd=config.kas_work_dir) if retc == 0: logging.info('Repository %s cloned', repo.name) - return + return retc # Does refspec exist in the current repository? (retc, output) = yield from run_cmd_async(['/usr/bin/git', @@ -186,7 +186,7 @@ def _repo_fetch_async(config, repo): if retc == 0: logging.info('Repository %s already contains %s as %s', repo.name, repo.refspec, output.strip()) - return + return retc # No it is missing, try to fetch (retc, output) = yield from run_cmd_async(['/usr/bin/git', @@ -199,18 +199,27 @@ def _repo_fetch_async(config, repo): repo.name, output) else: logging.info('Repository %s updated', repo.name) + return 0 def repos_fetch(config, repos): """ Fetches the list of repositories to the kas_work_dir. """ - cmds = [] + tasks = [] for repo in repos: - cmds.append(_repo_fetch_async(config, repo)) + if hasattr(asyncio, 'ensure_future'): + task = asyncio.ensure_future(_repo_fetch_async(config, repo)) + else: + task = asyncio.async(_repo_fetch_async(config, repo)) + tasks.append(task) loop = asyncio.get_event_loop() - return loop.run_until_complete(asyncio.wait(cmds)) + loop.run_until_complete(asyncio.wait(tasks)) + + for task in tasks: + if task.result(): + sys.exit(task.result()) def repo_checkout(config, repo):