]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Use docopt instead of argparse
authorZack Cerza <zack.cerza@inktank.com>
Tue, 11 Nov 2014 17:36:29 +0000 (10:36 -0700)
committerZack Cerza <zack.cerza@inktank.com>
Wed, 12 Nov 2014 18:00:39 +0000 (11:00 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
scripts/results.py
teuthology/results.py
teuthology/test/test_results.py

index b857c53c46b0a2b244de04410bde093ae01594fa..73b417ab30d0f8ce105fa4a92f5b960a259be60b 100644 (file)
@@ -1,40 +1,21 @@
-import argparse
+"""
+usage: teuthology-results [-h] [-v] [--email EMAIL] [--timeout TIMEOUT] --archive-dir DIR --name NAME
 
+Email teuthology suite results
+
+optional arguments:
+  -h, --help         show this help message and exit
+  -v, --verbose      be more verbose
+  --email EMAIL      address to email test failures to
+  --timeout TIMEOUT  how many seconds to wait for all tests to finish (default
+                     no wait)
+  --archive-dir DIR  path under which results for the suite are stored
+  --name NAME        name of the suite
+"""
+import docopt
 import teuthology.results
 
 
 def main():
-    teuthology.results.main(parse_args())
-
-
-def parse_args():
-    parser = argparse.ArgumentParser(
-        description='Email teuthology suite results')
-    parser.add_argument(
-        '--email',
-        help='address to email test failures to',
-    )
-    parser.add_argument(
-        '--timeout',
-        help='how many seconds to wait for all tests to finish (default no ' +
-        'wait)',
-        type=int,
-        default=0,
-    )
-    parser.add_argument(
-        '--archive-dir',
-        metavar='DIR',
-        help='path under which results for the suite are stored',
-        required=True,
-    )
-    parser.add_argument(
-        '--name',
-        help='name of the suite',
-        required=True,
-    )
-    parser.add_argument(
-        '-v', '--verbose',
-        action='store_true', default=False,
-        help='be more verbose',
-    )
-    return parser.parse_args()
+    args = docopt.docopt(__doc__)
+    teuthology.results.main(args)
index daa14fafea79c9a2f7ba4845145992082437f210..20274f39475ea650d37e62af5d57fb5e672b24d7 100644 (file)
@@ -20,49 +20,49 @@ log = logging.getLogger(__name__)
 def main(args):
 
     log = logging.getLogger(__name__)
-    if args.verbose:
+    if args['--verbose']:
         teuthology.log.setLevel(logging.DEBUG)
 
-    log_path = os.path.join(args.archive_dir, 'results.log')
+    log_path = os.path.join(args['--archive-dir'], 'results.log')
     teuthology.setup_log_file(log_path)
 
     try:
-        results(args)
+        results(args['--archive-dir'], args['--name'], args['--email'],
+                args['--timeout'])
     except Exception:
         log.exception('error generating results')
         raise
 
 
-def results(args):
-    archive_base = os.path.split(args.archive_dir)[0]
+def results(archive_dir, name, email, timeout):
+    archive_base = os.path.split(archive_dir)[0]
     serializer = ResultsSerializer(archive_base)
     starttime = time.time()
 
-    log.info('Waiting up to %d seconds for tests to finish...', args.timeout)
-    while serializer.running_jobs_for_run(args.name) and args.timeout > 0:
-        if time.time() - starttime > args.timeout:
+    log.info('Waiting up to %d seconds for tests to finish...', timeout)
+    while serializer.running_jobs_for_run(name) and timeout > 0:
+        if time.time() - starttime > timeout:
             log.warn('test(s) did not finish before timeout of %d seconds',
-                     args.timeout)
+                     timeout)
             break
         time.sleep(10)
     log.info('Tests finished! gathering results...')
 
-    (subject, body) = build_email_body(args.name, args.archive_dir,
-                                       args.timeout)
+    (subject, body) = build_email_body(name, archive_dir)
 
     try:
-        if args.email:
+        if email:
             email_results(
                 subject=subject,
                 from_=config.results_sending_email or 'teuthology',
-                to=args.email,
+                to=email,
                 body=body,
             )
     finally:
-        generate_coverage(args)
+        generate_coverage(archive_dir, name)
 
 
-def generate_coverage(args):
+def generate_coverage(archive_dir, name):
     coverage_config_keys = ('coverage_output_dir', 'coverage_html_dir',
                             'coverage_tools_dir')
     for key in coverage_config_keys:
@@ -77,12 +77,12 @@ def generate_coverage(args):
             os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-coverage'),
             '-v',
             '-o',
-            os.path.join(config.coverage_output_dir, args.name),
+            os.path.join(config.coverage_output_dir, name),
             '--html-output',
-            os.path.join(config.coverage_html_dir, args.name),
+            os.path.join(config.coverage_html_dir, name),
             '--cov-tools-dir',
             config.coverage_tools_dir,
-            args.archive_dir,
+            archive_dir,
         ],
     )
 
@@ -101,7 +101,7 @@ def email_results(subject, from_, to, body):
     smtp.quit()
 
 
-def build_email_body(name, archive_dir, timeout):
+def build_email_body(name, archive_dir):
     failed = {}
     hung = {}
     passed = {}
index f635b29c4fb664283e0702f662d6fdeca14626d0..32f3b360601b506a8e91417ca1da9c3358a04017 100644 (file)
@@ -86,8 +86,6 @@ class TestResultsEmail(object):
         self.archive.populate_archive(run_name, self.reference['jobs'])
         (subject, body) = results.build_email_body(
             run_name,
-            run_dir,
-            36000)
+            run_dir)
         assert subject == self.reference['subject']
-        print body
         assert body == self.reference['body']