Home | History | Annotate | Download | only in site_utils
      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 
      8 from __future__ import print_function
      9 
     10 import common
     11 import sys
     12 
     13 from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
     14 from autotest_lib.server.lib import suite_report
     15 from chromite.lib import commandline
     16 from chromite.lib import cros_logging as logging
     17 
     18 def 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')
     25     parser.add_argument('--afe', type=str, action='store',
     26                         help='AFE server to connect to')
     27     return parser
     28 
     29 
     30 def 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 
     39     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)
     42 
     43     # 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)
     47         suite_entries = suite_report.generate_suite_report(suite_job_id,
     48                                                            afe=afe, tko=tko)
     49         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 
     60 if __name__ == '__main__':
     61     main(sys.argv)
     62