blob: 21ecba90fbf35ff482348fc3f420dbe32f9dcac0 [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
Aviv Keshet46e65b02017-05-22 10:49:00 -070017from chromite.lib import ts_mon_config
David Rileyd23d24a2016-10-04 20:07:00 -070018
19def 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 Rileyaca5b012017-02-22 15:33:23 -080026 parser.add_argument('--afe', type=str, action='store',
27 help='AFE server to connect to')
David Rileyd23d24a2016-10-04 20:07:00 -070028 return parser
29
30
31def 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 Keshet46e65b02017-05-22 10:49:00 -070040 with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'):
David Rileyaca5b012017-02-22 15:33:23 -080041
Aviv Keshet46e65b02017-05-22 10:49:00 -070042 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 Rileyd23d24a2016-10-04 20:07:00 -070045
Aviv Keshet46e65b02017-05-22 10:49:00 -070046 # 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 Rileyd23d24a2016-10-04 20:07:00 -070061
62
63if __name__ == '__main__':
64 main(sys.argv)