From 8fbd087d6bfac987d0f95ec55e620ec22fb6974d Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 15 Mar 2012 16:21:33 -0700 Subject: [PATCH] results: make sure email is sent before anything else fails --- teuthology/suite.py | 64 ++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/teuthology/suite.py b/teuthology/suite.py index 3aed2e018b02e..56edceef6803b 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -205,6 +205,33 @@ def ls(): if args.verbose and 'failure_reason' in summary: print ' {reason}'.format(reason=summary['failure_reason']) +def generate_coverage(args): + subprocess.Popen( + args=[ + os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-coverage'), + '-v', + '-o', + os.path.join(args.teuthology_config['coverage_output_dir'], args.name), + '--html-output', + os.path.join(args.teuthology_config['coverage_html_dir'], args.name), + '--cov-tools-dir', + args.teuthology_config['coverage_tools_dir'], + args.archive_dir, + ], + ) + +def email_results(subject, from_, to, body): + import smtplib + from email.mime.text import MIMEText + msg = MIMEText(body) + msg['Subject'] = subject + msg['From'] = from_ + msg['To'] = to + log.debug('sending email %s', msg.as_string()) + smtp = smtplib.SMTP('localhost') + smtp.sendmail(msg['From'], [msg['To']], msg.as_string()) + smtp.quit() + def results(): parser = argparse.ArgumentParser(description='Email teuthology suite results') parser.add_argument( @@ -263,20 +290,6 @@ def results(): break time.sleep(10) - subprocess.Popen( - args=[ - os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-coverage'), - '-v', - '-o', - os.path.join(args.teuthology_config['coverage_output_dir'], args.name), - '--html-output', - os.path.join(args.teuthology_config['coverage_html_dir'], args.name), - '--cov-tools-dir', - args.teuthology_config['coverage_tools_dir'], - args.archive_dir, - ], - ) - descriptions = [] failures = [] num_failures = 0 @@ -311,9 +324,6 @@ def results(): reason=summary['failure_reason'], )) - if not args.email: - return - if failures or unfinished: subject = ('{num_failed} failed, {num_hung} possibly hung, ' 'and {num_passed} passed tests in {suite}'.format( @@ -341,13 +351,13 @@ These tests passed: 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()) - smtp = smtplib.SMTP('localhost') - smtp.sendmail(msg['From'], [msg['To']], msg.as_string()) - smtp.quit() + try: + if args.email: + email_results( + subject=subject, + from_=args.teuthology_config['results_sending_email'], + to=args.email, + body=body, + ) + finally: + generate_coverage(args) -- 2.39.5