]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Rewrite branch fetching.
authorZack Cerza <zack@cerza.org>
Fri, 23 Aug 2013 14:59:48 +0000 (09:59 -0500)
committerZack Cerza <zack@cerza.org>
Fri, 23 Aug 2013 14:59:48 +0000 (09:59 -0500)
teuthology/queue.py

index d35b574f0e19a1444b2131ff69ddeee6b4021b04..088196cc892c90fe769a0dd7ffeb503a12d38db5 100644 (file)
@@ -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'):