]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
suite: add option to send an email if the entire suite passed
authorJosh Durgin <josh.durgin@dreamhost.com>
Mon, 29 Aug 2011 19:42:45 +0000 (12:42 -0700)
committerJosh Durgin <josh.durgin@dreamhost.com>
Mon, 29 Aug 2011 19:42:45 +0000 (12:42 -0700)
teuthology/queue.py
teuthology/run.py
teuthology/suite.py

index 5857c4ca8866a8e1a007d65559510a14a99befa8..3caf5e2dba98b4c15b5a6cafd00c12efdc0d5d5e 100644 (file)
@@ -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)
index b4e53f8fdcab0825264307cbfe13047f963d028d..32b54c63051bb1bccd22b138c1f6927fcf1fae2a 100644 (file)
@@ -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,
index 3372508ccaf6eb55813f1cc7c79706ef84c17f30..364704f0b277baf12e59abbefa0b4b922673428c 100644 (file)
@@ -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())