From 04f8fd85bbc81eb9a2853e247d1e8a027f5d67b8 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 16 Oct 2014 12:54:07 -0600 Subject: [PATCH] Use new functions provided by job_status Signed-off-by: Zack Cerza --- teuthology/ls.py | 6 ++++-- teuthology/report.py | 5 +++-- teuthology/results.py | 3 ++- teuthology/run.py | 16 ++++++++++------ teuthology/run_tasks.py | 11 +++++++---- teuthology/task/internal.py | 14 ++++++++------ 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/teuthology/ls.py b/teuthology/ls.py index 57c1ef5502..8df818b0ac 100644 --- a/teuthology/ls.py +++ b/teuthology/ls.py @@ -3,6 +3,8 @@ import yaml import errno import re +from .job_status import get_status + def main(args): return ls(args.archive_dir, args.verbose) @@ -47,11 +49,11 @@ def ls(archive_dir, verbose): else: raise - print "{job} {success} {owner} {desc} {duration}s".format( + print "{job} {status} {owner} {desc} {duration}s".format( job=j, owner=summary.get('owner', '-'), desc=summary.get('description', '-'), - success='pass' if summary.get('success', False) else 'FAIL', + status=get_status(summary), duration=int(summary.get('duration', 0)), ) if verbose and 'failure_reason' in summary: diff --git a/teuthology/report.py b/teuthology/report.py index 7f052594b2..5144016489 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -9,6 +9,7 @@ from datetime import datetime import teuthology from .config import config +from .job_status import get_status, set_status report_exceptions = (requests.exceptions.RequestException, socket.error) @@ -288,8 +289,8 @@ class ResultsReporter(object): base=self.base_uri, name=run_name,) if job_info is None: job_info = self.serializer.job_info(run_name, job_id) - if dead and job_info.get('success') is None: - job_info['status'] = 'dead' + if dead and get_status(job_info) is None: + set_status(job_info, 'dead') job_json = json.dumps(job_info) headers = {'content-type': 'application/json'} response = self.session.post(run_uri, data=job_json, headers=headers) diff --git a/teuthology/results.py b/teuthology/results.py index 586a6c5e5c..4669b62e52 100644 --- a/teuthology/results.py +++ b/teuthology/results.py @@ -10,6 +10,7 @@ from textwrap import fill import teuthology from teuthology import misc from teuthology import ls +from .job_status import get_status from .report import ResultsSerializer log = logging.getLogger(__name__) @@ -131,7 +132,7 @@ def build_email_body(name, archive_dir, timeout): with file(summary_file) as f: summary = yaml.safe_load(f) - if summary['success']: + if get_status(summary) == 'pass': passed[job] = email_templates['pass_templ'].format( job_id=job, desc=summary.get('description'), diff --git a/teuthology/run.py b/teuthology/run.py index 64cb513854..714153aeff 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -8,6 +8,7 @@ from traceback import format_tb import teuthology from . import report +from .job_status import get_status, set_status from .misc import get_user from .misc import read_config from .nuke import nuke @@ -131,7 +132,8 @@ def main(ctx): log.debug('\n '.join(['Config:', ] + yaml.safe_dump( ctx.config, default_flow_style=False).splitlines())) - ctx.summary = dict(success=True) + ctx.summary = dict(status='pass') + set_status(ctx.summary, 'pass') ctx.summary['owner'] = ctx.owner @@ -185,7 +187,9 @@ def main(ctx): try: run_tasks(tasks=ctx.config['tasks'], ctx=ctx) finally: - if not ctx.summary.get('success') and bool(ctx.config.get('nuke-on-error')): + status = get_status(ctx.summary) + passed = status == 'pass' + if not passed and bool(ctx.config.get('nuke-on-error')): # only unlock if we locked them in the first place nuke(ctx, ctx.lock) if ctx.archive is not None: @@ -196,7 +200,7 @@ def main(ctx): log.info('Summary data:\n%s' % f.getvalue()) with contextlib.closing(StringIO.StringIO()) as f: if ('email-on-error' in ctx.config - and not ctx.summary.get('success', False)): + and not passed): yaml.safe_dump(ctx.summary, f) yaml.safe_dump(ctx.config, f) emsg = f.getvalue() @@ -207,8 +211,8 @@ def main(ctx): report.try_push_job_info(ctx.config, ctx.summary) - if ctx.summary.get('success', True): - log.info('pass') + if passed: + log.info(status) else: - log.info('FAIL') + log.info(str(status).upper()) sys.exit(1) diff --git a/teuthology/run_tasks.py b/teuthology/run_tasks.py index fd379fe559..588e7ea6c2 100644 --- a/teuthology/run_tasks.py +++ b/teuthology/run_tasks.py @@ -1,6 +1,7 @@ import sys import logging from .sentry import get_client as get_sentry_client +from .job_status import set_status from .misc import get_http_log_path from .config import config as teuth_config from .exceptions import ConnectionLostError @@ -54,10 +55,11 @@ def run_tasks(tasks, ctx): manager.__enter__() stack.append((taskname, manager)) except BaseException as e: - ctx.summary['success'] = False if isinstance(e, ConnectionLostError): # Prevent connection issues being flagged as failures - ctx.summary['status'] = 'dead' + set_status(ctx.summary, 'dead') + else: + set_status(ctx.summary, 'fail') if 'failure_reason' not in ctx.summary: ctx.summary['failure_reason'] = str(e) log.exception('Saw exception from tasks.') @@ -116,10 +118,11 @@ def run_tasks(tasks, ctx): try: suppress = manager.__exit__(*exc_info) except Exception as e: - ctx.summary['success'] = False if isinstance(e, ConnectionLostError): # Prevent connection issues being flagged as failures - ctx.summary['status'] = 'dead' + set_status(ctx.summary, 'dead') + else: + set_status(ctx.summary, 'fail') if 'failure_reason' not in ctx.summary: ctx.summary['failure_reason'] = str(e) log.exception('Manager failed: %s', taskname) diff --git a/teuthology/task/internal.py b/teuthology/task/internal.py index efdd854e46..bb0e7a0061 100644 --- a/teuthology/task/internal.py +++ b/teuthology/task/internal.py @@ -15,6 +15,7 @@ from teuthology import lockstatus from teuthology import lock from teuthology import misc from teuthology import provision +from teuthology.job_status import get_status, set_status from teuthology.config import config as teuth_config from teuthology.parallel import parallel from ..orchestra import cluster, remote, run @@ -147,7 +148,7 @@ def lock_machines(ctx, config): yield finally: if ctx.config.get('unlock_on_failure', False) or \ - ctx.summary.get('success', False): + get_status(ctx.summary) == 'pass': log.info('Unlocking machines...') for machine in ctx.config['targets'].iterkeys(): lock.unlock_one(ctx, machine, ctx.owner) @@ -320,11 +321,12 @@ def archive(ctx, config): yield except Exception: # we need to know this below - ctx.summary['success'] = False + set_status(ctx.summary, 'fail') raise finally: + passed = get_status(ctx.summary) == 'pass' if ctx.archive is not None and \ - not (ctx.config.get('archive-on-error') and ctx.summary['success']): + not (ctx.config.get('archive-on-error') and passed): log.info('Transferring archived files...') logdir = os.path.join(ctx.archive, 'remote') if (not os.path.exists(logdir)): @@ -415,7 +417,7 @@ def coredump(ctx, config): ) ) - # set success=false if the dir is still there = coredumps were + # set status = 'fail' if the dir is still there = coredumps were # seen for rem in ctx.cluster.remotes.iterkeys(): r = rem.run( @@ -428,7 +430,7 @@ def coredump(ctx, config): ) if r.stdout.getvalue() != 'OK\n': log.warning('Found coredumps on %s, flagging run as failed', rem) - ctx.summary['success'] = False + set_status(ctx.summary, 'fail') if 'failure_reason' not in ctx.summary: ctx.summary['failure_reason'] = \ 'Found coredumps on {rem}'.format(rem=rem) @@ -545,7 +547,7 @@ kern.* -{adir}/syslog/kern.log;RSYSLOG_FileFormat stdout = r.stdout.getvalue() if stdout != '': log.error('Error in syslog on %s: %s', rem.name, stdout) - ctx.summary['success'] = False + set_status(ctx.summary, 'fail') if 'failure_reason' not in ctx.summary: ctx.summary['failure_reason'] = \ "'{error}' in syslog".format(error=stdout) -- 2.39.5