• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
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 argparse
12import logging
13import sys
14
15from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
16from autotest_lib.server.lib import suite_report
17from chromite.lib import ts_mon_config
18
19def GetParser():
20    """Creates the argparse parser."""
21    parser = argparse.ArgumentParser(description=__doc__)
22    parser.add_argument('job_ids', type=int, nargs='+',
23                        help='Suite job ids to dump')
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.')
30    parser.add_argument('--output', '-o', type=str, action='store',
31                        help='Path to write JSON file to')
32    parser.add_argument('--afe', type=str, action='store',
33                        help='AFE server to connect to')
34    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
46    with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'):
47
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)
51
52        job_ids = set(options.job_ids)
53        if options.provision_job_id:
54            job_ids.add(options.provision_job_id)
55
56        # Look up and generate entries for all jobs.
57        entries = []
58        for suite_job_id in job_ids:
59            reset_finish_time = (suite_job_id == options.provision_job_id)
60
61            logging.debug('Suite job %s:' % suite_job_id)
62            suite_entries = suite_report.generate_suite_report(
63                suite_job_id, afe=afe, tko=tko,
64                reset_finish_time=reset_finish_time)
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)
74
75
76if __name__ == '__main__':
77    main(sys.argv)
78