blob: 7d470d83058cb33b1c7f5bd540e1e1259d7ff717 [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/env python2
David Rileyd23d24a2016-10-04 20:07:00 -07002# 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
Mike Frysinger2c3d9c32020-02-06 14:46:40 -050011import logging
David Rileyd23d24a2016-10-04 20:07:00 -070012import sys
13
David Riley237f85c2017-03-09 14:26:31 -080014from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
David Rileyd23d24a2016-10-04 20:07:00 -070015from autotest_lib.server.lib import suite_report
16from chromite.lib import commandline
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')
Ningning Xiabbba11f2018-03-16 13:35:24 -070024 # 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 Rileyd23d24a2016-10-04 20:07:00 -070030 parser.add_argument('--output', '-o', type=str, action='store',
31 help='Path to write JSON file to')
David Rileyaca5b012017-02-22 15:33:23 -080032 parser.add_argument('--afe', type=str, action='store',
33 help='AFE server to connect to')
David Rileyd23d24a2016-10-04 20:07:00 -070034 return parser
35
36
37def 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 Keshet46e65b02017-05-22 10:49:00 -070046 with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'):
David Rileyaca5b012017-02-22 15:33:23 -080047
Aviv Keshet46e65b02017-05-22 10:49:00 -070048 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 Rileyd23d24a2016-10-04 20:07:00 -070051
Ningning Xiabbba11f2018-03-16 13:35:24 -070052 job_ids = set(options.job_ids)
53 if options.provision_job_id:
54 job_ids.add(options.provision_job_id)
55
Aviv Keshet46e65b02017-05-22 10:49:00 -070056 # Look up and generate entries for all jobs.
57 entries = []
Ningning Xiabbba11f2018-03-16 13:35:24 -070058 for suite_job_id in job_ids:
59 reset_finish_time = (suite_job_id == options.provision_job_id)
60
Aviv Keshet46e65b02017-05-22 10:49:00 -070061 logging.debug('Suite job %s:' % suite_job_id)
Ningning Xiabbba11f2018-03-16 13:35:24 -070062 suite_entries = suite_report.generate_suite_report(
63 suite_job_id, afe=afe, tko=tko,
64 reset_finish_time=reset_finish_time)
Aviv Keshet46e65b02017-05-22 10:49:00 -070065 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 Rileyd23d24a2016-10-04 20:07:00 -070074
75
76if __name__ == '__main__':
77 main(sys.argv)