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): 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 31 @raises AutoservRunError if the suite does not complete successfully. 32 """ 33 try: 34 # Fetch the board of the DUT's assigned to this Moblab. There should 35 # only be one type. 36 board = host.afe.get_hosts()[0].platform 37 except IndexError: 38 raise error.TestFail('All hosts for this MobLab are down. Please ' 39 'request the lab admins to take a look.') 40 # TODO (crbug.com/399132) sbasi - Replace repair version with actual 41 # stable_version for the given board. 42 stable_version_map = host.afe.get_stable_version_map( 43 host.afe.CROS_IMAGE_TYPE) 44 build = stable_version_map.get_image_name(board) 45 46 logging.debug('Running suite: %s.', suite_name) 47 try: 48 result = host.run_as_moblab( 49 "%s/site_utils/run_suite.py --pool='' " 50 "--board=%s --build=%s --suite_name=%s" % 51 (moblab_host.AUTOTEST_INSTALL_DIR, board, build, 52 suite_name), timeout=10800) 53 except error.AutoservRunError as e: 54 # Collect the results and logs from the moblab device. 55 moblab_logs_dir = os.path.join(self.resultsdir, 'moblab_logs') 56 for folder in FAILURE_FOLDERS: 57 try: 58 host.get_file(folder, moblab_logs_dir) 59 except error.AutoservRunError as e2: 60 logging.error(e2) 61 pass 62 raise e 63 logging.debug('Suite Run Output:\n%s', result.stdout) 64