David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Generate a report on a given suite run.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import common |
| 11 | import sys |
| 12 | |
David Riley | 237f85c | 2017-03-09 14:26:31 -0800 | [diff] [blame] | 13 | from autotest_lib.server.cros.dynamic_suite import frontend_wrappers |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 14 | from autotest_lib.server.lib import suite_report |
| 15 | from chromite.lib import commandline |
| 16 | from chromite.lib import cros_logging as logging |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame^] | 17 | from chromite.lib import ts_mon_config |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 18 | |
| 19 | def GetParser(): |
| 20 | """Creates the argparse parser.""" |
| 21 | parser = commandline.ArgumentParser(description=__doc__) |
| 22 | parser.add_argument('job_ids', type=int, nargs='+', |
| 23 | help='Suite job ids to dump') |
| 24 | parser.add_argument('--output', '-o', type=str, action='store', |
| 25 | help='Path to write JSON file to') |
David Riley | aca5b01 | 2017-02-22 15:33:23 -0800 | [diff] [blame] | 26 | parser.add_argument('--afe', type=str, action='store', |
| 27 | help='AFE server to connect to') |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 28 | return parser |
| 29 | |
| 30 | |
| 31 | def main(argv): |
| 32 | """Standard main() for command line processing. |
| 33 | |
| 34 | @param argv Command line arguments (normally sys.argv). |
| 35 | """ |
| 36 | |
| 37 | parser = GetParser() |
| 38 | options = parser.parse_args(argv[1:]) |
| 39 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame^] | 40 | with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'): |
David Riley | aca5b01 | 2017-02-22 15:33:23 -0800 | [diff] [blame] | 41 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame^] | 42 | afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10, |
| 43 | server=options.afe) |
| 44 | tko = frontend_wrappers.RetryingTKO(timeout_min=5, delay_sec=10) |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 45 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame^] | 46 | # Look up and generate entries for all jobs. |
| 47 | entries = [] |
| 48 | for suite_job_id in options.job_ids: |
| 49 | logging.debug('Suite job %s:' % suite_job_id) |
| 50 | suite_entries = suite_report.generate_suite_report(suite_job_id, |
| 51 | afe=afe, tko=tko) |
| 52 | logging.debug('... generated %d entries' % len(suite_entries)) |
| 53 | entries.extend(suite_entries) |
| 54 | |
| 55 | # Write all entries as JSON. |
| 56 | if options.output: |
| 57 | with open(options.output, 'w') as f: |
| 58 | suite_report.dump_entries_as_json(entries, f) |
| 59 | else: |
| 60 | suite_report.dump_entries_as_json(entries, sys.stdout) |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | main(sys.argv) |