blob: e2f80c6ca6a95237df3e7146196a1af62554050f [file] [log] [blame]
David Rileyd23d24a2016-10-04 20:07:00 -07001#!/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
8from __future__ import print_function
9
10import common
11import sys
12
David Riley237f85c2017-03-09 14:26:31 -080013from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
David Rileyd23d24a2016-10-04 20:07:00 -070014from autotest_lib.server.lib import suite_report
15from chromite.lib import commandline
16from chromite.lib import cros_logging as logging
17
18def GetParser():
19 """Creates the argparse parser."""
20 parser = commandline.ArgumentParser(description=__doc__)
21 parser.add_argument('job_ids', type=int, nargs='+',
22 help='Suite job ids to dump')
23 parser.add_argument('--output', '-o', type=str, action='store',
24 help='Path to write JSON file to')
David Rileyaca5b012017-02-22 15:33:23 -080025 parser.add_argument('--afe', type=str, action='store',
26 help='AFE server to connect to')
David Rileyd23d24a2016-10-04 20:07:00 -070027 return parser
28
29
30def main(argv):
31 """Standard main() for command line processing.
32
33 @param argv Command line arguments (normally sys.argv).
34 """
35
36 parser = GetParser()
37 options = parser.parse_args(argv[1:])
38
David Riley237f85c2017-03-09 14:26:31 -080039 afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10,
40 server=options.afe)
41 tko = frontend_wrappers.RetryingTKO(timeout_min=5, delay_sec=10)
David Rileyaca5b012017-02-22 15:33:23 -080042
David Rileyd23d24a2016-10-04 20:07:00 -070043 # Look up and generate entries for all jobs.
44 entries = []
45 for suite_job_id in options.job_ids:
46 logging.debug('Suite job %s:' % suite_job_id)
David Rileyaca5b012017-02-22 15:33:23 -080047 suite_entries = suite_report.generate_suite_report(suite_job_id,
David Riley237f85c2017-03-09 14:26:31 -080048 afe=afe, tko=tko)
David Rileyd23d24a2016-10-04 20:07:00 -070049 logging.debug('... generated %d entries' % len(suite_entries))
50 entries.extend(suite_entries)
51
52 # Write all entries as JSON.
53 if options.output:
54 with open(options.output, 'w') as f:
55 suite_report.dump_entries_as_json(entries, f)
56 else:
57 suite_report.dump_entries_as_json(entries, sys.stdout)
58
59
60if __name__ == '__main__':
61 main(sys.argv)