From 2270db724ddb474464018588f7b730df1db6d179 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 4 Oct 2013 10:25:07 -0500 Subject: [PATCH] Add (and use) try_push_job_info() for easy pushin' Signed-off-by: Zack Cerza --- teuthology/report.py | 26 +++++++++++++++++++++++++- teuthology/run.py | 24 +++++------------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/teuthology/report.py b/teuthology/report.py index de0ff43c0abe6..b896ff10c1810 100755 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -327,7 +327,6 @@ def push_job_info(run_name, job_id, job_info, base_uri=None): :param job_info: A dict containing the job's information. :param base_uri: The endpoint of the results server. If you leave it out ResultsReporter will ask teuthology.config. - :returns: True if the run was successfully created. """ # We are using archive_base='' here because we KNOW the serializer isn't # needed for this codepath. @@ -336,6 +335,31 @@ def push_job_info(run_name, job_id, job_info, base_uri=None): reporter.report_job(run_name, job_id, job_json) +def try_push_job_info(job_config, job_info=None): + """ + Wrap push_job_info, gracefully doing nothing if: + A RequestFailedError is raised + config.results_server is not set + + :param job_config: The ctx.config object + :param job_info: Dict to push (commonly None) + """ + if not config.results_server: + msg = "No results_server set in {yaml}; not attempting to push results" + log.debug(msg.format(yaml=config.teuthology_yaml)) + else: + run_name = job_config['name'] + job_id = job_config['job_id'] + if job_info is None: + job_info = job_config + + try: + push_job_info(run_name, job_id, job_info) + except RequestFailedError: + log.exception("Could not report results to %s" % + config.results_server) + + def parse_args(): parser = argparse.ArgumentParser( description="Submit test results to a web service") diff --git a/teuthology/run.py b/teuthology/run.py index 15f4de8de8336..767e131e2918f 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -155,7 +155,6 @@ def main(): import logging from . import report - from .config import config as teuth_config ctx = parse_args() set_up_logging(ctx) @@ -166,15 +165,7 @@ def main(): ctx.owner = get_user() write_initial_metadata(ctx) - if teuth_config.results_server: - try: - run_name = ctx.config['name'] - report.create_run(run_name) - report.push_job_info(run_name, ctx.config['job_id'], ctx.config) - except report.RequestFailedError: - log.exception("Could not report results to %s" % - teuth_config.results_server) - + report.try_push_job_info(ctx.config) if 'targets' in ctx.config and 'roles' in ctx.config: targets = len(ctx.config['targets']) @@ -259,15 +250,9 @@ def main(): subject = "Teuthology error -- %s" % ctx.summary['failure_reason'] from teuthology.suite import email_results email_results(subject,"Teuthology",ctx.config['email-on-error'],emsg) - if teuth_config.results_server: - try: - run_name = ctx.config['name'] - job_id = ctx.config['name'] - report.push_job_info(run_name, job_id, ctx.config) - report.push_job_info(run_name, job_id, ctx.summary) - except report.RequestFailedError: - log.exception("Could not report results to %s" % - teuth_config.results_server) + + report.try_push_job_info(ctx.config, ctx.summary) + report.try_push_job_info(ctx.config) if ctx.summary.get('success', True): log.info('pass') @@ -276,6 +261,7 @@ def main(): import sys sys.exit(1) + def schedule(): parser = argparse.ArgumentParser(description='Schedule ceph integration tests') parser.add_argument( -- 2.39.5