-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)
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:
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,
],
)
smtp.quit()
-def build_email_body(name, archive_dir, timeout):
+def build_email_body(name, archive_dir):
failed = {}
hung = {}
passed = {}