From 307284c2edf866163d0793f89cf24ba2333b0ccc Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 23 Aug 2013 09:59:48 -0500 Subject: [PATCH] Rewrite branch fetching. --- teuthology/queue.py | 55 ++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/teuthology/queue.py b/teuthology/queue.py index d35b574f0e..088196cc89 100644 --- a/teuthology/queue.py +++ b/teuthology/queue.py @@ -2,6 +2,7 @@ import argparse import logging import os import subprocess +import shutil import sys import tempfile import yaml @@ -86,34 +87,52 @@ describe. One job is run at a time. log.debug('Config is: %s', job.body) job_config = yaml.safe_load(job.body) safe_archive = safepath.munge(job_config['name']) - teuthology_branch = job_config.get('config', {}).get('teuthology_branch', 'master') + teuthology_branch = job_config.get( + 'config', {}).get('teuthology_branch', 'master') teuth_path = os.path.join(os.getenv("HOME"), 'teuthology-' + teuthology_branch) + # Make sure we have the correct teuthology branch checked out and # up-to-date if not os.path.isdir(teuth_path): - log.info("Local teuthology repo not found at %s - cloning", - teuth_path) - subprocess.Popen(('git', 'clone', '--branch', teuthology_branch, - teuthology_git_upstream, teuth_path), - cwd=os.getenv("HOME")) - - log.info("Bootstrapping %s", teuth_path) - # This magic makes the bootstrap script not attempt to clobber an - # existing virtualenv. - env = os.environ.copy() - env['NO_CLOBBER'] = '1' - subprocess.Popen(('./bootstrap'), cwd=teuth_path, env=env) + log.info("Cloning %s from upstream", teuthology_branch) + log.info( + subprocess.check_output(('git', 'clone', '--branch', + teuthology_branch, + teuthology_git_upstream, teuth_path), + cwd=os.getenv("HOME")) + ) else: - log.info("Pulling %s from upstream", teuthology_branch) - subprocess.Popen(('git', 'fetch', '-p', 'origin'), cwd=teuth_path) - subprocess.Popen(('git', 'reset', '--hard', 'origin/%s' % - teuthology_branch), cwd=teuth_path) + log.info("Fetching %s from upstream", teuthology_branch) + log.info( + subprocess.check_output(('git', 'fetch', '-p', 'origin'), + cwd=teuth_path) + ) + + # This try/except block will notice if the requested branch doesn't + # exist, whether it was cloned or fetched. + try: + subprocess.check_call(('git', 'reset', '--hard', 'origin/%s' % + teuthology_branch), cwd=teuth_path) + except subprocess.CalledProcessError: + log.error("teuthology branch not found: %s", teuthology_branch) + shutil.rmtree(teuth_path) + raise + + log.info("Bootstrapping %s", teuth_path) + # This magic makes the bootstrap script not attempt to clobber an + # existing virtualenv. But the branch's bootstrap needs to actually + # check for the NO_CLOBBER variable. + env = os.environ.copy() + env['NO_CLOBBER'] = '1' + log.info( + subprocess.check_output(('./bootstrap'), cwd=teuth_path, env=env) + ) teuth_bin_path = os.path.join(teuth_path, 'virtualenv', 'bin') if not os.path.isdir(teuth_bin_path): - raise RuntimeError('Teuthology branch %s not found at %s' % + raise RuntimeError("teuthology branch %s at %s not bootstrapped!" % (teuthology_branch, teuth_bin_path)) if job_config.get('last_in_suite'): -- 2.39.5