import logging
import os
import subprocess
+import shutil
import sys
import tempfile
import yaml
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'):