From 61350db1bfd3f60112f976871767b820cfa9d272 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Mon, 27 Jun 2016 23:16:40 -0700 Subject: [PATCH] suite: move config tmpfile management to Run base_config changes over the course of the run, and so cannot be written to a tmpfile until it's completely finalized. Move the create/write/rm out of main() and into schedule_suite(). Signed-off-by: Dan Mick --- teuthology/suite/__init__.py | 19 ------------------- teuthology/suite/run.py | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/teuthology/suite/__init__.py b/teuthology/suite/__init__.py index 7a7f308f51..cf71b4c600 100644 --- a/teuthology/suite/__init__.py +++ b/teuthology/suite/__init__.py @@ -5,7 +5,6 @@ import logging import os import time -from tempfile import NamedTemporaryFile import teuthology from ..config import config, YamlConfig @@ -63,26 +62,8 @@ def main(args): log.info('Will upload archives to ' + args['--archive-upload']) run = Run(fn) - job_config = run.base_config name = run.name - - job_config.name = name - job_config.priority = fn.priority - if config.results_email: - job_config.email = config.results_email - if fn.owner: - job_config.owner = fn.owner - - if fn.dry_run: - log.debug("Base job config:\n%s" % job_config) - - with NamedTemporaryFile(prefix='schedule_suite_', - delete=False) as base_yaml: - base_yaml.write(str(job_config)) - base_yaml_path = base_yaml.name - run.base_yaml_paths.insert(0, base_yaml_path) run.prepare_and_schedule() - os.remove(base_yaml_path) if not fn.dry_run and args['--wait']: return wait(name, config.max_job_time, args['--archive-upload-url']) diff --git a/teuthology/suite/run.py b/teuthology/suite/run.py index 3addb602da..a105865566 100644 --- a/teuthology/suite/run.py +++ b/teuthology/suite/run.py @@ -6,6 +6,7 @@ import time import yaml from datetime import datetime +from tempfile import NamedTemporaryFile from ..config import config, JobConfig from ..exceptions import ( @@ -212,6 +213,12 @@ class Run(object): conf_dict = substitute_placeholders(dict_templ, self.config_input) conf_dict.update(self.kernel_dict) job_config = JobConfig.from_dict(conf_dict) + job_config.name = self.name + job_config.priority = self.args.priority + if self.args.results_email: + job_config.email = self.args.results_email + if self.args.owner: + job_config.owner = self.args.owner return job_config def build_base_args(self): @@ -414,6 +421,17 @@ class Run(object): log.info('Suite %s in %s generated %d jobs (not yet filtered)' % ( suite_name, suite_path, len(configs))) + if self.args.dry_run: + log.debug("Base job config:\n%s" % self.base_config) + + # create, but do not write, the temp file here, so it can be + # added to the args in collect_jobs, but not filled until + # any backtracking is done + base_yaml_path = NamedTemporaryFile( + prefix='schedule_suite_', delete=False + ).name + self.base_yaml_paths.insert(0, base_yaml_path) + # if newest, do this until there are no missing packages # if not, do it once backtrack = 0 @@ -444,8 +462,15 @@ class Run(object): name=name, ) + if self.args.dry_run: + log.debug("Base job config:\n%s" % self.base_config) + + with open(base_yaml_path, 'w+b') as base_yaml: + base_yaml.write(str(self.base_config)) self.schedule_jobs(jobs_missing_packages, jobs_to_schedule, name) + os.remove(base_yaml_path) + count = len(jobs_to_schedule) missing_count = len(jobs_missing_packages) log.info( -- 2.39.5