1# Copyright (c) 2014 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 5import logging 6import os 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.server.cros import moblab_test 10from autotest_lib.server.hosts import moblab_host 11 12 13FAILURE_FOLDERS = ['/usr/local/autotest/results', '/usr/local/autotest/logs'] 14 15 16class moblab_RunSuite(moblab_test.MoblabTest): 17 """ 18 Moblab run suite test. Ensures that a Moblab can run a suite from start 19 to finish by kicking off a suite which will have the Moblab stage an 20 image, provision its DUTs and run the tests. 21 """ 22 version = 1 23 24 25 def run_once(self, host, suite_name, moblab_suite_max_retries): 26 """Runs a suite on a Moblab Host against its test DUTS. 27 28 @param host: Moblab Host that will run the suite. 29 @param suite_name: Name of the suite to run. 30 @param moblab_suite_max_retries: The maximum number of test retries 31 allowed within the suite launched on moblab. 32 33 @raises AutoservRunError if the suite does not complete successfully. 34 """ 35 try: 36 # Fetch the board of the DUT's assigned to this Moblab. There should 37 # only be one type. 38 board = host.afe.get_hosts()[0].platform 39 except IndexError: 40 raise error.TestFail('All hosts for this MobLab are down. Please ' 41 'request the lab admins to take a look.') 42 # TODO (crbug.com/399132) sbasi - Replace repair version with actual 43 # stable_version for the given board. 44 stable_version_map = host.afe.get_stable_version_map( 45 host.afe.CROS_IMAGE_TYPE) 46 build = stable_version_map.get_image_name(board) 47 48 logging.debug('Running suite: %s.', suite_name) 49 try: 50 result = host.run_as_moblab( 51 "%s/site_utils/run_suite.py --pool='' " 52 "--board=%s --build=%s --suite_name=%s --retry=True " 53 "--max_retries=%d" % 54 (moblab_host.AUTOTEST_INSTALL_DIR, board, build, 55 suite_name, moblab_suite_max_retries), timeout=10800) 56 except error.AutoservRunError as e: 57 # Collect the results and logs from the moblab device. 58 moblab_logs_dir = os.path.join(self.resultsdir, 'moblab_logs') 59 for folder in FAILURE_FOLDERS: 60 try: 61 host.get_file(folder, moblab_logs_dir) 62 except error.AutoservRunError as e2: 63 logging.error(e2) 64 pass 65 raise e 66 logging.debug('Suite Run Output:\n%s', result.stdout) 67