1# Copyright (c) 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"""Host object for Jetstream devices. 6 7Host customization provided for fine-tuning autotest reset, verification, 8and provisioning on Jetstream devices. A more customized host wrapper is 9typicaly used in Jetstream autotests. 10""" 11 12import logging 13 14import common 15from autotest_lib.client.common_lib import error 16from autotest_lib.client.common_lib import lsbrelease_utils 17from autotest_lib.server.hosts import cros_host 18from autotest_lib.server.hosts import cros_repair 19 20 21# Presence of any of these processes indicates that the host is up: 22BOOT_DETECTION_PROCESSES = ('ap-controller',) 23 24# Maximum time for host to report is_up after rebooting 25BOOT_TIMEOUT_SECONDS = 180 26 27# Maximum time for host to recover after resetting 28RESET_TIMEOUT_SECONDS = 60 29 30 31class JetstreamHost(cros_host.CrosHost): 32 """Jetstream-specific host class.""" 33 34 @staticmethod 35 def check_host(host, timeout=10): 36 """ 37 Check if the given host is jetstream host. 38 39 @param host: An ssh host representing a device. 40 @param timeout: The timeout for the run command. 41 42 @return: True if the host is a Jetstream device, otherwise False. 43 """ 44 try: 45 lsb_release_content = host.run( 46 'grep CHROMEOS_RELEASE_BOARD /etc/lsb-release').stdout 47 return lsbrelease_utils.is_jetstream( 48 lsb_release_content=lsb_release_content) 49 except (error.AutoservRunError, error.AutoservSSHTimeout): 50 return False 51 52 def _initialize(self, *args, **dargs): 53 logging.debug('Initializing Jetstream host') 54 super(JetstreamHost, self)._initialize(*args, **dargs) 55 # Overwrite base class initialization 56 self._repair_strategy = cros_repair.create_jetstream_repair_strategy() 57 58 def get_os_type(self): 59 return 'jetstream' 60 61 def get_wait_up_processes(self): 62 return BOOT_DETECTION_PROCESSES 63 64 def verify(self): 65 # Whirlwind takes longer to start all system services, so check 66 # that ap-controller is running before verifying, crbug/739583. 67 self.wait_up(timeout=BOOT_TIMEOUT_SECONDS) 68 logging.debug('Jetstream host is up, starting verification') 69 super(JetstreamHost, self).verify() 70 71 def cleanup_services(self): 72 """Restores the host to default settings. 73 74 @raises AutoservRunError: on failure. 75 """ 76 logging.debug('Jetstream: Resetting AP services') 77 # This is a 'fake' factory reset which restores the DUT to 78 # its default state and restarts AP services. 79 self.run('sudo ap-configure --factory_reset', ignore_status=False) 80 self.wait_up(timeout=RESET_TIMEOUT_SECONDS) 81 82 # Stop service ap-update-manager to prevent rebooting during autoupdate. 83 self.run('sudo stop ap-update-manager', ignore_status=False) 84 85 def prepare_for_update(self): 86 """Prepare the host for an update.""" 87 logging.debug('Jetstream: Prepare for update') 88 try: 89 self.cleanup_services() 90 except error.AutoservRunError: 91 logging.exception('Failed to reset host') 92