• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8from __future__ import print_function
9
10import common
11import sys
12
13from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
14from autotest_lib.server.lib import suite_report
15from chromite.lib import commandline
16from chromite.lib import cros_logging as logging
17from chromite.lib import ts_mon_config
18
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')
26    parser.add_argument('--afe', type=str, action='store',
27                        help='AFE server to connect to')
28    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
40    with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'):
41
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)
45
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)
61
62
63if __name__ == '__main__':
64    main(sys.argv)
65