From 7be9eaa03068a40fd19d5d6af37d7e95d1b324ab Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 29 Aug 2011 12:42:45 -0700 Subject: [PATCH] suite: add option to send an email if the entire suite passed --- teuthology/queue.py | 26 ++++++++++++----------- teuthology/run.py | 8 +++++++ teuthology/suite.py | 51 ++++++++++++++++++++++++++++++++------------- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/teuthology/queue.py b/teuthology/queue.py index 5857c4ca88..3caf5e2dba 100644 --- a/teuthology/queue.py +++ b/teuthology/queue.py @@ -79,18 +79,20 @@ describe. One job is run at a time. if job_config.get('last_in_suite', False): log.debug('Generating coverage for %s', job_config['name']) - subprocess.Popen( - args=[ - os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-results'), - '--timeout', - job_config.get('results_timeout', '21600'), - '--email', - job_config['email'], - '--archive-dir', - os.path.join(ctx.archive_dir, safe_archive), - '--name', - job_config['name'], - ]) + args = [ + os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-results'), + '--timeout', + job_config.get('results_timeout', '21600'), + '--email', + job_config['email'], + '--archive-dir', + os.path.join(ctx.archive_dir, safe_archive), + '--name', + job_config['name'], + ] + if job_config.get('email_on_success', False): + args.append('--email-on-success') + subprocess.Popen(args=args) else: log.debug('Creating archive dir...') safepath.makedirs(ctx.archive_dir, safe_archive) diff --git a/teuthology/run.py b/teuthology/run.py index b4e53f8fdc..32b54c6305 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -185,6 +185,12 @@ def schedule(): '--email', help='where to send the results of a suite (only applies to the last job in a suite)', ) + parser.add_argument( + '--email-on-success', + action='store_true', + default=False, + help='email even if all tests pass', + ) parser.add_argument( '--timeout', help='how many seconds to wait for jobs to finish before emailing results (only applies to the last job in a suite', @@ -209,6 +215,7 @@ def schedule(): if not ctx.last_in_suite: assert not ctx.email, '--email is only applicable to the last job in a suite' assert not ctx.timeout, '--timeout is only applicable to the last job in a suite' + assert not ctx.email_on_success, '--email-on-success is only applicable to the last job in a suite' from teuthology.misc import read_config, get_user if ctx.owner is None: @@ -224,6 +231,7 @@ def schedule(): name=ctx.name, last_in_suite=ctx.last_in_suite, email=ctx.email, + email_on_success=ctx.email_on_success, description=ctx.description, owner=ctx.owner, verbose=ctx.verbose, diff --git a/teuthology/suite.py b/teuthology/suite.py index 3372508cca..364704f0b2 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -56,6 +56,12 @@ combination, and will override anything in the suite. '--email', help='address to email test failures to', ) + parser.add_argument( + '--email-on-success', + action='store_true', + default=False, + help='email even if all tests pass', + ) parser.add_argument( '--timeout', help='how many seconds to wait for jobs to finish before emailing results', @@ -185,6 +191,12 @@ def results(): '--email', help='address to email test failures to', ) + parser.add_argument( + '--email-on-success', + action='store_true', + default=False, + help='email even if all tests pass', + ) parser.add_argument( '--timeout', help='how many seconds to wait for all tests to finish (default no wait)', @@ -251,6 +263,7 @@ def results(): ], ) + descriptions = [] failures = [] unfinished = [] for j in sorted(os.listdir(args.archive_dir)): @@ -265,17 +278,24 @@ def results(): g = yaml.safe_load_all(f) for new in g: summary.update(new) + desc = '{test}: {desc}'.format( + desc=summary['description'], + test=j, + ) + descriptions.append(desc) if not summary['success']: - failures.append('{test}: {desc}'.format( - desc=summary['description'], - test=j, - )) - if (not failures and not unfinished) or not args.email: + failures.append(desc) + + if not args.email or not (failures or unfinished or args.email_on_success): return - import smtplib - from email.mime.text import MIMEText - msg = MIMEText(""" + if failures or unfinished: + subject = '{num_failed} failed and {num_hung} possibly hung tests in {suite}'.format( + num_failed=len(failures), + num_hung=len(unfinished), + suite=args.name, + ) + body = """ The following tests failed: {failures} @@ -285,12 +305,15 @@ These tests may be hung (did not finish in {timeout} seconds after the last test failures='\n'.join(failures), unfinished='\n'.join(unfinished), timeout=args.timeout, - )) - msg['Subject'] = '{num_failed} failed and {num_hung} possibly hung tests in {suite}'.format( - num_failed=len(failures), - num_hung=len(unfinished), - suite=args.name, - ) + ) + else: + subject = 'All tests passed in {suite}!'.format(suite=args.name) + body = '\n'.join(descriptions) + + import smtplib + from email.mime.text import MIMEText + msg = MIMEText(body) + msg['Subject'] = subject msg['From'] = args.teuthology_config['results_sending_email'] msg['To'] = args.email log.debug('sending email %s', msg.as_string()) -- 2.39.5