• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Utility to deploy and run result utils on a DUT.
6"""
7
8import logging
9import os
10
11import common
12from autotest_lib.client.common_lib import error
13from autotest_lib.client.common_lib import utils as client_utils
14
15try:
16    from chromite.lib import metrics
17except ImportError:
18    metrics = client_utils.metrics_mock
19
20THROTTLE_OPTION_FMT = '-m %s'
21BUILD_DIR_SUMMARY_CMD = '%s/result_tools/utils.py -p %s %s'
22BUILD_DIR_SUMMARY_TIMEOUT = 120
23
24def run_on_client(host, client_results_dir, enable_result_throttling=False):
25    """Run result utils on the given host.
26
27    @param host: Host to run the result utils.
28    @param client_results_dir: Path to the results directory on the client.
29    @param enable_result_throttling: True to enable result throttling.
30    """
31    with metrics.SecondsTimer(
32            'chromeos/autotest/job/dir_summary_collection_duration',
33            fields={'dut_host_name': host.hostname}):
34        try:
35            logging.debug('Deploy result utilities to %s', host.hostname)
36            host.send_file(os.path.dirname(__file__), host.autodir)
37            logging.debug('Getting directory summary for %s.',
38                          client_results_dir)
39            throttle_option = ''
40            if enable_result_throttling:
41                throttle_option = (THROTTLE_OPTION_FMT %
42                                   host.job.max_result_size_KB)
43            cmd = (BUILD_DIR_SUMMARY_CMD %
44                   (host.autodir, client_results_dir + '/', throttle_option))
45            host.run(cmd, ignore_status=False,
46                     timeout=BUILD_DIR_SUMMARY_TIMEOUT)
47        except error.AutoservRunError:
48            logging.exception(
49                    'Failed to create directory summary for %s.',
50                    client_results_dir)
51