Mike Frysinger | d03e6b5 | 2019-08-03 12:49:01 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 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 |
Mike Frysinger | 2c3d9c3 | 2020-02-06 14:46:40 -0500 | [diff] [blame] | 11 | import logging |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 12 | import sys |
| 13 | |
David Riley | 237f85c | 2017-03-09 14:26:31 -0800 | [diff] [blame] | 14 | from autotest_lib.server.cros.dynamic_suite import frontend_wrappers |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 15 | from autotest_lib.server.lib import suite_report |
| 16 | from chromite.lib import commandline |
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') |
Ningning Xia | bbba11f | 2018-03-16 13:35:24 -0700 | [diff] [blame] | 24 | # As a provision suite may exit before its all provision jobs finish, the |
| 25 | # provision suite report may not contain all the provision jobs. This hack |
| 26 | # helps to dump report for all provision jobs under the given provision |
| 27 | # suite (provision-job-id). See more details in crbug.com/794346 |
| 28 | parser.add_argument('--provision-job-id', type=int, |
| 29 | help='Provision suite job id to dump report.') |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 30 | parser.add_argument('--output', '-o', type=str, action='store', |
| 31 | help='Path to write JSON file to') |
David Riley | aca5b01 | 2017-02-22 15:33:23 -0800 | [diff] [blame] | 32 | parser.add_argument('--afe', type=str, action='store', |
| 33 | help='AFE server to connect to') |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 34 | return parser |
| 35 | |
| 36 | |
| 37 | def main(argv): |
| 38 | """Standard main() for command line processing. |
| 39 | |
| 40 | @param argv Command line arguments (normally sys.argv). |
| 41 | """ |
| 42 | |
| 43 | parser = GetParser() |
| 44 | options = parser.parse_args(argv[1:]) |
| 45 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame] | 46 | with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'): |
David Riley | aca5b01 | 2017-02-22 15:33:23 -0800 | [diff] [blame] | 47 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame] | 48 | afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10, |
| 49 | server=options.afe) |
| 50 | tko = frontend_wrappers.RetryingTKO(timeout_min=5, delay_sec=10) |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 51 | |
Ningning Xia | bbba11f | 2018-03-16 13:35:24 -0700 | [diff] [blame] | 52 | job_ids = set(options.job_ids) |
| 53 | if options.provision_job_id: |
| 54 | job_ids.add(options.provision_job_id) |
| 55 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame] | 56 | # Look up and generate entries for all jobs. |
| 57 | entries = [] |
Ningning Xia | bbba11f | 2018-03-16 13:35:24 -0700 | [diff] [blame] | 58 | for suite_job_id in job_ids: |
| 59 | reset_finish_time = (suite_job_id == options.provision_job_id) |
| 60 | |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame] | 61 | logging.debug('Suite job %s:' % suite_job_id) |
Ningning Xia | bbba11f | 2018-03-16 13:35:24 -0700 | [diff] [blame] | 62 | suite_entries = suite_report.generate_suite_report( |
| 63 | suite_job_id, afe=afe, tko=tko, |
| 64 | reset_finish_time=reset_finish_time) |
Aviv Keshet | 46e65b0 | 2017-05-22 10:49:00 -0700 | [diff] [blame] | 65 | logging.debug('... generated %d entries' % len(suite_entries)) |
| 66 | entries.extend(suite_entries) |
| 67 | |
| 68 | # Write all entries as JSON. |
| 69 | if options.output: |
| 70 | with open(options.output, 'w') as f: |
| 71 | suite_report.dump_entries_as_json(entries, f) |
| 72 | else: |
| 73 | suite_report.dump_entries_as_json(entries, sys.stdout) |
David Riley | d23d24a | 2016-10-04 20:07:00 -0700 | [diff] [blame] | 74 | |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | main(sys.argv) |