Add negative cachine to EnvironmentFactory Previously if there was a failed build requested N times we would attempt to build N times, instead of remembering that it failed. This adds a negative cache that is in memory only
Project: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/commit/5f3f5fb2 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/tree/5f3f5fb2 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/diff/5f3f5fb2 Branch: refs/heads/master Commit: 5f3f5fb2a1615fa7eec34b22bd6b481ce256bec2 Parents: 4a6eac1 Author: Thomas Jackson <[email protected]> Authored: Wed Jan 28 20:04:42 2015 -0800 Committer: Thomas Jackson <[email protected]> Committed: Wed Jan 28 20:04:42 2015 -0800 ---------------------------------------------------------------------- tsqa/environment.py | 66 ++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/5f3f5fb2/tsqa/environment.py ---------------------------------------------------------------------- diff --git a/tsqa/environment.py b/tsqa/environment.py index a5265b5..15580a6 100644 --- a/tsqa/environment.py +++ b/tsqa/environment.py @@ -21,6 +21,10 @@ class EnvironmentFactory(object): and will return copies of these in environments to callers ''' class_environment_stash = None + + # key -> exception + negative_cache = {} + def __init__(self, source_dir, env_cache_dir, @@ -128,34 +132,40 @@ class EnvironmentFactory(object): # if we don't have it built already, lets build it if key not in self.environment_stash: - self.autoreconf() - builddir = tempfile.mkdtemp() - - kwargs = { - 'cwd': builddir, - 'env': env, - 'stdout': subprocess.PIPE, - 'stderr': subprocess.PIPE - } - - if log.isEnabledFor(logging.DEBUG): - kwargs['stdout'] = sys.stdout.fileno() - kwargs['stderr'] = sys.stderr.fileno() - - # configure - args = [os.path.join(self.source_dir, 'configure'), '--prefix=/'] + tsqa.utils.configure_list(configure) - tsqa.utils.run_sync_command(args, **kwargs) - - # make - tsqa.utils.run_sync_command(['make', '-j{0}'.format(multiprocessing.cpu_count())], **kwargs) - installdir = tempfile.mkdtemp(dir=self.env_cache_dir) - - # make install - tsqa.utils.run_sync_command(['make', 'install', 'DESTDIR={0}'.format(installdir)], **kwargs) - - shutil.rmtree(builddir) # delete builddir, not useful after install - # stash the env - self.environment_stash[key] = installdir + if key in EnvironmentFactory.negative_cache: + raise EnvironmentFactory.negative_cache[key] + try: + self.autoreconf() + builddir = tempfile.mkdtemp() + + kwargs = { + 'cwd': builddir, + 'env': env, + 'stdout': subprocess.PIPE, + 'stderr': subprocess.PIPE + } + + if log.isEnabledFor(logging.DEBUG): + kwargs['stdout'] = sys.stdout.fileno() + kwargs['stderr'] = sys.stderr.fileno() + + # configure + args = [os.path.join(self.source_dir, 'configure'), '--prefix=/'] + tsqa.utils.configure_list(configure) + tsqa.utils.run_sync_command(args, **kwargs) + + # make + tsqa.utils.run_sync_command(['make', '-j{0}'.format(multiprocessing.cpu_count())], **kwargs) + installdir = tempfile.mkdtemp(dir=self.env_cache_dir) + + # make install + tsqa.utils.run_sync_command(['make', 'install', 'DESTDIR={0}'.format(installdir)], **kwargs) + + shutil.rmtree(builddir) # delete builddir, not useful after install + # stash the env + self.environment_stash[key] = installdir + except Exception as e: + EnvironmentFactory.negative_cache[key] = e + raise # create a layout layout = Layout(self.environment_stash[key])
