J. Richard Barnette | 24adbf4 | 2012-04-11 15:04:53 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Dale Curtis | aa5eedb | 2011-08-23 16:18:52 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Aviv Keshet | 74c89a9 | 2013-02-04 15:18:30 -0800 | [diff] [blame] | 5 | import functools |
J. Richard Barnette | 1d78b01 | 2012-05-15 13:56:30 -0700 | [diff] [blame] | 6 | import logging |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 7 | import os |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 8 | import re |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 9 | import time |
| 10 | |
mussa | 584b446 | 2014-06-20 15:13:28 -0700 | [diff] [blame] | 11 | import common |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 12 | from autotest_lib.client.bin import utils |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 13 | from autotest_lib.client.common_lib import autotemp |
Richard Barnette | 0c73ffc | 2012-11-19 15:21:18 -0800 | [diff] [blame] | 14 | from autotest_lib.client.common_lib import error |
| 15 | from autotest_lib.client.common_lib import global_config |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 16 | from autotest_lib.client.common_lib import lsbrelease_utils |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 17 | from autotest_lib.client.common_lib.cros import autoupdater |
Richard Barnette | 03a0c13 | 2012-11-05 12:40:35 -0800 | [diff] [blame] | 18 | from autotest_lib.client.common_lib.cros import dev_server |
Gabe Black | b72f4fb | 2015-01-20 16:47:13 -0800 | [diff] [blame] | 19 | from autotest_lib.client.common_lib.cros.graphite import autotest_es |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 20 | from autotest_lib.client.common_lib.cros.graphite import autotest_stats |
Hsinyu Chao | e0b08e6 | 2015-08-11 10:50:37 +0000 | [diff] [blame] | 21 | from autotest_lib.client.cros import constants as client_constants |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 22 | from autotest_lib.client.cros import cros_ui |
Cheng-Yi Chiang | f4104ff | 2014-12-23 19:39:01 +0800 | [diff] [blame] | 23 | from autotest_lib.client.cros.audio import cras_utils |
Katherine Threlkeld | ab83d39 | 2015-06-18 16:45:57 -0700 | [diff] [blame] | 24 | from autotest_lib.client.cros.input_playback import input_playback |
Mussa | 5b58905 | 2015-10-26 17:55:26 -0700 | [diff] [blame] | 25 | from autotest_lib.client.cros.video import constants as video_test_constants |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 26 | from autotest_lib.server import autoserv_parser |
| 27 | from autotest_lib.server import autotest |
| 28 | from autotest_lib.server import constants |
| 29 | from autotest_lib.server import crashcollect |
Dan Shi | a1ecd5c | 2013-06-06 11:21:31 -0700 | [diff] [blame] | 30 | from autotest_lib.server import utils as server_utils |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 31 | from autotest_lib.server.cros import provision |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 32 | from autotest_lib.server.cros.dynamic_suite import constants as ds_constants |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 33 | from autotest_lib.server.cros.dynamic_suite import tools, frontend_wrappers |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 34 | from autotest_lib.server.cros.faft.config.config import Config as FAFTConfig |
Fang Deng | 96667ca | 2013-08-01 17:46:18 -0700 | [diff] [blame] | 35 | from autotest_lib.server.hosts import abstract_ssh |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 36 | from autotest_lib.server.hosts import chameleon_host |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 37 | from autotest_lib.server.hosts import servo_host |
Simran Basi | dcff425 | 2012-11-20 16:13:20 -0800 | [diff] [blame] | 38 | from autotest_lib.site_utils.rpm_control_system import rpm_client |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 39 | |
| 40 | |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 41 | CONFIG = global_config.global_config |
| 42 | |
Eric Caruso | ee673ac | 2015-08-05 17:03:04 -0700 | [diff] [blame] | 43 | LUCID_SLEEP_BOARDS = ['samus', 'lulu'] |
| 44 | |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 45 | # A file to indicate provision failure and require Repair job to powerwash the |
| 46 | # dut. |
| 47 | PROVISION_FAILED = '/var/tmp/provision_failed' |
| 48 | |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 49 | class FactoryImageCheckerException(error.AutoservError): |
| 50 | """Exception raised when an image is a factory image.""" |
| 51 | pass |
| 52 | |
| 53 | |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 54 | class CrosHost(abstract_ssh.AbstractSSHHost): |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 55 | """Chromium OS specific subclass of Host.""" |
| 56 | |
| 57 | _parser = autoserv_parser.autoserv_parser |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 58 | _AFE = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10) |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 59 | |
Richard Barnette | 03a0c13 | 2012-11-05 12:40:35 -0800 | [diff] [blame] | 60 | # Timeout values (in seconds) associated with various Chrome OS |
| 61 | # state changes. |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 62 | # |
Richard Barnette | 0c73ffc | 2012-11-19 15:21:18 -0800 | [diff] [blame] | 63 | # In general, a good rule of thumb is that the timeout can be up |
| 64 | # to twice the typical measured value on the slowest platform. |
| 65 | # The times here have not necessarily been empirically tested to |
| 66 | # meet this criterion. |
J. Richard Barnette | eb69d72 | 2012-06-18 17:29:44 -0700 | [diff] [blame] | 67 | # |
| 68 | # SLEEP_TIMEOUT: Time to allow for suspend to memory. |
Richard Barnette | 0c73ffc | 2012-11-19 15:21:18 -0800 | [diff] [blame] | 69 | # RESUME_TIMEOUT: Time to allow for resume after suspend, plus |
| 70 | # time to restart the netwowrk. |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 71 | # SHUTDOWN_TIMEOUT: Time to allow for shut down. |
J. Richard Barnette | eb69d72 | 2012-06-18 17:29:44 -0700 | [diff] [blame] | 72 | # BOOT_TIMEOUT: Time to allow for boot from power off. Among |
Richard Barnette | 0c73ffc | 2012-11-19 15:21:18 -0800 | [diff] [blame] | 73 | # other things, this must account for the 30 second dev-mode |
J. Richard Barnette | 417cc79 | 2015-10-01 09:56:36 -0700 | [diff] [blame] | 74 | # screen delay, time to start the network on the DUT, and the |
| 75 | # ssh timeout of 120 seconds. |
J. Richard Barnette | eb69d72 | 2012-06-18 17:29:44 -0700 | [diff] [blame] | 76 | # USB_BOOT_TIMEOUT: Time to allow for boot from a USB device, |
Richard Barnette | 0c73ffc | 2012-11-19 15:21:18 -0800 | [diff] [blame] | 77 | # including the 30 second dev-mode delay and time to start the |
J. Richard Barnette | d4649c6 | 2013-03-06 17:42:27 -0800 | [diff] [blame] | 78 | # network. |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 79 | # INSTALL_TIMEOUT: Time to allow for chromeos-install. |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 80 | # POWERWASH_BOOT_TIMEOUT: Time to allow for a reboot that |
| 81 | # includes powerwash. |
J. Richard Barnette | eb69d72 | 2012-06-18 17:29:44 -0700 | [diff] [blame] | 82 | |
| 83 | SLEEP_TIMEOUT = 2 |
J. Richard Barnette | d4649c6 | 2013-03-06 17:42:27 -0800 | [diff] [blame] | 84 | RESUME_TIMEOUT = 10 |
Tom Wai-Hong Tam | fe005c2 | 2014-12-03 09:25:44 +0800 | [diff] [blame] | 85 | SHUTDOWN_TIMEOUT = 10 |
J. Richard Barnette | 417cc79 | 2015-10-01 09:56:36 -0700 | [diff] [blame] | 86 | BOOT_TIMEOUT = 150 |
J. Richard Barnette | 5bab5f5 | 2015-08-03 13:14:38 -0700 | [diff] [blame] | 87 | USB_BOOT_TIMEOUT = 300 |
J. Richard Barnette | 7817b05 | 2014-08-28 09:47:29 -0700 | [diff] [blame] | 88 | INSTALL_TIMEOUT = 480 |
Dan Shi | 2c88eed | 2013-11-12 10:18:38 -0800 | [diff] [blame] | 89 | POWERWASH_BOOT_TIMEOUT = 60 |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 90 | |
Dan Shi | ca50348 | 2015-03-30 17:23:25 -0700 | [diff] [blame] | 91 | # Minimum OS version that supports server side packaging. Older builds may |
| 92 | # not have server side package built or with Autotest code change to support |
| 93 | # server-side packaging. |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 94 | MIN_VERSION_SUPPORT_SSP = CONFIG.get_config_value( |
Dan Shi | ced09e4 | 2015-04-17 16:09:34 -0700 | [diff] [blame] | 95 | 'AUTOSERV', 'min_version_support_ssp', type=int) |
Dan Shi | ca50348 | 2015-03-30 17:23:25 -0700 | [diff] [blame] | 96 | |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 97 | # REBOOT_TIMEOUT: How long to wait for a reboot. |
| 98 | # |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 99 | # We have a long timeout to ensure we don't flakily fail due to other |
| 100 | # issues. Shorter timeouts are vetted in platform_RebootAfterUpdate. |
Simran Basi | 1160e2c | 2013-10-04 16:00:24 -0700 | [diff] [blame] | 101 | # TODO(sbasi - crbug.com/276094) Restore to 5 mins once the 'host did not |
| 102 | # return from reboot' bug is solved. |
| 103 | REBOOT_TIMEOUT = 480 |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 104 | |
Ismail Noorbasha | 07fdb61 | 2013-02-14 14:13:31 -0800 | [diff] [blame] | 105 | # _USB_POWER_TIMEOUT: Time to allow for USB to power toggle ON and OFF. |
| 106 | # _POWER_CYCLE_TIMEOUT: Time to allow for manual power cycle. |
| 107 | _USB_POWER_TIMEOUT = 5 |
| 108 | _POWER_CYCLE_TIMEOUT = 10 |
| 109 | |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 110 | _RPM_RECOVERY_BOARDS = CONFIG.get_config_value('CROS', |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 111 | 'rpm_recovery_boards', type=str).split(',') |
| 112 | |
| 113 | _MAX_POWER_CYCLE_ATTEMPTS = 6 |
| 114 | _LAB_MACHINE_FILE = '/mnt/stateful_partition/.labmachine' |
Fang Deng | deba14f | 2014-11-14 11:54:09 -0800 | [diff] [blame] | 115 | _RPM_HOSTNAME_REGEX = ('chromeos(\d+)(-row(\d+))?-rack(\d+[a-z]*)' |
| 116 | '-host(\d+)') |
Katherine Threlkeld | ab83d39 | 2015-06-18 16:45:57 -0700 | [diff] [blame] | 117 | _LIGHTSENSOR_FILES = [ "in_illuminance0_input", |
| 118 | "in_illuminance_input", |
| 119 | "in_illuminance0_raw", |
| 120 | "in_illuminance_raw", |
| 121 | "illuminance0_input"] |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 122 | _LIGHTSENSOR_SEARCH_DIR = '/sys/bus/iio/devices' |
| 123 | _LABEL_FUNCTIONS = [] |
Aviv Keshet | 74c89a9 | 2013-02-04 15:18:30 -0800 | [diff] [blame] | 124 | _DETECTABLE_LABELS = [] |
Kevin Cheng | 3a4a57a | 2015-09-30 12:09:50 -0700 | [diff] [blame] | 125 | label_decorator = functools.partial(server_utils.add_label_detector, |
| 126 | _LABEL_FUNCTIONS, |
Aviv Keshet | 74c89a9 | 2013-02-04 15:18:30 -0800 | [diff] [blame] | 127 | _DETECTABLE_LABELS) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 128 | |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 129 | # Constants used in ping_wait_up() and ping_wait_down(). |
| 130 | # |
| 131 | # _PING_WAIT_COUNT is the approximate number of polling |
| 132 | # cycles to use when waiting for a host state change. |
| 133 | # |
| 134 | # _PING_STATUS_DOWN and _PING_STATUS_UP are names used |
| 135 | # for arguments to the internal _ping_wait_for_status() |
| 136 | # method. |
| 137 | _PING_WAIT_COUNT = 40 |
| 138 | _PING_STATUS_DOWN = False |
| 139 | _PING_STATUS_UP = True |
| 140 | |
Ismail Noorbasha | 07fdb61 | 2013-02-14 14:13:31 -0800 | [diff] [blame] | 141 | # Allowed values for the power_method argument. |
| 142 | |
| 143 | # POWER_CONTROL_RPM: Passed as default arg for power_off/on/cycle() methods. |
| 144 | # POWER_CONTROL_SERVO: Used in set_power() and power_cycle() methods. |
| 145 | # POWER_CONTROL_MANUAL: Used in set_power() and power_cycle() methods. |
| 146 | POWER_CONTROL_RPM = 'RPM' |
| 147 | POWER_CONTROL_SERVO = 'servoj10' |
| 148 | POWER_CONTROL_MANUAL = 'manual' |
| 149 | |
| 150 | POWER_CONTROL_VALID_ARGS = (POWER_CONTROL_RPM, |
| 151 | POWER_CONTROL_SERVO, |
| 152 | POWER_CONTROL_MANUAL) |
Richard Barnette | 0c73ffc | 2012-11-19 15:21:18 -0800 | [diff] [blame] | 153 | |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 154 | _RPM_OUTLET_CHANGED = 'outlet_changed' |
| 155 | |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 156 | # URL pattern to download firmware image. |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 157 | _FW_IMAGE_URL_PATTERN = CONFIG.get_config_value( |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 158 | 'CROS', 'firmware_url_pattern', type=str) |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 159 | |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 160 | # File that has a list of directories to be collected |
| 161 | _LOGS_TO_COLLECT_FILE = os.path.join( |
| 162 | common.client_dir, 'common_lib', 'logs_to_collect') |
| 163 | |
| 164 | # Prefix of logging message w.r.t. crash collection |
| 165 | _CRASHLOGS_PREFIX = 'collect_crashlogs' |
| 166 | |
| 167 | # Time duration waiting for host up/down check |
| 168 | _CHECK_HOST_UP_TIMEOUT_SECS = 15 |
| 169 | |
| 170 | # A command that interacts with kernel and hardware (e.g., rm, mkdir, etc) |
| 171 | # might not be completely done deep through the hardware when the machine |
| 172 | # is powered down right after the command returns. |
| 173 | # We should wait for a few seconds to make them done. Finger crossed. |
| 174 | _SAFE_WAIT_SECS = 10 |
| 175 | |
| 176 | |
J. Richard Barnette | 964fba0 | 2012-10-24 17:34:29 -0700 | [diff] [blame] | 177 | @staticmethod |
beeps | 46dadc9 | 2013-11-07 14:07:10 -0800 | [diff] [blame] | 178 | def check_host(host, timeout=10): |
| 179 | """ |
| 180 | Check if the given host is a chrome-os host. |
| 181 | |
| 182 | @param host: An ssh host representing a device. |
| 183 | @param timeout: The timeout for the run command. |
| 184 | |
| 185 | @return: True if the host device is chromeos. |
| 186 | |
beeps | 46dadc9 | 2013-11-07 14:07:10 -0800 | [diff] [blame] | 187 | """ |
| 188 | try: |
Simran Basi | 933c8af | 2015-04-29 14:05:07 -0700 | [diff] [blame] | 189 | result = host.run( |
| 190 | 'grep -q CHROMEOS /etc/lsb-release && ' |
| 191 | '! test -f /mnt/stateful_partition/.android_tester && ' |
| 192 | '! grep -q moblab /etc/lsb-release', |
| 193 | ignore_status=True, timeout=timeout) |
beeps | 46dadc9 | 2013-11-07 14:07:10 -0800 | [diff] [blame] | 194 | except (error.AutoservRunError, error.AutoservSSHTimeout): |
| 195 | return False |
| 196 | return result.exit_status == 0 |
| 197 | |
| 198 | |
| 199 | @staticmethod |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 200 | def _extract_arguments(args_dict, key_subset): |
| 201 | """Extract options from `args_dict` and return a subset result. |
J. Richard Barnette | 7214e0b | 2013-02-06 15:20:49 -0800 | [diff] [blame] | 202 | |
| 203 | Take the provided dictionary of argument options and return |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 204 | a subset that represent standard arguments needed to construct |
| 205 | a test-assistant object (chameleon or servo) for a host. The |
| 206 | intent is to provide standard argument processing from |
Christopher Wiley | 644ef3e | 2015-05-15 13:14:14 -0700 | [diff] [blame] | 207 | CrosHost for tests that require a test-assistant board |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 208 | to operate. |
| 209 | |
| 210 | @param args_dict Dictionary from which to extract the arguments. |
| 211 | @param key_subset Tuple of keys to extract from the args_dict, e.g. |
| 212 | ('servo_host', 'servo_port'). |
| 213 | """ |
| 214 | result = {} |
| 215 | for arg in key_subset: |
| 216 | if arg in args_dict: |
| 217 | result[arg] = args_dict[arg] |
| 218 | return result |
| 219 | |
| 220 | |
| 221 | @staticmethod |
| 222 | def get_chameleon_arguments(args_dict): |
| 223 | """Extract chameleon options from `args_dict` and return the result. |
| 224 | |
| 225 | Recommended usage: |
| 226 | ~~~~~~~~ |
| 227 | args_dict = utils.args_to_dict(args) |
| 228 | chameleon_args = hosts.CrosHost.get_chameleon_arguments(args_dict) |
| 229 | host = hosts.create_host(machine, chameleon_args=chameleon_args) |
| 230 | ~~~~~~~~ |
| 231 | |
| 232 | @param args_dict Dictionary from which to extract the chameleon |
| 233 | arguments. |
| 234 | """ |
| 235 | return CrosHost._extract_arguments( |
| 236 | args_dict, ('chameleon_host', 'chameleon_port')) |
| 237 | |
| 238 | |
| 239 | @staticmethod |
| 240 | def get_servo_arguments(args_dict): |
| 241 | """Extract servo options from `args_dict` and return the result. |
J. Richard Barnette | 7214e0b | 2013-02-06 15:20:49 -0800 | [diff] [blame] | 242 | |
| 243 | Recommended usage: |
| 244 | ~~~~~~~~ |
| 245 | args_dict = utils.args_to_dict(args) |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 246 | servo_args = hosts.CrosHost.get_servo_arguments(args_dict) |
J. Richard Barnette | 7214e0b | 2013-02-06 15:20:49 -0800 | [diff] [blame] | 247 | host = hosts.create_host(machine, servo_args=servo_args) |
| 248 | ~~~~~~~~ |
| 249 | |
| 250 | @param args_dict Dictionary from which to extract the servo |
| 251 | arguments. |
| 252 | """ |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 253 | return CrosHost._extract_arguments( |
| 254 | args_dict, ('servo_host', 'servo_port')) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 255 | |
J. Richard Barnette | 964fba0 | 2012-10-24 17:34:29 -0700 | [diff] [blame] | 256 | |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 257 | def _initialize(self, hostname, chameleon_args=None, servo_args=None, |
Fang Deng | e545abb | 2014-12-30 18:43:47 -0800 | [diff] [blame] | 258 | try_lab_servo=False, ssh_verbosity_flag='', ssh_options='', |
Fang Deng | d1c2b73 | 2013-08-20 12:59:46 -0700 | [diff] [blame] | 259 | *args, **dargs): |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 260 | """Initialize superclasses, |self.chameleon|, and |self.servo|. |
J. Richard Barnette | 67ccb87 | 2012-04-19 16:34:56 -0700 | [diff] [blame] | 261 | |
Fang Deng | e545abb | 2014-12-30 18:43:47 -0800 | [diff] [blame] | 262 | This method will attempt to create the test-assistant object |
| 263 | (chameleon/servo) when it is needed by the test. Check |
| 264 | the docstring of chameleon_host.create_chameleon_host and |
| 265 | servo_host.create_servo_host for how this is determined. |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 266 | |
Fang Deng | e545abb | 2014-12-30 18:43:47 -0800 | [diff] [blame] | 267 | @param hostname: Hostname of the dut. |
| 268 | @param chameleon_args: A dictionary that contains args for creating |
| 269 | a ChameleonHost. See chameleon_host for details. |
| 270 | @param servo_args: A dictionary that contains args for creating |
| 271 | a ServoHost object. See servo_host for details. |
| 272 | @param try_lab_servo: Boolean, False indicates that ServoHost should |
| 273 | not be created for a device in Cros test lab. |
| 274 | See servo_host for details. |
| 275 | @param ssh_verbosity_flag: String, to pass to the ssh command to control |
| 276 | verbosity. |
| 277 | @param ssh_options: String, other ssh options to pass to the ssh |
| 278 | command. |
J. Richard Barnette | 67ccb87 | 2012-04-19 16:34:56 -0700 | [diff] [blame] | 279 | """ |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 280 | super(CrosHost, self)._initialize(hostname=hostname, |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 281 | *args, **dargs) |
J. Richard Barnette | f085985 | 2012-08-20 14:55:50 -0700 | [diff] [blame] | 282 | # self.env is a dictionary of environment variable settings |
| 283 | # to be exported for commands run on the host. |
| 284 | # LIBC_FATAL_STDERR_ can be useful for diagnosing certain |
| 285 | # errors that might happen. |
| 286 | self.env['LIBC_FATAL_STDERR_'] = '1' |
Fang Deng | d1c2b73 | 2013-08-20 12:59:46 -0700 | [diff] [blame] | 287 | self._ssh_verbosity_flag = ssh_verbosity_flag |
Aviv Keshet | c5947fa | 2013-09-04 14:06:29 -0700 | [diff] [blame] | 288 | self._ssh_options = ssh_options |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 289 | # TODO(fdeng): We need to simplify the |
| 290 | # process of servo and servo_host initialization. |
| 291 | # crbug.com/298432 |
Fang Deng | e545abb | 2014-12-30 18:43:47 -0800 | [diff] [blame] | 292 | self._servo_host = servo_host.create_servo_host( |
| 293 | dut=self.hostname, servo_args=servo_args, |
| 294 | try_lab_servo=try_lab_servo) |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 295 | # TODO(waihong): Do the simplication on Chameleon too. |
Tom Wai-Hong Tam | 3d6790d | 2014-04-14 16:15:47 +0800 | [diff] [blame] | 296 | self._chameleon_host = chameleon_host.create_chameleon_host( |
| 297 | dut=self.hostname, chameleon_args=chameleon_args) |
| 298 | |
Dan Shi | 4d47852 | 2014-02-14 13:46:32 -0800 | [diff] [blame] | 299 | if self._servo_host is not None: |
| 300 | self.servo = self._servo_host.get_servo() |
| 301 | else: |
| 302 | self.servo = None |
| 303 | |
Tom Wai-Hong Tam | 3d6790d | 2014-04-14 16:15:47 +0800 | [diff] [blame] | 304 | if self._chameleon_host: |
Tom Wai-Hong Tam | eaee340 | 2014-01-22 08:52:10 +0800 | [diff] [blame] | 305 | self.chameleon = self._chameleon_host.create_chameleon_board() |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 306 | else: |
Tom Wai-Hong Tam | 3d6790d | 2014-04-14 16:15:47 +0800 | [diff] [blame] | 307 | self.chameleon = None |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 308 | |
| 309 | |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 310 | def get_repair_image_name(self, image_type='cros'): |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 311 | """Generate a image_name from variables in the global config. |
| 312 | |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 313 | image_type is used to differentiate different images. Default is CrOS, |
| 314 | in which case, repair image's name follows the naming convention defined |
| 315 | in global setting CROS/stable_build_pattern. |
| 316 | If the image_type is not `cros`, the repair image will be looked up |
| 317 | using key `board_name/image_type`, e.g., daisy_spring/firmware. |
| 318 | |
| 319 | @param image_type: Type of the image. Default is `cros`. |
| 320 | |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 321 | @returns a str of $board-version/$BUILD. |
| 322 | |
| 323 | """ |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 324 | board = self._get_board_from_afe() |
| 325 | if board is None: |
| 326 | raise error.AutoservError('DUT has no board attribute, ' |
| 327 | 'cannot be repaired.') |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 328 | if image_type != 'cros': |
| 329 | board = '%s/%s' % (board, image_type) |
Dan Shi | 6964fa5 | 2014-12-18 11:04:27 -0800 | [diff] [blame] | 330 | stable_version = self._AFE.run('get_stable_version', board=board) |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 331 | if image_type == 'cros': |
| 332 | build_pattern = CONFIG.get_config_value( |
| 333 | 'CROS', 'stable_build_pattern') |
| 334 | stable_version = build_pattern % (board, stable_version) |
| 335 | return stable_version |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 336 | |
| 337 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 338 | def _host_in_AFE(self): |
| 339 | """Check if the host is an object the AFE knows. |
| 340 | |
| 341 | @returns the host object. |
| 342 | """ |
| 343 | return self._AFE.get_hosts(hostname=self.hostname) |
| 344 | |
| 345 | |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 346 | def lookup_job_repo_url(self): |
| 347 | """Looks up the job_repo_url for the host. |
| 348 | |
| 349 | @returns job_repo_url from AFE or None if not found. |
| 350 | |
| 351 | @raises KeyError if the host does not have a job_repo_url |
| 352 | """ |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 353 | hosts = self._AFE.get_hosts(hostname=self.hostname) |
beeps | b5efc53 | 2013-06-04 11:29:34 -0700 | [diff] [blame] | 354 | if hosts and ds_constants.JOB_REPO_URL in hosts[0].attributes: |
| 355 | return hosts[0].attributes[ds_constants.JOB_REPO_URL] |
J. Richard Barnette | 85d0aac | 2015-08-20 10:34:39 -0700 | [diff] [blame] | 356 | else: |
| 357 | return None |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 358 | |
| 359 | |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 360 | def clear_cros_version_labels_and_job_repo_url(self): |
| 361 | """Clear cros_version labels and host attribute job_repo_url.""" |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 362 | if not self._host_in_AFE(): |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 363 | return |
| 364 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 365 | host_list = [self.hostname] |
| 366 | labels = self._AFE.get_labels( |
| 367 | name__startswith=ds_constants.VERSION_PREFIX, |
| 368 | host__hostname=self.hostname) |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 369 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 370 | for label in labels: |
| 371 | label.remove_hosts(hosts=host_list) |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 372 | |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 373 | self.update_job_repo_url(None, None) |
| 374 | |
| 375 | |
| 376 | def update_job_repo_url(self, devserver_url, image_name): |
| 377 | """ |
| 378 | Updates the job_repo_url host attribute and asserts it's value. |
| 379 | |
| 380 | @param devserver_url: The devserver to use in the job_repo_url. |
| 381 | @param image_name: The name of the image to use in the job_repo_url. |
| 382 | |
| 383 | @raises AutoservError: If we failed to update the job_repo_url. |
| 384 | """ |
| 385 | repo_url = None |
| 386 | if devserver_url and image_name: |
| 387 | repo_url = tools.get_package_url(devserver_url, image_name) |
| 388 | self._AFE.set_host_attribute(ds_constants.JOB_REPO_URL, repo_url, |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 389 | hostname=self.hostname) |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 390 | if self.lookup_job_repo_url() != repo_url: |
| 391 | raise error.AutoservError('Failed to update job_repo_url with %s, ' |
| 392 | 'host %s' % (repo_url, self.hostname)) |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 393 | |
| 394 | |
Dan Shi | e930926 | 2013-06-19 22:50:21 -0700 | [diff] [blame] | 395 | def add_cros_version_labels_and_job_repo_url(self, image_name): |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 396 | """Add cros_version labels and host attribute job_repo_url. |
| 397 | |
| 398 | @param image_name: The name of the image e.g. |
| 399 | lumpy-release/R27-3837.0.0 |
Dan Shi | 7458bf6 | 2013-06-10 12:50:16 -0700 | [diff] [blame] | 400 | |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 401 | """ |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 402 | if not self._host_in_AFE(): |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 403 | return |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 404 | |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 405 | cros_label = '%s%s' % (ds_constants.VERSION_PREFIX, image_name) |
Dan Shi | e930926 | 2013-06-19 22:50:21 -0700 | [diff] [blame] | 406 | devserver_url = dev_server.ImageServer.resolve(image_name).url() |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 407 | |
MK Ryu | fb5e3a8 | 2015-07-01 12:21:20 -0700 | [diff] [blame] | 408 | self._AFE.run('label_add_hosts', id=cros_label, hosts=[self.hostname]) |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 409 | self.update_job_repo_url(devserver_url, image_name) |
| 410 | |
| 411 | |
beeps | dae65fd | 2013-07-26 16:24:41 -0700 | [diff] [blame] | 412 | def verify_job_repo_url(self, tag=''): |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 413 | """ |
| 414 | Make sure job_repo_url of this host is valid. |
| 415 | |
joychen | 03eaad9 | 2013-06-26 09:55:21 -0700 | [diff] [blame] | 416 | Eg: The job_repo_url "http://lmn.cd.ab.xyx:8080/static/\ |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 417 | lumpy-release/R29-4279.0.0/autotest/packages" claims to have the |
| 418 | autotest package for lumpy-release/R29-4279.0.0. If this isn't the case, |
| 419 | download and extract it. If the devserver embedded in the url is |
| 420 | unresponsive, update the job_repo_url of the host after staging it on |
| 421 | another devserver. |
| 422 | |
| 423 | @param job_repo_url: A url pointing to the devserver where the autotest |
| 424 | package for this build should be staged. |
beeps | dae65fd | 2013-07-26 16:24:41 -0700 | [diff] [blame] | 425 | @param tag: The tag from the server job, in the format |
| 426 | <job_id>-<user>/<hostname>, or <hostless> for a server job. |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 427 | |
| 428 | @raises DevServerException: If we could not resolve a devserver. |
| 429 | @raises AutoservError: If we're unable to save the new job_repo_url as |
| 430 | a result of choosing a new devserver because the old one failed to |
| 431 | respond to a health check. |
beeps | 0c86503 | 2013-07-30 11:37:06 -0700 | [diff] [blame] | 432 | @raises urllib2.URLError: If the devserver embedded in job_repo_url |
| 433 | doesn't respond within the timeout. |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 434 | """ |
| 435 | job_repo_url = self.lookup_job_repo_url() |
| 436 | if not job_repo_url: |
| 437 | logging.warning('No job repo url set on host %s', self.hostname) |
| 438 | return |
| 439 | |
| 440 | logging.info('Verifying job repo url %s', job_repo_url) |
| 441 | devserver_url, image_name = tools.get_devserver_build_from_package_url( |
| 442 | job_repo_url) |
| 443 | |
beeps | 0c86503 | 2013-07-30 11:37:06 -0700 | [diff] [blame] | 444 | ds = dev_server.ImageServer(devserver_url) |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 445 | |
| 446 | logging.info('Staging autotest artifacts for %s on devserver %s', |
| 447 | image_name, ds.url()) |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 448 | |
| 449 | start_time = time.time() |
Simran Basi | 25e7a92 | 2014-10-31 11:56:10 -0700 | [diff] [blame] | 450 | ds.stage_artifacts(image_name, ['autotest_packages']) |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 451 | stage_time = time.time() - start_time |
| 452 | |
| 453 | # Record how much of the verification time comes from a devserver |
| 454 | # restage. If we're doing things right we should not see multiple |
| 455 | # devservers for a given board/build/branch path. |
| 456 | try: |
J. Richard Barnette | 3cbd76b | 2013-11-27 12:11:25 -0800 | [diff] [blame] | 457 | board, build_type, branch = server_utils.ParseBuildName( |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 458 | image_name)[:3] |
J. Richard Barnette | 3cbd76b | 2013-11-27 12:11:25 -0800 | [diff] [blame] | 459 | except server_utils.ParseBuildNameException: |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 460 | pass |
| 461 | else: |
beeps | 0c86503 | 2013-07-30 11:37:06 -0700 | [diff] [blame] | 462 | devserver = devserver_url[ |
Chris Sosa | 6542508 | 2013-10-16 13:26:22 -0700 | [diff] [blame] | 463 | devserver_url.find('/') + 2:devserver_url.rfind(':')] |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 464 | stats_key = { |
| 465 | 'board': board, |
| 466 | 'build_type': build_type, |
| 467 | 'branch': branch, |
beeps | 0c86503 | 2013-07-30 11:37:06 -0700 | [diff] [blame] | 468 | 'devserver': devserver.replace('.', '_'), |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 469 | } |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 470 | autotest_stats.Gauge('verify_job_repo_url').send( |
beeps | 687243d | 2013-07-18 15:29:27 -0700 | [diff] [blame] | 471 | '%(board)s.%(build_type)s.%(branch)s.%(devserver)s' % stats_key, |
| 472 | stage_time) |
beeps | cb6f1e2 | 2013-06-28 19:14:10 -0700 | [diff] [blame] | 473 | |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 474 | |
Dan Shi | cf4d203 | 2015-03-12 15:04:21 -0700 | [diff] [blame] | 475 | def stage_server_side_package(self, image=None): |
| 476 | """Stage autotest server-side package on devserver. |
| 477 | |
| 478 | @param image: Full path of an OS image to install or a build name. |
| 479 | |
| 480 | @return: A url to the autotest server-side package. |
| 481 | """ |
| 482 | if image: |
| 483 | image_name = tools.get_build_from_image(image) |
| 484 | if not image_name: |
| 485 | raise error.AutoservError( |
| 486 | 'Failed to parse build name from %s' % image) |
| 487 | ds = dev_server.ImageServer.resolve(image_name) |
| 488 | else: |
| 489 | job_repo_url = self.lookup_job_repo_url() |
| 490 | if job_repo_url: |
| 491 | devserver_url, image_name = ( |
| 492 | tools.get_devserver_build_from_package_url(job_repo_url)) |
| 493 | ds = dev_server.ImageServer(devserver_url) |
| 494 | else: |
| 495 | labels = self._AFE.get_labels( |
| 496 | name__startswith=ds_constants.VERSION_PREFIX, |
| 497 | host__hostname=self.hostname) |
| 498 | if not labels: |
| 499 | raise error.AutoservError( |
| 500 | 'Failed to stage server-side package. The host has ' |
| 501 | 'no job_report_url attribute or version label.') |
| 502 | image_name = labels[0].name[len(ds_constants.VERSION_PREFIX):] |
| 503 | ds = dev_server.ImageServer.resolve(image_name) |
Dan Shi | ca50348 | 2015-03-30 17:23:25 -0700 | [diff] [blame] | 504 | |
| 505 | # Get the OS version of the build, for any build older than |
| 506 | # MIN_VERSION_SUPPORT_SSP, server side packaging is not supported. |
| 507 | match = re.match('.*/R\d+-(\d+)\.', image_name) |
| 508 | if match and int(match.group(1)) < self.MIN_VERSION_SUPPORT_SSP: |
| 509 | logging.warn('Build %s is older than %s. Server side packaging is ' |
| 510 | 'disabled.', image_name, self.MIN_VERSION_SUPPORT_SSP) |
| 511 | return None |
| 512 | |
Dan Shi | cf4d203 | 2015-03-12 15:04:21 -0700 | [diff] [blame] | 513 | ds.stage_artifacts(image_name, ['autotest_server_package']) |
| 514 | return '%s/static/%s/%s' % (ds.url(), image_name, |
| 515 | 'autotest_server_package.tar.bz2') |
| 516 | |
| 517 | |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 518 | def _try_stateful_update(self, update_url, force_update, updater): |
| 519 | """Try to use stateful update to initialize DUT. |
| 520 | |
| 521 | When DUT is already running the same version that machine_install |
| 522 | tries to install, stateful update is a much faster way to clean up |
| 523 | the DUT for testing, compared to a full reimage. It is implemeted |
| 524 | by calling autoupdater.run_update, but skipping updating root, as |
| 525 | updating the kernel is time consuming and not necessary. |
| 526 | |
| 527 | @param update_url: url of the image. |
| 528 | @param force_update: Set to True to update the image even if the DUT |
| 529 | is running the same version. |
| 530 | @param updater: ChromiumOSUpdater instance used to update the DUT. |
| 531 | @returns: True if the DUT was updated with stateful update. |
| 532 | |
| 533 | """ |
J. Richard Barnette | 3f73103 | 2014-04-07 17:42:59 -0700 | [diff] [blame] | 534 | # TODO(jrbarnette): Yes, I hate this re.match() test case. |
| 535 | # It's better than the alternative: see crbug.com/360944. |
| 536 | image_name = autoupdater.url_to_image_name(update_url) |
| 537 | release_pattern = r'^.*-release/R[0-9]+-[0-9]+\.[0-9]+\.0$' |
| 538 | if not re.match(release_pattern, image_name): |
| 539 | return False |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 540 | if not updater.check_version(): |
| 541 | return False |
| 542 | if not force_update: |
| 543 | logging.info('Canceling stateful update because the new and ' |
| 544 | 'old versions are the same.') |
| 545 | return False |
| 546 | # Following folders should be rebuilt after stateful update. |
| 547 | # A test file is used to confirm each folder gets rebuilt after |
| 548 | # the stateful update. |
| 549 | folders_to_check = ['/var', '/home', '/mnt/stateful_partition'] |
| 550 | test_file = '.test_file_to_be_deleted' |
| 551 | for folder in folders_to_check: |
| 552 | touch_path = os.path.join(folder, test_file) |
| 553 | self.run('touch %s' % touch_path) |
| 554 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 555 | updater.run_update(update_root=False) |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 556 | |
| 557 | # Reboot to complete stateful update. |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame] | 558 | self.reboot(timeout=self.REBOOT_TIMEOUT, wait=True) |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 559 | check_file_cmd = 'test -f %s; echo $?' |
| 560 | for folder in folders_to_check: |
| 561 | test_file_path = os.path.join(folder, test_file) |
| 562 | result = self.run(check_file_cmd % test_file_path, |
| 563 | ignore_status=True) |
| 564 | if result.exit_status == 1: |
| 565 | return False |
| 566 | return True |
| 567 | |
| 568 | |
J. Richard Barnette | 7275b61 | 2013-06-04 18:13:11 -0700 | [diff] [blame] | 569 | def _post_update_processing(self, updater, expected_kernel=None): |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 570 | """After the DUT is updated, confirm machine_install succeeded. |
| 571 | |
| 572 | @param updater: ChromiumOSUpdater instance used to update the DUT. |
J. Richard Barnette | 7275b61 | 2013-06-04 18:13:11 -0700 | [diff] [blame] | 573 | @param expected_kernel: kernel expected to be active after reboot, |
| 574 | or `None` to skip rollback checking. |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 575 | |
| 576 | """ |
J. Richard Barnette | 7275b61 | 2013-06-04 18:13:11 -0700 | [diff] [blame] | 577 | # Touch the lab machine file to leave a marker that |
| 578 | # distinguishes this image from other test images. |
| 579 | # Afterwards, we must re-run the autoreboot script because |
| 580 | # it depends on the _LAB_MACHINE_FILE. |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 581 | self.run('touch %s' % self._LAB_MACHINE_FILE) |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 582 | self.run('start autoreboot') |
Chris Sosa | 6542508 | 2013-10-16 13:26:22 -0700 | [diff] [blame] | 583 | updater.verify_boot_expectations( |
| 584 | expected_kernel, rollback_message= |
Gilad Arnold | c26ae1f | 2015-10-22 16:09:41 -0700 | [diff] [blame] | 585 | 'Build %s failed to boot on %s; system rolled back to previous ' |
Chris Sosa | 6542508 | 2013-10-16 13:26:22 -0700 | [diff] [blame] | 586 | 'build' % (updater.update_version, self.hostname)) |
J. Richard Barnette | 7275b61 | 2013-06-04 18:13:11 -0700 | [diff] [blame] | 587 | # Check that we've got the build we meant to install. |
| 588 | if not updater.check_version_to_confirm_install(): |
| 589 | raise autoupdater.ChromiumOSError( |
| 590 | 'Failed to update %s to build %s; found build ' |
| 591 | '%s instead' % (self.hostname, |
Chris Sosa | 6542508 | 2013-10-16 13:26:22 -0700 | [diff] [blame] | 592 | updater.update_version, |
Dan Shi | 0942b1d | 2015-03-31 11:07:00 -0700 | [diff] [blame] | 593 | self.get_release_version())) |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 594 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 595 | logging.debug('Cleaning up old autotest directories.') |
| 596 | try: |
| 597 | installed_autodir = autotest.Autotest.get_installed_autodir(self) |
| 598 | self.run('rm -rf ' + installed_autodir) |
| 599 | except autotest.AutodirNotFoundError: |
| 600 | logging.debug('No autotest installed directory found.') |
| 601 | |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 602 | |
J. Richard Barnette | e4af8b9 | 2013-05-01 13:16:12 -0700 | [diff] [blame] | 603 | def _stage_image_for_update(self, image_name=None): |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 604 | """Stage a build on a devserver and return the update_url and devserver. |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 605 | |
| 606 | @param image_name: a name like lumpy-release/R27-3837.0.0 |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 607 | @returns a tuple with an update URL like: |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 608 | http://172.22.50.205:8082/update/lumpy-release/R27-3837.0.0 |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 609 | and the devserver instance. |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 610 | """ |
J. Richard Barnette | e4af8b9 | 2013-05-01 13:16:12 -0700 | [diff] [blame] | 611 | if not image_name: |
| 612 | image_name = self.get_repair_image_name() |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 613 | |
J. Richard Barnette | e4af8b9 | 2013-05-01 13:16:12 -0700 | [diff] [blame] | 614 | logging.info('Staging build for AU: %s', image_name) |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 615 | devserver = dev_server.ImageServer.resolve(image_name) |
| 616 | devserver.trigger_download(image_name, synchronous=False) |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 617 | return (tools.image_url_pattern() % (devserver.url(), image_name), |
| 618 | devserver) |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 619 | |
| 620 | |
J. Richard Barnette | e4af8b9 | 2013-05-01 13:16:12 -0700 | [diff] [blame] | 621 | def stage_image_for_servo(self, image_name=None): |
| 622 | """Stage a build on a devserver and return the update_url. |
| 623 | |
| 624 | @param image_name: a name like lumpy-release/R27-3837.0.0 |
| 625 | @returns an update URL like: |
| 626 | http://172.22.50.205:8082/update/lumpy-release/R27-3837.0.0 |
| 627 | """ |
| 628 | if not image_name: |
| 629 | image_name = self.get_repair_image_name() |
| 630 | logging.info('Staging build for servo install: %s', image_name) |
| 631 | devserver = dev_server.ImageServer.resolve(image_name) |
| 632 | devserver.stage_artifacts(image_name, ['test_image']) |
| 633 | return devserver.get_test_image_url(image_name) |
| 634 | |
| 635 | |
beeps | e539be0 | 2013-07-31 21:57:39 -0700 | [diff] [blame] | 636 | def stage_factory_image_for_servo(self, image_name): |
| 637 | """Stage a build on a devserver and return the update_url. |
| 638 | |
| 639 | @param image_name: a name like <baord>/4262.204.0 |
beeps | 12c0a3c | 2013-09-03 11:58:27 -0700 | [diff] [blame] | 640 | |
beeps | e539be0 | 2013-07-31 21:57:39 -0700 | [diff] [blame] | 641 | @return: An update URL, eg: |
| 642 | http://<devserver>/static/canary-channel/\ |
| 643 | <board>/4262.204.0/factory_test/chromiumos_factory_image.bin |
beeps | 12c0a3c | 2013-09-03 11:58:27 -0700 | [diff] [blame] | 644 | |
| 645 | @raises: ValueError if the factory artifact name is missing from |
| 646 | the config. |
| 647 | |
beeps | e539be0 | 2013-07-31 21:57:39 -0700 | [diff] [blame] | 648 | """ |
| 649 | if not image_name: |
| 650 | logging.error('Need an image_name to stage a factory image.') |
| 651 | return |
| 652 | |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 653 | factory_artifact = CONFIG.get_config_value( |
beeps | 12c0a3c | 2013-09-03 11:58:27 -0700 | [diff] [blame] | 654 | 'CROS', 'factory_artifact', type=str, default='') |
| 655 | if not factory_artifact: |
| 656 | raise ValueError('Cannot retrieve the factory artifact name from ' |
| 657 | 'autotest config, and hence cannot stage factory ' |
| 658 | 'artifacts.') |
| 659 | |
beeps | e539be0 | 2013-07-31 21:57:39 -0700 | [diff] [blame] | 660 | logging.info('Staging build for servo install: %s', image_name) |
| 661 | devserver = dev_server.ImageServer.resolve(image_name) |
| 662 | devserver.stage_artifacts( |
| 663 | image_name, |
beeps | 12c0a3c | 2013-09-03 11:58:27 -0700 | [diff] [blame] | 664 | [factory_artifact], |
| 665 | archive_url=None) |
beeps | e539be0 | 2013-07-31 21:57:39 -0700 | [diff] [blame] | 666 | |
| 667 | return tools.factory_image_url_pattern() % (devserver.url(), image_name) |
| 668 | |
| 669 | |
Chris Sosa | a3ac215 | 2012-05-23 22:23:13 -0700 | [diff] [blame] | 670 | def machine_install(self, update_url=None, force_update=False, |
Richard Barnette | 0b023a7 | 2015-04-24 16:07:30 +0000 | [diff] [blame] | 671 | local_devserver=False, repair=False, |
| 672 | force_full_update=False): |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 673 | """Install the DUT. |
| 674 | |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 675 | Use stateful update if the DUT is already running the same build. |
| 676 | Stateful update does not update kernel and tends to run much faster |
| 677 | than a full reimage. If the DUT is running a different build, or it |
| 678 | failed to do a stateful update, full update, including kernel update, |
| 679 | will be applied to the DUT. |
| 680 | |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 681 | Once a host enters machine_install its cros_version label will be |
| 682 | removed as well as its host attribute job_repo_url (used for |
| 683 | package install). |
| 684 | |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 685 | @param update_url: The url to use for the update |
| 686 | pattern: http://$devserver:###/update/$build |
| 687 | If update_url is None and repair is True we will install the |
Dan Shi | 6964fa5 | 2014-12-18 11:04:27 -0800 | [diff] [blame] | 688 | stable image listed in afe_stable_versions table. If the table |
| 689 | is not setup, global_config value under CROS.stable_cros_version |
| 690 | will be used instead. |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 691 | @param force_update: Force an update even if the version installed |
| 692 | is the same. Default:False |
Christopher Wiley | 6a4ff93 | 2015-05-15 14:00:47 -0700 | [diff] [blame] | 693 | @param local_devserver: Used by test_that to allow people to |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 694 | use their local devserver. Default: False |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 695 | @param repair: Forces update to repair image. Implies force_update. |
Fang Deng | 3d3b927 | 2014-12-22 12:20:28 -0800 | [diff] [blame] | 696 | @param force_full_update: If True, do not attempt to run stateful |
| 697 | update, force a full reimage. If False, try stateful update |
| 698 | first when the dut is already installed with the same version. |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 699 | @raises autoupdater.ChromiumOSError |
| 700 | |
| 701 | """ |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 702 | devserver = None |
Richard Barnette | 0b023a7 | 2015-04-24 16:07:30 +0000 | [diff] [blame] | 703 | if repair: |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 704 | update_url, devserver = self._stage_image_for_update() |
Richard Barnette | 0b023a7 | 2015-04-24 16:07:30 +0000 | [diff] [blame] | 705 | force_update = True |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 706 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 707 | if not update_url and not self._parser.options.image: |
| 708 | raise error.AutoservError( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 709 | 'There is no update URL, nor a method to get one.') |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 710 | |
| 711 | if not update_url and self._parser.options.image: |
| 712 | # This is the base case where we have no given update URL i.e. |
| 713 | # dynamic suites logic etc. This is the most flexible case where we |
| 714 | # can serve an update from any of our fleet of devservers. |
| 715 | requested_build = self._parser.options.image |
| 716 | if not requested_build.startswith('http://'): |
| 717 | logging.debug('Update will be staged for this installation') |
| 718 | update_url, devserver = self._stage_image_for_update( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 719 | requested_build) |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 720 | else: |
| 721 | update_url = requested_build |
| 722 | |
| 723 | logging.debug('Update URL is %s', update_url) |
| 724 | |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 725 | # Remove cros-version and job_repo_url host attribute from host. |
| 726 | self.clear_cros_version_labels_and_job_repo_url() |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 727 | |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 728 | # Create a file to indicate if provision fails. The file will be removed |
| 729 | # by stateful update or full install. |
| 730 | self.run('touch %s' % PROVISION_FAILED) |
| 731 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 732 | update_complete = False |
| 733 | updater = autoupdater.ChromiumOSUpdater( |
| 734 | update_url, host=self, local_devserver=local_devserver) |
Fang Deng | 3d3b927 | 2014-12-22 12:20:28 -0800 | [diff] [blame] | 735 | if not force_full_update: |
| 736 | try: |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 737 | # If the DUT is already running the same build, try stateful |
| 738 | # update first as it's much quicker than a full re-image. |
| 739 | update_complete = self._try_stateful_update( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 740 | update_url, force_update, updater) |
Fang Deng | 3d3b927 | 2014-12-22 12:20:28 -0800 | [diff] [blame] | 741 | except Exception as e: |
| 742 | logging.exception(e) |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 743 | |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 744 | inactive_kernel = None |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 745 | if update_complete or (not force_update and updater.check_version()): |
| 746 | logging.info('Install complete without full update') |
| 747 | else: |
| 748 | logging.info('DUT requires full update.') |
| 749 | self.reboot(timeout=self.REBOOT_TIMEOUT, wait=True) |
| 750 | num_of_attempts = provision.FLAKY_DEVSERVER_ATTEMPTS |
Chris Sosa | b7612bc | 2013-03-21 10:32:37 -0700 | [diff] [blame] | 751 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 752 | while num_of_attempts > 0: |
| 753 | num_of_attempts -= 1 |
| 754 | try: |
| 755 | updater.run_update() |
| 756 | except Exception: |
| 757 | logging.warn('Autoupdate did not complete.') |
| 758 | # Do additional check for the devserver health. Ideally, |
| 759 | # the autoupdater.py could raise an exception when it |
| 760 | # detected network flake but that would require |
| 761 | # instrumenting the update engine and parsing it log. |
| 762 | if (num_of_attempts <= 0 or |
| 763 | devserver is None or |
| 764 | dev_server.DevServer.devserver_healthy( |
| 765 | devserver.url())): |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 766 | raise |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 767 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 768 | logging.warn('Devserver looks unhealthy. Trying another') |
| 769 | update_url, devserver = self._stage_image_for_update( |
| 770 | requested_build) |
| 771 | logging.debug('New Update URL is %s', update_url) |
| 772 | updater = autoupdater.ChromiumOSUpdater( |
| 773 | update_url, host=self, |
| 774 | local_devserver=local_devserver) |
| 775 | else: |
| 776 | break |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 777 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 778 | # Give it some time in case of IO issues. |
| 779 | time.sleep(10) |
Dan Shi | 5699ac2 | 2014-12-19 10:55:49 -0800 | [diff] [blame] | 780 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 781 | # Figure out active and inactive kernel. |
| 782 | active_kernel, inactive_kernel = updater.get_kernel_state() |
Simran Basi | 13fa1ba | 2013-03-04 10:56:47 -0800 | [diff] [blame] | 783 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 784 | # Ensure inactive kernel has higher priority than active. |
| 785 | if (updater.get_kernel_priority(inactive_kernel) |
| 786 | < updater.get_kernel_priority(active_kernel)): |
| 787 | raise autoupdater.ChromiumOSError( |
| 788 | 'Update failed. The priority of the inactive kernel' |
| 789 | ' partition is less than that of the active kernel' |
| 790 | ' partition.') |
| 791 | |
| 792 | # Updater has returned successfully; reboot the host. |
| 793 | self.reboot(timeout=self.REBOOT_TIMEOUT, wait=True) |
| 794 | |
| 795 | self._post_update_processing(updater, inactive_kernel) |
| 796 | self.add_cros_version_labels_and_job_repo_url( |
| 797 | autoupdater.url_to_image_name(update_url)) |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 798 | |
| 799 | |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 800 | def _clear_fw_version_labels(self): |
| 801 | """Clear firmware version labels from the machine.""" |
| 802 | labels = self._AFE.get_labels( |
Dan Shi | 0723bf5 | 2015-06-24 10:52:38 -0700 | [diff] [blame] | 803 | name__startswith=provision.FW_RW_VERSION_PREFIX, |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 804 | host__hostname=self.hostname) |
| 805 | for label in labels: |
| 806 | label.remove_hosts(hosts=[self.hostname]) |
| 807 | |
| 808 | |
| 809 | def _add_fw_version_label(self, build): |
| 810 | """Add firmware version label to the machine. |
| 811 | |
| 812 | @param build: Build of firmware. |
| 813 | |
| 814 | """ |
| 815 | fw_label = provision.fw_version_to_label(build) |
MK Ryu | 73be986 | 2015-07-06 12:25:00 -0700 | [diff] [blame] | 816 | self._AFE.run('label_add_hosts', id=fw_label, hosts=[self.hostname]) |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 817 | |
| 818 | |
| 819 | def firmware_install(self, build=None): |
| 820 | """Install firmware to the DUT. |
| 821 | |
| 822 | Use stateful update if the DUT is already running the same build. |
| 823 | Stateful update does not update kernel and tends to run much faster |
| 824 | than a full reimage. If the DUT is running a different build, or it |
| 825 | failed to do a stateful update, full update, including kernel update, |
| 826 | will be applied to the DUT. |
| 827 | |
| 828 | Once a host enters firmware_install its fw_version label will be |
| 829 | removed. After the firmware is updated successfully, a new fw_version |
| 830 | label will be added to the host. |
| 831 | |
| 832 | @param build: The build version to which we want to provision the |
| 833 | firmware of the machine, |
| 834 | e.g. 'link-firmware/R22-2695.1.144'. |
| 835 | |
| 836 | TODO(dshi): After bug 381718 is fixed, update here with corresponding |
| 837 | exceptions that could be raised. |
| 838 | |
| 839 | """ |
| 840 | if not self.servo: |
| 841 | raise error.TestError('Host %s does not have servo.' % |
| 842 | self.hostname) |
| 843 | |
| 844 | # TODO(fdeng): use host.get_board() after |
| 845 | # crbug.com/271834 is fixed. |
| 846 | board = self._get_board_from_afe() |
| 847 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 848 | # If build is not set, try to install firmware from stable CrOS. |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 849 | if not build: |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 850 | build = self.get_repair_image_name(image_type='firmware') |
| 851 | if not build: |
| 852 | raise error.TestError( |
| 853 | 'Failed to find stable firmware build for %s.', |
| 854 | self.hostname) |
| 855 | logging.info('Will install firmware from build %s.', build) |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 856 | |
| 857 | config = FAFTConfig(board) |
| 858 | if config.use_u_boot: |
| 859 | ap_image = 'image-%s.bin' % board |
| 860 | else: # Depthcharge platform |
| 861 | ap_image = 'image.bin' |
| 862 | ec_image = 'ec.bin' |
| 863 | ds = dev_server.ImageServer.resolve(build) |
| 864 | ds.stage_artifacts(build, ['firmware']) |
| 865 | |
| 866 | tmpd = autotemp.tempdir(unique_id='fwimage') |
| 867 | try: |
| 868 | fwurl = self._FW_IMAGE_URL_PATTERN % (ds.url(), build) |
| 869 | local_tarball = os.path.join(tmpd.name, os.path.basename(fwurl)) |
| 870 | server_utils.system('wget -O %s %s' % (local_tarball, fwurl), |
| 871 | timeout=60) |
| 872 | server_utils.system('tar xf %s -C %s %s %s' % |
| 873 | (local_tarball, tmpd.name, ap_image, ec_image), |
| 874 | timeout=60) |
| 875 | server_utils.system('tar xf %s --wildcards -C %s "dts/*"' % |
| 876 | (local_tarball, tmpd.name), |
| 877 | timeout=60, ignore_status=True) |
| 878 | |
| 879 | self._clear_fw_version_labels() |
| 880 | logging.info('Will re-program EC now') |
| 881 | self.servo.program_ec(os.path.join(tmpd.name, ec_image)) |
| 882 | logging.info('Will re-program BIOS now') |
| 883 | self.servo.program_bios(os.path.join(tmpd.name, ap_image)) |
| 884 | self.servo.get_power_state_controller().reset() |
| 885 | time.sleep(self.servo.BOOT_DELAY) |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 886 | self._add_fw_version_label(build) |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 887 | finally: |
| 888 | tmpd.clean() |
| 889 | |
| 890 | |
Dan Shi | 10e992b | 2013-08-30 11:02:59 -0700 | [diff] [blame] | 891 | def show_update_engine_log(self): |
| 892 | """Output update engine log.""" |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 893 | logging.debug('Dumping %s', client_constants.UPDATE_ENGINE_LOG) |
| 894 | self.run('cat %s' % client_constants.UPDATE_ENGINE_LOG) |
Dan Shi | 10e992b | 2013-08-30 11:02:59 -0700 | [diff] [blame] | 895 | |
| 896 | |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 897 | def _get_board_from_afe(self): |
| 898 | """Retrieve this host's board from its labels in the AFE. |
| 899 | |
| 900 | Looks for a host label of the form "board:<board>", and |
| 901 | returns the "<board>" part of the label. `None` is returned |
| 902 | if there is not a single, unique label matching the pattern. |
| 903 | |
| 904 | @returns board from label, or `None`. |
| 905 | """ |
Dan Shi | a1ecd5c | 2013-06-06 11:21:31 -0700 | [diff] [blame] | 906 | return server_utils.get_board_from_afe(self.hostname, self._AFE) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 907 | |
| 908 | |
| 909 | def get_build(self): |
| 910 | """Retrieve the current build for this Host from the AFE. |
| 911 | |
| 912 | Looks through this host's labels in the AFE to determine its build. |
| 913 | |
| 914 | @returns The current build or None if it could not find it or if there |
| 915 | were multiple build labels assigned to this host. |
| 916 | """ |
Dan Shi | a1ecd5c | 2013-06-06 11:21:31 -0700 | [diff] [blame] | 917 | return server_utils.get_build_from_afe(self.hostname, self._AFE) |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 918 | |
| 919 | |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 920 | def _install_repair(self): |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 921 | """Attempt to repair this host using the update-engine. |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 922 | |
| 923 | If the host is up, try installing the DUT with a stable |
Dan Shi | 6964fa5 | 2014-12-18 11:04:27 -0800 | [diff] [blame] | 924 | "repair" version of Chrome OS as defined in afe_stable_versions table. |
| 925 | If the table is not setup, global_config value under |
| 926 | CROS.stable_cros_version will be used instead. |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 927 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 928 | @raises AutoservRepairMethodNA if the DUT is not reachable. |
| 929 | @raises ChromiumOSError if the install failed for some reason. |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 930 | |
| 931 | """ |
| 932 | if not self.is_up(): |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 933 | raise error.AutoservRepairMethodNA('DUT unreachable for install.') |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 934 | logging.info('Attempting to reimage machine to repair image.') |
| 935 | try: |
Richard Barnette | 0b023a7 | 2015-04-24 16:07:30 +0000 | [diff] [blame] | 936 | self.machine_install(repair=True) |
Fang Deng | d0672f3 | 2013-03-18 17:18:09 -0700 | [diff] [blame] | 937 | except autoupdater.ChromiumOSError as e: |
| 938 | logging.exception(e) |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 939 | logging.info('Repair via install failed.') |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 940 | raise |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 941 | |
| 942 | |
Dan Shi | 2c88eed | 2013-11-12 10:18:38 -0800 | [diff] [blame] | 943 | def _install_repair_with_powerwash(self): |
Dan Shi | 9cc4845 | 2013-11-12 12:39:26 -0800 | [diff] [blame] | 944 | """Attempt to powerwash first then repair this host using update-engine. |
Dan Shi | 2c88eed | 2013-11-12 10:18:38 -0800 | [diff] [blame] | 945 | |
Dan Shi | 9cc4845 | 2013-11-12 12:39:26 -0800 | [diff] [blame] | 946 | update-engine may fail due to a bad image. In such case, powerwash |
| 947 | may help to cleanup the DUT for update-engine to work again. |
Dan Shi | 2c88eed | 2013-11-12 10:18:38 -0800 | [diff] [blame] | 948 | |
| 949 | @raises AutoservRepairMethodNA if the DUT is not reachable. |
| 950 | @raises ChromiumOSError if the install failed for some reason. |
| 951 | |
| 952 | """ |
| 953 | if not self.is_up(): |
| 954 | raise error.AutoservRepairMethodNA('DUT unreachable for install.') |
| 955 | |
| 956 | logging.info('Attempting to powerwash the DUT.') |
| 957 | self.run('echo "fast safe" > ' |
| 958 | '/mnt/stateful_partition/factory_install_reset') |
| 959 | self.reboot(timeout=self.POWERWASH_BOOT_TIMEOUT, wait=True) |
| 960 | if not self.is_up(): |
Dan Shi | 9cc4845 | 2013-11-12 12:39:26 -0800 | [diff] [blame] | 961 | logging.error('Powerwash failed. DUT did not come back after ' |
Dan Shi | 2c88eed | 2013-11-12 10:18:38 -0800 | [diff] [blame] | 962 | 'reboot.') |
| 963 | raise error.AutoservRepairFailure( |
| 964 | 'DUT failed to boot from powerwash after %d seconds' % |
| 965 | self.POWERWASH_BOOT_TIMEOUT) |
| 966 | |
| 967 | logging.info('Powerwash succeeded.') |
| 968 | self._install_repair() |
| 969 | |
| 970 | |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 971 | def servo_install(self, image_url=None, usb_boot_timeout=USB_BOOT_TIMEOUT, |
| 972 | install_timeout=INSTALL_TIMEOUT): |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 973 | """ |
| 974 | Re-install the OS on the DUT by: |
| 975 | 1) installing a test image on a USB storage device attached to the Servo |
| 976 | board, |
Richard Barnette | 03a0c13 | 2012-11-05 12:40:35 -0800 | [diff] [blame] | 977 | 2) booting that image in recovery mode, and then |
J. Richard Barnette | 31b2e31 | 2013-04-04 16:05:22 -0700 | [diff] [blame] | 978 | 3) installing the image with chromeos-install. |
| 979 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 980 | @param image_url: If specified use as the url to install on the DUT. |
| 981 | otherwise boot the currently staged image on the USB stick. |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 982 | @param usb_boot_timeout: The usb_boot_timeout to use during reimage. |
| 983 | Factory images need a longer usb_boot_timeout than regular |
| 984 | cros images. |
| 985 | @param install_timeout: The timeout to use when installing the chromeos |
| 986 | image. Factory images need a longer install_timeout. |
Richard Barnette | 03a0c13 | 2012-11-05 12:40:35 -0800 | [diff] [blame] | 987 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 988 | @raises AutoservError if the image fails to boot. |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 989 | |
J. Richard Barnette | 0199cc8 | 2014-12-05 17:08:40 -0800 | [diff] [blame] | 990 | """ |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 991 | usb_boot_timer_key = ('servo_install.usb_boot_timeout_%s' |
| 992 | % usb_boot_timeout) |
| 993 | logging.info('Downloading image to USB, then booting from it. Usb boot ' |
| 994 | 'timeout = %s', usb_boot_timeout) |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 995 | timer = autotest_stats.Timer(usb_boot_timer_key) |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 996 | timer.start() |
J. Richard Barnette | 31b2e31 | 2013-04-04 16:05:22 -0700 | [diff] [blame] | 997 | self.servo.install_recovery_image(image_url) |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 998 | if not self.wait_up(timeout=usb_boot_timeout): |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 999 | raise error.AutoservRepairFailure( |
| 1000 | 'DUT failed to boot from USB after %d seconds' % |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 1001 | usb_boot_timeout) |
| 1002 | timer.stop() |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1003 | |
Tom Wai-Hong Tam | f6b4f81 | 2015-08-08 04:14:59 +0800 | [diff] [blame] | 1004 | # The new chromeos-tpm-recovery has been merged since R44-7073.0.0. |
| 1005 | # In old CrOS images, this command fails. Skip the error. |
Tom Wai-Hong Tam | 27af733 | 2015-07-25 06:09:39 +0800 | [diff] [blame] | 1006 | logging.info('Resetting the TPM status') |
Tom Wai-Hong Tam | f6b4f81 | 2015-08-08 04:14:59 +0800 | [diff] [blame] | 1007 | try: |
| 1008 | self.run('chromeos-tpm-recovery') |
| 1009 | except error.AutoservRunError: |
| 1010 | logging.warn('chromeos-tpm-recovery is too old.') |
| 1011 | |
Tom Wai-Hong Tam | 27af733 | 2015-07-25 06:09:39 +0800 | [diff] [blame] | 1012 | |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 1013 | install_timer_key = ('servo_install.install_timeout_%s' |
| 1014 | % install_timeout) |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1015 | timer = autotest_stats.Timer(install_timer_key) |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 1016 | timer.start() |
| 1017 | logging.info('Installing image through chromeos-install.') |
J. Richard Barnette | 9af1963 | 2015-09-25 12:18:03 -0700 | [diff] [blame] | 1018 | self.run('chromeos-install --yes', timeout=install_timeout) |
| 1019 | self.halt() |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 1020 | timer.stop() |
| 1021 | |
| 1022 | logging.info('Power cycling DUT through servo.') |
J. Richard Barnette | 0199cc8 | 2014-12-05 17:08:40 -0800 | [diff] [blame] | 1023 | self.servo.get_power_state_controller().power_off() |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1024 | self.servo.switch_usbkey('off') |
J. Richard Barnette | 0199cc8 | 2014-12-05 17:08:40 -0800 | [diff] [blame] | 1025 | # N.B. The Servo API requires that we use power_on() here |
| 1026 | # for two reasons: |
| 1027 | # 1) After turning on a DUT in recovery mode, you must turn |
| 1028 | # it off and then on with power_on() once more to |
| 1029 | # disable recovery mode (this is a Parrot specific |
| 1030 | # requirement). |
| 1031 | # 2) After power_off(), the only way to turn on is with |
| 1032 | # power_on() (this is a Storm specific requirement). |
J. Richard Barnette | fbcc712 | 2013-07-24 18:24:59 -0700 | [diff] [blame] | 1033 | self.servo.get_power_state_controller().power_on() |
beeps | f079cfb | 2013-09-18 17:49:51 -0700 | [diff] [blame] | 1034 | |
| 1035 | logging.info('Waiting for DUT to come back up.') |
Richard Barnette | 03a0c13 | 2012-11-05 12:40:35 -0800 | [diff] [blame] | 1036 | if not self.wait_up(timeout=self.BOOT_TIMEOUT): |
| 1037 | raise error.AutoservError('DUT failed to reboot installed ' |
| 1038 | 'test image after %d seconds' % |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1039 | self.BOOT_TIMEOUT) |
| 1040 | |
| 1041 | |
Dan Shi | c1b8bdd | 2015-09-14 23:11:24 -0700 | [diff] [blame] | 1042 | def _setup_servo(self): |
| 1043 | """Try to force to create servo object if it's not set up yet. |
| 1044 | """ |
| 1045 | if self.servo: |
| 1046 | return |
| 1047 | |
| 1048 | try: |
| 1049 | # Setting servo_args to {} will force it to create the servo_host |
| 1050 | # object if possible. |
| 1051 | self._servo_host = servo_host.create_servo_host( |
| 1052 | dut=self.hostname, servo_args={}) |
| 1053 | if self._servo_host: |
| 1054 | self.servo = self._servo_host.get_servo() |
| 1055 | else: |
| 1056 | logging.error('Failed to create servo_host object.') |
| 1057 | except Exception as e: |
| 1058 | logging.error('Failed to create servo object: %s', e) |
| 1059 | |
| 1060 | |
J. Richard Barnette | e4af8b9 | 2013-05-01 13:16:12 -0700 | [diff] [blame] | 1061 | def _servo_repair_reinstall(self): |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1062 | """Reinstall the DUT utilizing servo and a test image. |
| 1063 | |
| 1064 | Re-install the OS on the DUT by: |
| 1065 | 1) installing a test image on a USB storage device attached to the Servo |
| 1066 | board, |
Tom Wai-Hong Tam | 27af733 | 2015-07-25 06:09:39 +0800 | [diff] [blame] | 1067 | 2) booting that image in recovery mode, |
| 1068 | 3) resetting the TPM status, and then |
| 1069 | 4) installing the image with chromeos-install. |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1070 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1071 | @raises AutoservRepairMethodNA if the device does not have servo |
| 1072 | support. |
| 1073 | |
| 1074 | """ |
Dan Shi | c1b8bdd | 2015-09-14 23:11:24 -0700 | [diff] [blame] | 1075 | # To repair a DUT connected to a moblab, try to create a servo object if |
| 1076 | # it was failed to be created earlier as there may be a servo_host host |
| 1077 | # attribute for this host. |
| 1078 | if utils.is_moblab(): |
| 1079 | self._setup_servo() |
| 1080 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1081 | if not self.servo: |
| 1082 | raise error.AutoservRepairMethodNA('Repair Reinstall NA: ' |
| 1083 | 'DUT has no servo support.') |
| 1084 | |
| 1085 | logging.info('Attempting to recovery servo enabled device with ' |
| 1086 | 'servo_repair_reinstall') |
| 1087 | |
J. Richard Barnette | e4af8b9 | 2013-05-01 13:16:12 -0700 | [diff] [blame] | 1088 | image_url = self.stage_image_for_servo() |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1089 | self.servo_install(image_url) |
| 1090 | |
| 1091 | |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 1092 | def _firmware_repair(self): |
| 1093 | """Reinstall the firmware image using servo. |
| 1094 | |
| 1095 | This repair function attempts to install the stable firmware specified |
| 1096 | by the stable firmware version. |
| 1097 | Then reset the DUT and try to verify it. If verify fails, it will try to |
| 1098 | install the CrOS image using servo. |
| 1099 | |
| 1100 | Note that the firmware repair is only applicable to DUTs in pools listed |
| 1101 | in global config CROS/pools_support_firmware_repair. |
| 1102 | """ |
| 1103 | logging.info('Checking if host %s can be repaired with firmware ' |
| 1104 | 'repair.', self.hostname) |
| 1105 | pools = server_utils.get_labels_from_afe(self.hostname, 'pool:', |
| 1106 | self._AFE) |
| 1107 | pools_support_firmware_repair = CONFIG.get_config_value('CROS', |
| 1108 | 'pools_support_firmware_repair', type=str).split(',') |
| 1109 | if (not pools or not pools_support_firmware_repair or |
| 1110 | not set(pools).intersection(set(pools_support_firmware_repair))): |
| 1111 | logging.info('Host %s is not in pools that support firmware repair.' |
| 1112 | ' pools supporting firmware repair are: %s.', |
| 1113 | self.hostname, pools_support_firmware_repair) |
| 1114 | raise error.AutoservRepairMethodNA( |
| 1115 | 'Firmware repair is not applicable to host %s.' % |
| 1116 | self.hostname) |
| 1117 | |
| 1118 | # To repair a DUT connected to a moblab, try to create a servo object if |
| 1119 | # it was failed to be created earlier as there may be a servo_host host |
| 1120 | # attribute for this host. |
| 1121 | if utils.is_moblab(): |
| 1122 | self._setup_servo() |
| 1123 | |
| 1124 | if not self.servo: |
| 1125 | raise error.AutoservRepairMethodNA('Repair Reinstall NA: ' |
| 1126 | 'DUT has no servo support.') |
| 1127 | |
| 1128 | logging.info('Attempting to recovery servo enabled device with ' |
| 1129 | 'firmware_repair.') |
| 1130 | self.firmware_install() |
| 1131 | |
| 1132 | logging.info('Firmware repaired. Check if the DUT can boot. If not, ' |
| 1133 | 'reinstall the CrOS using servo.') |
| 1134 | try: |
| 1135 | self.servo.reset() |
| 1136 | self.verify() |
| 1137 | except Exception as e: |
| 1138 | logging.warn('Failed to verify DUT, error: %s. Will try to repair ' |
| 1139 | 'the DUT with servo_repair_reinstall.', e) |
| 1140 | self._servo_repair_reinstall() |
| 1141 | |
| 1142 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1143 | def _servo_repair_power(self): |
| 1144 | """Attempt to repair DUT using an attached Servo. |
| 1145 | |
| 1146 | Attempt to power on the DUT via power_long_press. |
| 1147 | |
| 1148 | @raises AutoservRepairMethodNA if the device does not have servo |
| 1149 | support. |
| 1150 | @raises AutoservRepairFailure if the repair fails for any reason. |
| 1151 | """ |
| 1152 | if not self.servo: |
| 1153 | raise error.AutoservRepairMethodNA('Repair Power NA: ' |
| 1154 | 'DUT has no servo support.') |
| 1155 | |
| 1156 | logging.info('Attempting to recover servo enabled device by ' |
| 1157 | 'powering it off and on.') |
| 1158 | self.servo.get_power_state_controller().power_off() |
| 1159 | self.servo.get_power_state_controller().power_on() |
| 1160 | if self.wait_up(self.BOOT_TIMEOUT): |
| 1161 | return |
| 1162 | |
| 1163 | raise error.AutoservRepairFailure('DUT did not boot after long_press.') |
Richard Barnette | 03a0c13 | 2012-11-05 12:40:35 -0800 | [diff] [blame] | 1164 | |
| 1165 | |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1166 | def _powercycle_to_repair(self): |
| 1167 | """Utilize the RPM Infrastructure to bring the host back up. |
| 1168 | |
| 1169 | If the host is not up/repaired after the first powercycle we utilize |
| 1170 | auto fallback to the last good install by powercycling and rebooting the |
| 1171 | host 6 times. |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1172 | |
| 1173 | @raises AutoservRepairMethodNA if the device does not support remote |
| 1174 | power. |
| 1175 | @raises AutoservRepairFailure if the repair fails for any reason. |
| 1176 | |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1177 | """ |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1178 | if not self.has_power(): |
| 1179 | raise error.AutoservRepairMethodNA('Device does not support power.') |
| 1180 | |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1181 | logging.info('Attempting repair via RPM powercycle.') |
| 1182 | failed_cycles = 0 |
| 1183 | self.power_cycle() |
| 1184 | while not self.wait_up(timeout=self.BOOT_TIMEOUT): |
| 1185 | failed_cycles += 1 |
| 1186 | if failed_cycles >= self._MAX_POWER_CYCLE_ATTEMPTS: |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1187 | raise error.AutoservRepairFailure( |
| 1188 | 'Powercycled host %s %d times; device did not come back' |
| 1189 | ' online.' % (self.hostname, failed_cycles)) |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1190 | self.power_cycle() |
| 1191 | if failed_cycles == 0: |
| 1192 | logging.info('Powercycling was successful first time.') |
| 1193 | else: |
| 1194 | logging.info('Powercycling was successful after %d failures.', |
| 1195 | failed_cycles) |
| 1196 | |
| 1197 | |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1198 | def _reboot_repair(self): |
| 1199 | """SSH to this host and reboot.""" |
| 1200 | if not self.is_up(self._CHECK_HOST_UP_TIMEOUT_SECS): |
| 1201 | raise error.AutoservRepairMethodNA('DUT unreachable for reboot.') |
| 1202 | logging.info('Attempting repair via SSH reboot.') |
| 1203 | self.reboot(timeout=self.BOOT_TIMEOUT, wait=True) |
| 1204 | |
| 1205 | |
Prashanth B | 4d8184f | 2014-05-05 12:22:02 -0700 | [diff] [blame] | 1206 | def check_device(self): |
| 1207 | """Check if a device is ssh-able, and if so, clean and verify it. |
| 1208 | |
| 1209 | @raise AutoservSSHTimeout: If the ssh ping times out. |
| 1210 | @raise AutoservSshPermissionDeniedError: If ssh ping fails due to |
| 1211 | permissions. |
| 1212 | @raise AutoservSshPingHostError: For other AutoservRunErrors during |
| 1213 | ssh_ping. |
| 1214 | @raises AutoservError: As appropriate, during cleanup and verify. |
| 1215 | """ |
| 1216 | self.ssh_ping() |
| 1217 | self.cleanup() |
| 1218 | self.verify() |
| 1219 | |
| 1220 | |
Dan Shi | 9046635 | 2015-09-22 15:01:05 -0700 | [diff] [blame] | 1221 | def confirm_servo(self): |
| 1222 | """Confirm servo is initialized and verified. |
| 1223 | |
| 1224 | @raise AutoservError: If servo is not initialized and verified. |
| 1225 | """ |
| 1226 | if self._servo_host.required_by_test and self.servo: |
| 1227 | return |
| 1228 | |
| 1229 | # Force to re-create the servo object to make sure servo is verified. |
| 1230 | logging.debug('Rebuilding the servo object.') |
| 1231 | self.servo = None |
| 1232 | self._servo_host = None |
| 1233 | self._setup_servo() |
| 1234 | if not self.servo: |
| 1235 | raise error.AutoservError('Failed to create servo object.') |
| 1236 | |
| 1237 | |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1238 | def _is_last_provision_failed(self): |
| 1239 | """Checks if the last provision job failed. |
| 1240 | |
| 1241 | @return: True if there exists file /var/tmp/provision_failed, which |
| 1242 | indicates the last provision job failed. |
| 1243 | False if the file does not exist or the dut can't be reached. |
| 1244 | """ |
| 1245 | try: |
| 1246 | result = self.run('test -f %s' % PROVISION_FAILED, |
| 1247 | ignore_status=True, timeout=5) |
| 1248 | return result.exit_status == 0 |
| 1249 | except (error.AutoservRunError, error.AutoservSSHTimeout): |
| 1250 | # Default to False, for repair to try all repair method if the dut |
| 1251 | # can't be reached. |
| 1252 | return False |
| 1253 | |
| 1254 | |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1255 | def repair_full(self): |
| 1256 | """Repair a host for repair level NO_PROTECTION. |
| 1257 | |
| 1258 | This overrides the base class function for repair; it does |
| 1259 | not call back to the parent class, but instead offers a |
| 1260 | simplified implementation based on the capabilities in the |
| 1261 | Chrome OS test lab. |
| 1262 | |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 1263 | It first verifies and repairs servo if it is a DUT in CrOS |
Fang Deng | 03590af | 2013-10-07 17:34:20 -0700 | [diff] [blame] | 1264 | lab and a servo is attached. |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 1265 | |
Jakob Juelich | 82b7d1c | 2014-09-15 16:10:57 -0700 | [diff] [blame] | 1266 | This escalates in order through the following procedures and verifies |
| 1267 | the status using `self.check_device()` after each of them. This is done |
| 1268 | until both the repair and the veryfing step succeed. |
| 1269 | |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1270 | Escalation order of repair procedures from less intrusive to |
| 1271 | more intrusive repairs: |
| 1272 | 1. SSH to the DUT and reboot. |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1273 | 2. If there's a servo for the DUT, try to power the DUT off and |
| 1274 | on. |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1275 | 3. If the DUT can be power-cycled via RPM, try to repair |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1276 | by power-cycling. |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1277 | 4. Try to re-install to a known stable image using |
| 1278 | auto-update. |
| 1279 | 5. If there's a servo for the DUT, try to re-install via |
| 1280 | the servo. |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1281 | |
| 1282 | As with the parent method, the last operation performed on |
Prashanth B | 4d8184f | 2014-05-05 12:22:02 -0700 | [diff] [blame] | 1283 | the DUT must be to call `self.check_device()`; If that call fails the |
| 1284 | exception it raises is passed back to the caller. |
J. Richard Barnette | fde55fc | 2013-03-15 17:47:01 -0700 | [diff] [blame] | 1285 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1286 | @raises AutoservRepairTotalFailure if the repair process fails to |
| 1287 | fix the DUT. |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 1288 | @raises ServoHostRepairTotalFailure if the repair process fails to |
| 1289 | fix the servo host if one is attached to the DUT. |
| 1290 | @raises AutoservSshPermissionDeniedError if it is unable |
| 1291 | to ssh to the servo host due to permission error. |
| 1292 | |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1293 | """ |
Jakob Juelich | 82b7d1c | 2014-09-15 16:10:57 -0700 | [diff] [blame] | 1294 | # Caution: Deleting shards relies on repair to always reboot the DUT. |
| 1295 | |
Dan Shi | 4d47852 | 2014-02-14 13:46:32 -0800 | [diff] [blame] | 1296 | if self._servo_host and not self.servo: |
Fang Deng | 03590af | 2013-10-07 17:34:20 -0700 | [diff] [blame] | 1297 | try: |
Dan Shi | 4d47852 | 2014-02-14 13:46:32 -0800 | [diff] [blame] | 1298 | self._servo_host.repair_full() |
Fang Deng | 03590af | 2013-10-07 17:34:20 -0700 | [diff] [blame] | 1299 | except Exception as e: |
Fang Deng | 03590af | 2013-10-07 17:34:20 -0700 | [diff] [blame] | 1300 | logging.error('Could not create a healthy servo: %s', e) |
Dan Shi | 4d47852 | 2014-02-14 13:46:32 -0800 | [diff] [blame] | 1301 | self.servo = self._servo_host.get_servo() |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 1302 | |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1303 | self.try_collect_crashlogs() |
| 1304 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1305 | # TODO(scottz): This should use something similar to label_decorator, |
| 1306 | # but needs to be populated in order so DUTs are repaired with the |
| 1307 | # least amount of effort. |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1308 | force_powerwash = self._is_last_provision_failed() |
| 1309 | if force_powerwash: |
| 1310 | logging.info('Last provision failed, try powerwash first.') |
| 1311 | autotest_stats.Counter( |
| 1312 | 'repair_force_powerwash.TOTAL').increment() |
| 1313 | repair_funcs = [self._install_repair_with_powerwash, |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 1314 | self._servo_repair_reinstall, |
| 1315 | self._firmware_repair] |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1316 | else: |
| 1317 | repair_funcs = [self._reboot_repair, |
| 1318 | self._servo_repair_power, |
| 1319 | self._powercycle_to_repair, |
| 1320 | self._install_repair, |
| 1321 | self._install_repair_with_powerwash, |
Dan Shi | 3d7a0e1 | 2015-10-12 11:55:45 -0700 | [diff] [blame^] | 1322 | self._servo_repair_reinstall, |
| 1323 | self._firmware_repair] |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1324 | errors = [] |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1325 | board = self._get_board_from_afe() |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1326 | for repair_func in repair_funcs: |
| 1327 | try: |
| 1328 | repair_func() |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1329 | self.try_collect_crashlogs() |
Prashanth B | 4d8184f | 2014-05-05 12:22:02 -0700 | [diff] [blame] | 1330 | self.check_device() |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1331 | autotest_stats.Counter( |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1332 | '%s.SUCCEEDED' % repair_func.__name__).increment() |
| 1333 | if board: |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1334 | autotest_stats.Counter( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1335 | '%s.%s.SUCCEEDED' % (repair_func.__name__, |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1336 | board)).increment() |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1337 | if force_powerwash: |
| 1338 | autotest_stats.Counter( |
| 1339 | 'repair_force_powerwash.SUCCEEDED').increment() |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1340 | return |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1341 | except error.AutoservRepairMethodNA as e: |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1342 | autotest_stats.Counter( |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1343 | '%s.RepairNA' % repair_func.__name__).increment() |
| 1344 | if board: |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1345 | autotest_stats.Counter( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1346 | '%s.%s.RepairNA' % (repair_func.__name__, |
| 1347 | board)).increment() |
Ilja H. Friedel | 04be2bd | 2014-05-07 21:29:59 -0700 | [diff] [blame] | 1348 | logging.warning('Repair function NA: %s', e) |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1349 | errors.append(str(e)) |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1350 | except Exception as e: |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1351 | autotest_stats.Counter( |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1352 | '%s.FAILED' % repair_func.__name__).increment() |
| 1353 | if board: |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1354 | autotest_stats.Counter( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1355 | '%s.%s.FAILED' % (repair_func.__name__, |
| 1356 | board)).increment() |
Ilja H. Friedel | 04be2bd | 2014-05-07 21:29:59 -0700 | [diff] [blame] | 1357 | logging.warning('Failed to repair device: %s', e) |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1358 | errors.append(str(e)) |
Scott Zawalski | 89c44dd | 2013-02-26 09:28:02 -0500 | [diff] [blame] | 1359 | |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1360 | if force_powerwash: |
| 1361 | autotest_stats.Counter( |
| 1362 | 'repair_force_powerwash.FAILED').increment() |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1363 | autotest_stats.Counter('Full_Repair_Failed').increment() |
Simran Basi | e613093 | 2013-10-01 14:07:52 -0700 | [diff] [blame] | 1364 | if board: |
Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 1365 | autotest_stats.Counter( |
Dan Shi | d07ee2e | 2015-09-24 14:49:25 -0700 | [diff] [blame] | 1366 | 'Full_Repair_Failed.%s' % board).increment() |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 1367 | raise error.AutoservRepairTotalFailure( |
| 1368 | 'All attempts at repairing the device failed:\n%s' % |
| 1369 | '\n'.join(errors)) |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 1370 | |
| 1371 | |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1372 | def try_collect_crashlogs(self, check_host_up=True): |
| 1373 | """ |
| 1374 | Check if a host is up and logs need to be collected from the host, |
| 1375 | if yes, collect them. |
| 1376 | |
| 1377 | @param check_host_up: Flag for checking host is up. Default is True. |
| 1378 | """ |
| 1379 | try: |
| 1380 | crash_job = self._need_crash_logs() |
| 1381 | if crash_job: |
| 1382 | logging.debug('%s: Job %s was crashed', self._CRASHLOGS_PREFIX, |
| 1383 | crash_job) |
| 1384 | if not check_host_up or self.is_up( |
| 1385 | self._CHECK_HOST_UP_TIMEOUT_SECS): |
| 1386 | self._collect_crashlogs(crash_job) |
| 1387 | logging.debug('%s: Completed collecting logs for the ' |
| 1388 | 'crashed job %s', self._CRASHLOGS_PREFIX, |
| 1389 | crash_job) |
| 1390 | except Exception as e: |
| 1391 | # Exception should not result in repair failure. |
| 1392 | # Therefore, suppress all exceptions here. |
| 1393 | logging.error('%s: Failed while trying to collect crash-logs: %s', |
| 1394 | self._CRASHLOGS_PREFIX, e) |
| 1395 | |
| 1396 | |
| 1397 | def _need_crash_logs(self): |
| 1398 | """Get the value of need_crash_logs attribute of this host. |
| 1399 | |
| 1400 | @return: Value string of need_crash_logs attribute |
| 1401 | None if there is no need_crash_logs attribute |
| 1402 | """ |
| 1403 | attrs = self._AFE.get_host_attribute(constants.CRASHLOGS_HOST_ATTRIBUTE, |
| 1404 | hostname=self.hostname) |
| 1405 | assert len(attrs) < 2 |
| 1406 | return attrs[0].value if attrs else None |
| 1407 | |
| 1408 | |
| 1409 | def _collect_crashlogs(self, job_id): |
| 1410 | """Grab logs from the host where a job was crashed. |
| 1411 | |
| 1412 | First, check if PRIOR_LOGS_DIR exists in the host. |
| 1413 | If yes, collect them. |
| 1414 | Otherwise, check if a lab-machine marker (_LAB_MACHINE_FILE) exists |
| 1415 | in the host. |
| 1416 | If yes, the host was repaired automatically, and we collect normal |
| 1417 | system logs. |
| 1418 | |
| 1419 | @param job_id: Id of the job that was crashed. |
| 1420 | """ |
| 1421 | crashlogs_dir = crashcollect.get_crashinfo_dir(self, |
| 1422 | constants.CRASHLOGS_DEST_DIR_PREFIX) |
| 1423 | flag_prior_logs = False |
| 1424 | |
| 1425 | if self.path_exists(client_constants.PRIOR_LOGS_DIR): |
| 1426 | flag_prior_logs = True |
| 1427 | self._collect_prior_logs(crashlogs_dir) |
| 1428 | elif self.path_exists(self._LAB_MACHINE_FILE): |
| 1429 | self._collect_system_logs(crashlogs_dir) |
| 1430 | else: |
| 1431 | logging.warning('%s: Host was manually re-installed without ' |
| 1432 | '--lab_preserve_log option. Skip collecting ' |
| 1433 | 'crash-logs.', self._CRASHLOGS_PREFIX) |
| 1434 | |
| 1435 | # We make crash collection be one-time effort. |
| 1436 | # _collect_prior_logs() and _collect_system_logs() will not throw |
| 1437 | # any exception, and following codes will be executed even when |
| 1438 | # those methods fail. |
| 1439 | # _collect_crashlogs() is called only when the host is up (refer |
| 1440 | # to try_collect_crashlogs()). We assume _collect_prior_logs() and |
| 1441 | # _collect_system_logs() fail rarely when the host is up. |
| 1442 | # In addition, it is not clear how many times we should try crash |
| 1443 | # collection again while not triggering next repair unnecessarily. |
| 1444 | # Threfore, we try crash collection one time. |
| 1445 | |
| 1446 | # Create a marker file as soon as log collection is done. |
| 1447 | # Leave the job id to this marker for gs_offloader to consume. |
| 1448 | marker_file = os.path.join(crashlogs_dir, constants.CRASHLOGS_MARKER) |
| 1449 | with open(marker_file, 'a') as f: |
| 1450 | f.write('%s\n' % job_id) |
| 1451 | |
| 1452 | # Remove need_crash_logs attribute |
| 1453 | logging.debug('%s: Remove attribute need_crash_logs from host %s', |
| 1454 | self._CRASHLOGS_PREFIX, self.hostname) |
| 1455 | self._AFE.set_host_attribute(constants.CRASHLOGS_HOST_ATTRIBUTE, |
| 1456 | None, hostname=self.hostname) |
| 1457 | |
| 1458 | if flag_prior_logs: |
| 1459 | logging.debug('%s: Remove %s from host %s', self._CRASHLOGS_PREFIX, |
| 1460 | client_constants.PRIOR_LOGS_DIR, self.hostname) |
| 1461 | self.run('rm -rf %s; sync' % client_constants.PRIOR_LOGS_DIR) |
| 1462 | # Wait for a few seconds to make sure the prior command is |
| 1463 | # done deep through storage. |
| 1464 | time.sleep(self._SAFE_WAIT_SECS) |
| 1465 | |
| 1466 | |
| 1467 | def _collect_prior_logs(self, crashlogs_dir): |
| 1468 | """Grab prior logs that were stashed before re-installing a host. |
| 1469 | |
| 1470 | @param crashlogs_dir: Directory path where crash-logs are stored. |
| 1471 | """ |
| 1472 | logging.debug('%s: Found %s, collecting them...', |
| 1473 | self._CRASHLOGS_PREFIX, client_constants.PRIOR_LOGS_DIR) |
| 1474 | try: |
| 1475 | self.collect_logs(client_constants.PRIOR_LOGS_DIR, |
| 1476 | crashlogs_dir, False) |
| 1477 | logging.debug('%s: %s is collected', |
| 1478 | self._CRASHLOGS_PREFIX, client_constants.PRIOR_LOGS_DIR) |
| 1479 | except Exception as e: |
| 1480 | logging.error('%s: Failed to collect %s: %s', |
| 1481 | self._CRASHLOGS_PREFIX, client_constants.PRIOR_LOGS_DIR, |
| 1482 | e) |
| 1483 | |
| 1484 | |
| 1485 | def _collect_system_logs(self, crashlogs_dir): |
| 1486 | """Grab normal system logs from a host. |
| 1487 | |
| 1488 | @param crashlogs_dir: Directory path where crash-logs are stored. |
| 1489 | """ |
| 1490 | logging.debug('%s: Found %s, collecting system logs...', |
| 1491 | self._CRASHLOGS_PREFIX, self._LAB_MACHINE_FILE) |
| 1492 | sources = server_utils.parse_simple_config(self._LOGS_TO_COLLECT_FILE) |
| 1493 | for src in sources: |
| 1494 | try: |
| 1495 | if self.path_exists(src): |
| 1496 | logging.debug('%s: Collecting %s...', |
| 1497 | self._CRASHLOGS_PREFIX, src) |
| 1498 | dest = server_utils.concat_path_except_last( |
| 1499 | crashlogs_dir, src) |
| 1500 | self.collect_logs(src, dest, False) |
| 1501 | logging.debug('%s: %s is collected', |
| 1502 | self._CRASHLOGS_PREFIX, src) |
| 1503 | except Exception as e: |
| 1504 | logging.error('%s: Failed to collect %s: %s', |
| 1505 | self._CRASHLOGS_PREFIX, src, e) |
| 1506 | |
| 1507 | |
J. Richard Barnette | 1d78b01 | 2012-05-15 13:56:30 -0700 | [diff] [blame] | 1508 | def close(self): |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 1509 | super(CrosHost, self).close() |
J. Richard Barnette | 1d78b01 | 2012-05-15 13:56:30 -0700 | [diff] [blame] | 1510 | |
| 1511 | |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1512 | def get_power_supply_info(self): |
| 1513 | """Get the output of power_supply_info. |
| 1514 | |
| 1515 | power_supply_info outputs the info of each power supply, e.g., |
| 1516 | Device: Line Power |
| 1517 | online: no |
| 1518 | type: Mains |
| 1519 | voltage (V): 0 |
| 1520 | current (A): 0 |
| 1521 | Device: Battery |
| 1522 | state: Discharging |
| 1523 | percentage: 95.9276 |
| 1524 | technology: Li-ion |
| 1525 | |
| 1526 | Above output shows two devices, Line Power and Battery, with details of |
| 1527 | each device listed. This function parses the output into a dictionary, |
| 1528 | with key being the device name, and value being a dictionary of details |
| 1529 | of the device info. |
| 1530 | |
| 1531 | @return: The dictionary of power_supply_info, e.g., |
| 1532 | {'Line Power': {'online': 'yes', 'type': 'main'}, |
| 1533 | 'Battery': {'vendor': 'xyz', 'percentage': '100'}} |
Dan Shi | e9b765d | 2014-12-29 16:59:49 -0800 | [diff] [blame] | 1534 | @raise error.AutoservRunError if power_supply_info tool is not found in |
| 1535 | the DUT. Caller should handle this error to avoid false failure |
| 1536 | on verification. |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1537 | """ |
| 1538 | result = self.run('power_supply_info').stdout.strip() |
| 1539 | info = {} |
| 1540 | device_name = None |
| 1541 | device_info = {} |
| 1542 | for line in result.split('\n'): |
| 1543 | pair = [v.strip() for v in line.split(':')] |
| 1544 | if len(pair) != 2: |
| 1545 | continue |
| 1546 | if pair[0] == 'Device': |
| 1547 | if device_name: |
| 1548 | info[device_name] = device_info |
| 1549 | device_name = pair[1] |
| 1550 | device_info = {} |
| 1551 | else: |
| 1552 | device_info[pair[0]] = pair[1] |
| 1553 | if device_name and not device_name in info: |
| 1554 | info[device_name] = device_info |
| 1555 | return info |
| 1556 | |
| 1557 | |
| 1558 | def get_battery_percentage(self): |
| 1559 | """Get the battery percentage. |
| 1560 | |
| 1561 | @return: The percentage of battery level, value range from 0-100. Return |
| 1562 | None if the battery info cannot be retrieved. |
| 1563 | """ |
| 1564 | try: |
| 1565 | info = self.get_power_supply_info() |
| 1566 | logging.info(info) |
| 1567 | return float(info['Battery']['percentage']) |
Dan Shi | e9b765d | 2014-12-29 16:59:49 -0800 | [diff] [blame] | 1568 | except (KeyError, ValueError, error.AutoservRunError): |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1569 | return None |
| 1570 | |
| 1571 | |
| 1572 | def is_ac_connected(self): |
| 1573 | """Check if the dut has power adapter connected and charging. |
| 1574 | |
| 1575 | @return: True if power adapter is connected and charging. |
| 1576 | """ |
| 1577 | try: |
| 1578 | info = self.get_power_supply_info() |
| 1579 | return info['Line Power']['online'] == 'yes' |
Dan Shi | e9b765d | 2014-12-29 16:59:49 -0800 | [diff] [blame] | 1580 | except (KeyError, error.AutoservRunError): |
| 1581 | return None |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1582 | |
| 1583 | |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 1584 | def _cleanup_poweron(self): |
| 1585 | """Special cleanup method to make sure hosts always get power back.""" |
| 1586 | afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10) |
| 1587 | hosts = afe.get_hosts(hostname=self.hostname) |
| 1588 | if not hosts or not (self._RPM_OUTLET_CHANGED in |
| 1589 | hosts[0].attributes): |
| 1590 | return |
| 1591 | logging.debug('This host has recently interacted with the RPM' |
| 1592 | ' Infrastructure. Ensuring power is on.') |
| 1593 | try: |
| 1594 | self.power_on() |
Dan Shi | 7dca56e | 2014-11-11 17:07:56 -0800 | [diff] [blame] | 1595 | afe.set_host_attribute(self._RPM_OUTLET_CHANGED, None, |
| 1596 | hostname=self.hostname) |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 1597 | except rpm_client.RemotePowerException: |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 1598 | logging.error('Failed to turn Power On for this host after ' |
| 1599 | 'cleanup through the RPM Infrastructure.') |
Gabe Black | b72f4fb | 2015-01-20 16:47:13 -0800 | [diff] [blame] | 1600 | autotest_es.post( |
Dan Shi | 7dca56e | 2014-11-11 17:07:56 -0800 | [diff] [blame] | 1601 | type_str='RPM_poweron_failure', |
| 1602 | metadata={'hostname': self.hostname}) |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1603 | |
| 1604 | battery_percentage = self.get_battery_percentage() |
Dan Shi | f01ebe2 | 2014-12-05 13:10:57 -0800 | [diff] [blame] | 1605 | if battery_percentage and battery_percentage < 50: |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1606 | raise |
| 1607 | elif self.is_ac_connected(): |
| 1608 | logging.info('The device has power adapter connected and ' |
| 1609 | 'charging. No need to try to turn RPM on ' |
| 1610 | 'again.') |
| 1611 | afe.set_host_attribute(self._RPM_OUTLET_CHANGED, None, |
| 1612 | hostname=self.hostname) |
| 1613 | logging.info('Battery level is now at %s%%. The device may ' |
| 1614 | 'still have enough power to run test, so no ' |
| 1615 | 'exception will be raised.', battery_percentage) |
| 1616 | |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 1617 | |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1618 | def _is_factory_image(self): |
| 1619 | """Checks if the image on the DUT is a factory image. |
| 1620 | |
| 1621 | @return: True if the image on the DUT is a factory image. |
| 1622 | False otherwise. |
| 1623 | """ |
| 1624 | result = self.run('[ -f /root/.factory_test ]', ignore_status=True) |
| 1625 | return result.exit_status == 0 |
| 1626 | |
| 1627 | |
| 1628 | def _restart_ui(self): |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 1629 | """Restart the Chrome UI. |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1630 | |
| 1631 | @raises: FactoryImageCheckerException for factory images, since |
| 1632 | we cannot attempt to restart ui on them. |
| 1633 | error.AutoservRunError for any other type of error that |
| 1634 | occurs while restarting ui. |
| 1635 | """ |
| 1636 | if self._is_factory_image(): |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 1637 | raise FactoryImageCheckerException('Cannot restart ui on factory ' |
| 1638 | 'images') |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1639 | |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 1640 | # TODO(jrbarnette): The command to stop/start the ui job |
| 1641 | # should live inside cros_ui, too. However that would seem |
| 1642 | # to imply interface changes to the existing start()/restart() |
| 1643 | # functions, which is a bridge too far (for now). |
J. Richard Barnette | 6069aa1 | 2015-06-08 09:10:24 -0700 | [diff] [blame] | 1644 | prompt = cros_ui.get_chrome_session_ident(self) |
J. Richard Barnette | 84890bd | 2014-02-21 11:05:47 -0800 | [diff] [blame] | 1645 | self.run('stop ui; start ui') |
| 1646 | cros_ui.wait_for_chrome_ready(prompt, self) |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1647 | |
| 1648 | |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 1649 | def get_release_version(self): |
| 1650 | """Get the value of attribute CHROMEOS_RELEASE_VERSION from lsb-release. |
| 1651 | |
| 1652 | @returns The version string in lsb-release, under attribute |
| 1653 | CHROMEOS_RELEASE_VERSION. |
| 1654 | """ |
| 1655 | lsb_release_content = self.run( |
| 1656 | 'cat "%s"' % client_constants.LSB_RELEASE).stdout.strip() |
| 1657 | return lsbrelease_utils.get_chromeos_release_version( |
| 1658 | lsb_release_content=lsb_release_content) |
| 1659 | |
| 1660 | |
| 1661 | def verify_cros_version_label(self): |
| 1662 | """ Make sure host's cros-version label match the actual image in dut. |
| 1663 | |
| 1664 | Remove any cros-version: label that doesn't match that installed in |
| 1665 | the dut. |
| 1666 | |
| 1667 | @param raise_error: Set to True to raise exception if any mismatch found |
| 1668 | |
| 1669 | @raise error.AutoservError: If any mismatch between cros-version label |
| 1670 | and the build installed in dut is found. |
| 1671 | """ |
| 1672 | labels = self._AFE.get_labels( |
| 1673 | name__startswith=ds_constants.VERSION_PREFIX, |
| 1674 | host__hostname=self.hostname) |
| 1675 | mismatch_found = False |
| 1676 | if labels: |
| 1677 | # Get CHROMEOS_RELEASE_VERSION from lsb-release, e.g., 6908.0.0. |
| 1678 | # Note that it's different from cros-version label, which has |
| 1679 | # builder and branch info, e.g., |
| 1680 | # cros-version:peppy-release/R43-6908.0.0 |
| 1681 | release_version = self.get_release_version() |
| 1682 | host_list = [self.hostname] |
| 1683 | for label in labels: |
| 1684 | # Remove any cros-version label that does not match |
| 1685 | # release_version. |
| 1686 | build_version = label.name[len(ds_constants.VERSION_PREFIX):] |
| 1687 | if not utils.version_match(build_version, release_version): |
| 1688 | logging.warn('cros-version label "%s" does not match ' |
| 1689 | 'release version %s. Removing the label.', |
| 1690 | label.name, release_version) |
| 1691 | label.remove_hosts(hosts=host_list) |
| 1692 | mismatch_found = True |
| 1693 | if mismatch_found: |
Dan Shi | 1057bae | 2015-03-30 11:35:09 -0700 | [diff] [blame] | 1694 | autotest_es.post(use_http=True, |
| 1695 | type_str='cros_version_label_mismatch', |
| 1696 | metadata={'hostname': self.hostname}) |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 1697 | raise error.AutoservError('The host has wrong cros-version label.') |
| 1698 | |
| 1699 | |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1700 | def cleanup(self): |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1701 | self.run('rm -f %s' % client_constants.CLEANUP_LOGS_PAUSED_FILE) |
Scott Zawalski | ddbc31e | 2012-11-15 11:29:01 -0500 | [diff] [blame] | 1702 | try: |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1703 | self._restart_ui() |
| 1704 | except (error.AutotestRunError, error.AutoservRunError, |
| 1705 | FactoryImageCheckerException): |
Ilja H. Friedel | 04be2bd | 2014-05-07 21:29:59 -0700 | [diff] [blame] | 1706 | logging.warning('Unable to restart ui, rebooting device.') |
Scott Zawalski | ddbc31e | 2012-11-15 11:29:01 -0500 | [diff] [blame] | 1707 | # Since restarting the UI fails fall back to normal Autotest |
| 1708 | # cleanup routines, i.e. reboot the machine. |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 1709 | super(CrosHost, self).cleanup() |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 1710 | # Check if the rpm outlet was manipulated. |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 1711 | if self.has_power(): |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 1712 | self._cleanup_poweron() |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 1713 | self.verify_cros_version_label() |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 1714 | |
| 1715 | |
Yu-Ju Hong | a2be94a | 2012-07-31 09:48:52 -0700 | [diff] [blame] | 1716 | def reboot(self, **dargs): |
| 1717 | """ |
| 1718 | This function reboots the site host. The more generic |
| 1719 | RemoteHost.reboot() performs sync and sleeps for 5 |
| 1720 | seconds. This is not necessary for Chrome OS devices as the |
| 1721 | sync should be finished in a short time during the reboot |
| 1722 | command. |
| 1723 | """ |
Tom Wai-Hong Tam | f5cd1d4 | 2012-08-13 12:04:08 +0800 | [diff] [blame] | 1724 | if 'reboot_cmd' not in dargs: |
Doug Anderson | 7d5aeb2 | 2014-02-27 15:12:17 -0800 | [diff] [blame] | 1725 | reboot_timeout = dargs.get('reboot_timeout', 10) |
J. Richard Barnette | 9af1963 | 2015-09-25 12:18:03 -0700 | [diff] [blame] | 1726 | dargs['reboot_cmd'] = ('sleep 1; ' |
| 1727 | 'reboot & sleep %d; ' |
| 1728 | 'reboot -f' % reboot_timeout) |
Yu-Ju Hong | a2be94a | 2012-07-31 09:48:52 -0700 | [diff] [blame] | 1729 | # Enable fastsync to avoid running extra sync commands before reboot. |
Tom Wai-Hong Tam | f5cd1d4 | 2012-08-13 12:04:08 +0800 | [diff] [blame] | 1730 | if 'fastsync' not in dargs: |
| 1731 | dargs['fastsync'] = True |
Michael Liang | da8c60a | 2014-06-03 13:24:51 -0700 | [diff] [blame] | 1732 | |
Charlie Mooney | a8e6dab | 2014-05-29 14:37:55 -0700 | [diff] [blame] | 1733 | # For purposes of logging reboot times: |
| 1734 | # Get the board name i.e. 'daisy_spring' |
Michael Liang | ca4f5a6 | 2014-07-10 15:45:13 -0700 | [diff] [blame] | 1735 | board_fullname = self.get_board() |
| 1736 | |
| 1737 | # Strip the prefix and add it to dargs. |
| 1738 | dargs['board'] = board_fullname[board_fullname.find(':')+1:] |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 1739 | super(CrosHost, self).reboot(**dargs) |
Yu-Ju Hong | a2be94a | 2012-07-31 09:48:52 -0700 | [diff] [blame] | 1740 | |
| 1741 | |
Gwendal Grignou | 7a61d2f | 2014-05-23 11:05:51 -0700 | [diff] [blame] | 1742 | def suspend(self, **dargs): |
| 1743 | """ |
| 1744 | This function suspends the site host. |
| 1745 | """ |
| 1746 | suspend_time = dargs.get('suspend_time', 60) |
| 1747 | dargs['timeout'] = suspend_time |
| 1748 | if 'suspend_cmd' not in dargs: |
J. Richard Barnette | 9af1963 | 2015-09-25 12:18:03 -0700 | [diff] [blame] | 1749 | dargs['suspend_cmd'] = ' && '.join([ |
| 1750 | 'echo 0 > /sys/class/rtc/rtc0/wakealarm', |
Gwendal Grignou | 7a61d2f | 2014-05-23 11:05:51 -0700 | [diff] [blame] | 1751 | 'echo +%d > /sys/class/rtc/rtc0/wakealarm' % suspend_time, |
J. Richard Barnette | 9af1963 | 2015-09-25 12:18:03 -0700 | [diff] [blame] | 1752 | 'powerd_dbus_suspend --delay=0']) |
Gwendal Grignou | 7a61d2f | 2014-05-23 11:05:51 -0700 | [diff] [blame] | 1753 | super(CrosHost, self).suspend(**dargs) |
| 1754 | |
| 1755 | |
Simran Basi | ec56439 | 2014-08-25 16:48:09 -0700 | [diff] [blame] | 1756 | def upstart_status(self, service_name): |
| 1757 | """Check the status of an upstart init script. |
| 1758 | |
| 1759 | @param service_name: Service to look up. |
| 1760 | |
| 1761 | @returns True if the service is running, False otherwise. |
| 1762 | """ |
| 1763 | return self.run('status %s | grep start/running' % |
| 1764 | service_name).stdout.strip() != '' |
| 1765 | |
| 1766 | |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 1767 | def verify_software(self): |
Richard Barnette | b2bc13c | 2013-01-08 17:32:51 -0800 | [diff] [blame] | 1768 | """Verify working software on a Chrome OS system. |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 1769 | |
Richard Barnette | b2bc13c | 2013-01-08 17:32:51 -0800 | [diff] [blame] | 1770 | Tests for the following conditions: |
| 1771 | 1. All conditions tested by the parent version of this |
| 1772 | function. |
| 1773 | 2. Sufficient space in /mnt/stateful_partition. |
Fang Deng | 6b05f5b | 2013-03-20 13:42:11 -0700 | [diff] [blame] | 1774 | 3. Sufficient space in /mnt/stateful_partition/encrypted. |
| 1775 | 4. update_engine answers a simple status request over DBus. |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 1776 | |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 1777 | """ |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 1778 | # Check if a job was crashed on this host. |
| 1779 | # If yes, avoid verification until crash-logs are collected. |
| 1780 | if self._need_crash_logs(): |
| 1781 | raise error.AutoservCrashLogCollectRequired( |
| 1782 | 'Need to collect crash-logs before verification') |
| 1783 | |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 1784 | super(CrosHost, self).verify_software() |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 1785 | default_kilo_inodes_required = CONFIG.get_config_value( |
| 1786 | 'SERVER', 'kilo_inodes_required', type=int, default=100) |
| 1787 | board = self.get_board().replace(ds_constants.BOARD_PREFIX, '') |
| 1788 | kilo_inodes_required = CONFIG.get_config_value( |
| 1789 | 'SERVER', 'kilo_inodes_required_%s' % board, |
| 1790 | type=int, default=default_kilo_inodes_required) |
| 1791 | self.check_inodes('/mnt/stateful_partition', kilo_inodes_required) |
J. Richard Barnette | 45e93de | 2012-04-11 17:24:15 -0700 | [diff] [blame] | 1792 | self.check_diskspace( |
| 1793 | '/mnt/stateful_partition', |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 1794 | CONFIG.get_config_value( |
Fang Deng | 6b05f5b | 2013-03-20 13:42:11 -0700 | [diff] [blame] | 1795 | 'SERVER', 'gb_diskspace_required', type=float, |
| 1796 | default=20.0)) |
Gaurav Shah | e448af8 | 2014-06-19 15:18:59 -0700 | [diff] [blame] | 1797 | encrypted_stateful_path = '/mnt/stateful_partition/encrypted' |
| 1798 | # Not all targets build with encrypted stateful support. |
| 1799 | if self.path_exists(encrypted_stateful_path): |
| 1800 | self.check_diskspace( |
| 1801 | encrypted_stateful_path, |
Dan Shi | b8540a5 | 2015-07-16 14:18:23 -0700 | [diff] [blame] | 1802 | CONFIG.get_config_value( |
Gaurav Shah | e448af8 | 2014-06-19 15:18:59 -0700 | [diff] [blame] | 1803 | 'SERVER', 'gb_encrypted_diskspace_required', type=float, |
| 1804 | default=0.1)) |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1805 | |
Simran Basi | ec56439 | 2014-08-25 16:48:09 -0700 | [diff] [blame] | 1806 | if not self.upstart_status('system-services'): |
Prashanth B | 5d0a051 | 2014-04-25 12:26:08 -0700 | [diff] [blame] | 1807 | raise error.AutoservError('Chrome failed to reach login. ' |
| 1808 | 'System services not running.') |
| 1809 | |
beeps | c87ff60 | 2013-07-31 21:53:00 -0700 | [diff] [blame] | 1810 | # Factory images don't run update engine, |
| 1811 | # goofy controls dbus on these DUTs. |
| 1812 | if not self._is_factory_image(): |
| 1813 | self.run('update_engine_client --status') |
Scott Zawalski | fbca4a9 | 2013-03-04 15:56:42 -0500 | [diff] [blame] | 1814 | # Makes sure python is present, loads and can use built in functions. |
| 1815 | # We have seen cases where importing cPickle fails with undefined |
| 1816 | # symbols in cPickle.so. |
| 1817 | self.run('python -c "import cPickle"') |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1818 | |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 1819 | self.verify_cros_version_label() |
| 1820 | |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1821 | |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1822 | def verify_hardware(self): |
| 1823 | """Verify hardware system of a Chrome OS system. |
| 1824 | |
| 1825 | Check following hardware conditions: |
| 1826 | 1. Battery level. |
| 1827 | 2. Is power adapter connected. |
| 1828 | """ |
| 1829 | logging.info('Battery percentage: %s', self.get_battery_percentage()) |
Dan Shi | e9b765d | 2014-12-29 16:59:49 -0800 | [diff] [blame] | 1830 | if self.is_ac_connected() is None: |
| 1831 | logging.info('Can not determine if the device has power adapter ' |
| 1832 | 'connected.') |
| 1833 | else: |
| 1834 | logging.info('Device %s power adapter connected and charging.', |
| 1835 | 'has' if self.is_ac_connected() else 'does not have') |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 1836 | |
| 1837 | |
Fang Deng | 96667ca | 2013-08-01 17:46:18 -0700 | [diff] [blame] | 1838 | def make_ssh_command(self, user='root', port=22, opts='', hosts_file=None, |
| 1839 | connect_timeout=None, alive_interval=None): |
| 1840 | """Override default make_ssh_command to use options tuned for Chrome OS. |
| 1841 | |
| 1842 | Tuning changes: |
| 1843 | - ConnectTimeout=30; maximum of 30 seconds allowed for an SSH |
| 1844 | connection failure. Consistency with remote_access.sh. |
| 1845 | |
Samuel Tan | 2ce155b | 2015-06-23 18:24:38 -0700 | [diff] [blame] | 1846 | - ServerAliveInterval=900; which causes SSH to ping connection every |
| 1847 | 900 seconds. In conjunction with ServerAliveCountMax ensures |
| 1848 | that if the connection dies, Autotest will bail out. |
Fang Deng | 96667ca | 2013-08-01 17:46:18 -0700 | [diff] [blame] | 1849 | Originally tried 60 secs, but saw frequent job ABORTS where |
Samuel Tan | 2ce155b | 2015-06-23 18:24:38 -0700 | [diff] [blame] | 1850 | the test completed successfully. Later increased from 180 seconds to |
| 1851 | 900 seconds to account for tests where the DUT is suspended for |
| 1852 | longer periods of time. |
Fang Deng | 96667ca | 2013-08-01 17:46:18 -0700 | [diff] [blame] | 1853 | |
| 1854 | - ServerAliveCountMax=3; consistency with remote_access.sh. |
| 1855 | |
| 1856 | - ConnectAttempts=4; reduce flakiness in connection errors; |
| 1857 | consistency with remote_access.sh. |
| 1858 | |
| 1859 | - UserKnownHostsFile=/dev/null; we don't care about the keys. |
| 1860 | Host keys change with every new installation, don't waste |
| 1861 | memory/space saving them. |
| 1862 | |
| 1863 | - SSH protocol forced to 2; needed for ServerAliveInterval. |
| 1864 | |
| 1865 | @param user User name to use for the ssh connection. |
| 1866 | @param port Port on the target host to use for ssh connection. |
| 1867 | @param opts Additional options to the ssh command. |
| 1868 | @param hosts_file Ignored. |
| 1869 | @param connect_timeout Ignored. |
| 1870 | @param alive_interval Ignored. |
| 1871 | """ |
Aviv Keshet | c5947fa | 2013-09-04 14:06:29 -0700 | [diff] [blame] | 1872 | base_command = ('/usr/bin/ssh -a -x %s %s %s' |
| 1873 | ' -o StrictHostKeyChecking=no' |
Fang Deng | 96667ca | 2013-08-01 17:46:18 -0700 | [diff] [blame] | 1874 | ' -o UserKnownHostsFile=/dev/null -o BatchMode=yes' |
Samuel Tan | 2ce155b | 2015-06-23 18:24:38 -0700 | [diff] [blame] | 1875 | ' -o ConnectTimeout=30 -o ServerAliveInterval=900' |
Fang Deng | 96667ca | 2013-08-01 17:46:18 -0700 | [diff] [blame] | 1876 | ' -o ServerAliveCountMax=3 -o ConnectionAttempts=4' |
| 1877 | ' -o Protocol=2 -l %s -p %d') |
Aviv Keshet | c5947fa | 2013-09-04 14:06:29 -0700 | [diff] [blame] | 1878 | return base_command % (self._ssh_verbosity_flag, self._ssh_options, |
| 1879 | opts, user, port) |
Jason Abele | b6f924f | 2013-11-13 16:01:54 -0800 | [diff] [blame] | 1880 | def syslog(self, message, tag='autotest'): |
| 1881 | """Logs a message to syslog on host. |
| 1882 | |
| 1883 | @param message String message to log into syslog |
| 1884 | @param tag String tag prefix for syslog |
| 1885 | |
| 1886 | """ |
| 1887 | self.run('logger -t "%s" "%s"' % (tag, message)) |
| 1888 | |
| 1889 | |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 1890 | def _ping_check_status(self, status): |
| 1891 | """Ping the host once, and return whether it has a given status. |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1892 | |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 1893 | @param status Check the ping status against this value. |
| 1894 | @return True iff `status` and the result of ping are the same |
| 1895 | (i.e. both True or both False). |
| 1896 | |
| 1897 | """ |
| 1898 | ping_val = utils.ping(self.hostname, tries=1, deadline=1) |
| 1899 | return not (status ^ (ping_val == 0)) |
| 1900 | |
| 1901 | def _ping_wait_for_status(self, status, timeout): |
| 1902 | """Wait for the host to have a given status (UP or DOWN). |
| 1903 | |
| 1904 | Status is checked by polling. Polling will not last longer |
| 1905 | than the number of seconds in `timeout`. The polling |
| 1906 | interval will be long enough that only approximately |
| 1907 | _PING_WAIT_COUNT polling cycles will be executed, subject |
| 1908 | to a maximum interval of about one minute. |
| 1909 | |
| 1910 | @param status Waiting will stop immediately if `ping` of the |
| 1911 | host returns this status. |
| 1912 | @param timeout Poll for at most this many seconds. |
| 1913 | @return True iff the host status from `ping` matched the |
| 1914 | requested status at the time of return. |
| 1915 | |
| 1916 | """ |
| 1917 | # _ping_check_status() takes about 1 second, hence the |
| 1918 | # "- 1" in the formula below. |
| 1919 | poll_interval = min(int(timeout / self._PING_WAIT_COUNT), 60) - 1 |
| 1920 | end_time = time.time() + timeout |
| 1921 | while time.time() <= end_time: |
| 1922 | if self._ping_check_status(status): |
| 1923 | return True |
| 1924 | if poll_interval > 0: |
| 1925 | time.sleep(poll_interval) |
| 1926 | |
| 1927 | # The last thing we did was sleep(poll_interval), so it may |
| 1928 | # have been too long since the last `ping`. Check one more |
| 1929 | # time, just to be sure. |
| 1930 | return self._ping_check_status(status) |
| 1931 | |
| 1932 | def ping_wait_up(self, timeout): |
| 1933 | """Wait for the host to respond to `ping`. |
| 1934 | |
| 1935 | N.B. This method is not a reliable substitute for |
| 1936 | `wait_up()`, because a host that responds to ping will not |
| 1937 | necessarily respond to ssh. This method should only be used |
| 1938 | if the target DUT can be considered functional even if it |
| 1939 | can't be reached via ssh. |
| 1940 | |
| 1941 | @param timeout Minimum time to allow before declaring the |
| 1942 | host to be non-responsive. |
| 1943 | @return True iff the host answered to ping before the timeout. |
| 1944 | |
| 1945 | """ |
| 1946 | return self._ping_wait_for_status(self._PING_STATUS_UP, timeout) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1947 | |
Andrew Bresticker | 678c0c7 | 2013-01-22 10:44:09 -0800 | [diff] [blame] | 1948 | def ping_wait_down(self, timeout): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1949 | """Wait until the host no longer responds to `ping`. |
| 1950 | |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 1951 | This function can be used as a slightly faster version of |
| 1952 | `wait_down()`, by avoiding potentially long ssh timeouts. |
| 1953 | |
| 1954 | @param timeout Minimum time to allow for the host to become |
| 1955 | non-responsive. |
| 1956 | @return True iff the host quit answering ping before the |
| 1957 | timeout. |
| 1958 | |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1959 | """ |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 1960 | return self._ping_wait_for_status(self._PING_STATUS_DOWN, timeout) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1961 | |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 1962 | def test_wait_for_sleep(self, sleep_timeout=None): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1963 | """Wait for the client to enter low-power sleep mode. |
| 1964 | |
| 1965 | The test for "is asleep" can't distinguish a system that is |
| 1966 | powered off; to confirm that the unit was asleep, it is |
| 1967 | necessary to force resume, and then call |
| 1968 | `test_wait_for_resume()`. |
| 1969 | |
| 1970 | This function is expected to be called from a test as part |
| 1971 | of a sequence like the following: |
| 1972 | |
| 1973 | ~~~~~~~~ |
| 1974 | boot_id = host.get_boot_id() |
| 1975 | # trigger sleep on the host |
| 1976 | host.test_wait_for_sleep() |
| 1977 | # trigger resume on the host |
| 1978 | host.test_wait_for_resume(boot_id) |
| 1979 | ~~~~~~~~ |
| 1980 | |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 1981 | @param sleep_timeout time limit in seconds to allow the host sleep. |
| 1982 | |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1983 | @exception TestFail The host did not go to sleep within |
| 1984 | the allowed time. |
| 1985 | """ |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 1986 | if sleep_timeout is None: |
| 1987 | sleep_timeout = self.SLEEP_TIMEOUT |
| 1988 | |
| 1989 | if not self.ping_wait_down(timeout=sleep_timeout): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1990 | raise error.TestFail( |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 1991 | 'client failed to sleep after %d seconds' % sleep_timeout) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1992 | |
| 1993 | |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 1994 | def test_wait_for_resume(self, old_boot_id, resume_timeout=None): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 1995 | """Wait for the client to resume from low-power sleep mode. |
| 1996 | |
| 1997 | The `old_boot_id` parameter should be the value from |
| 1998 | `get_boot_id()` obtained prior to entering sleep mode. A |
| 1999 | `TestFail` exception is raised if the boot id changes. |
| 2000 | |
| 2001 | See @ref test_wait_for_sleep for more on this function's |
| 2002 | usage. |
| 2003 | |
J. Richard Barnette | 7214e0b | 2013-02-06 15:20:49 -0800 | [diff] [blame] | 2004 | @param old_boot_id A boot id value obtained before the |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2005 | target host went to sleep. |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 2006 | @param resume_timeout time limit in seconds to allow the host up. |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2007 | |
| 2008 | @exception TestFail The host did not respond within the |
| 2009 | allowed time. |
| 2010 | @exception TestFail The host responded, but the boot id test |
| 2011 | indicated a reboot rather than a sleep |
| 2012 | cycle. |
| 2013 | """ |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 2014 | if resume_timeout is None: |
| 2015 | resume_timeout = self.RESUME_TIMEOUT |
| 2016 | |
| 2017 | if not self.wait_up(timeout=resume_timeout): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2018 | raise error.TestFail( |
| 2019 | 'client failed to resume from sleep after %d seconds' % |
Tom Wai-Hong Tam | fced4f6 | 2014-04-17 10:56:30 +0800 | [diff] [blame] | 2020 | resume_timeout) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2021 | else: |
| 2022 | new_boot_id = self.get_boot_id() |
| 2023 | if new_boot_id != old_boot_id: |
Tom Wai-Hong Tam | 0179268 | 2015-01-06 08:00:46 +0800 | [diff] [blame] | 2024 | logging.error('client rebooted (old boot %s, new boot %s)', |
| 2025 | old_boot_id, new_boot_id) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2026 | raise error.TestFail( |
Tom Wai-Hong Tam | 0179268 | 2015-01-06 08:00:46 +0800 | [diff] [blame] | 2027 | 'client rebooted, but sleep was expected') |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2028 | |
| 2029 | |
Tom Wai-Hong Tam | fe005c2 | 2014-12-03 09:25:44 +0800 | [diff] [blame] | 2030 | def test_wait_for_shutdown(self, shutdown_timeout=None): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2031 | """Wait for the client to shut down. |
| 2032 | |
| 2033 | The test for "has shut down" can't distinguish a system that |
| 2034 | is merely asleep; to confirm that the unit was down, it is |
| 2035 | necessary to force boot, and then call test_wait_for_boot(). |
| 2036 | |
| 2037 | This function is expected to be called from a test as part |
| 2038 | of a sequence like the following: |
| 2039 | |
| 2040 | ~~~~~~~~ |
| 2041 | boot_id = host.get_boot_id() |
| 2042 | # trigger shutdown on the host |
| 2043 | host.test_wait_for_shutdown() |
| 2044 | # trigger boot on the host |
| 2045 | host.test_wait_for_boot(boot_id) |
| 2046 | ~~~~~~~~ |
| 2047 | |
Tom Wai-Hong Tam | fe005c2 | 2014-12-03 09:25:44 +0800 | [diff] [blame] | 2048 | @param shutdown_timeout time limit in seconds to allow the host down. |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2049 | @exception TestFail The host did not shut down within the |
| 2050 | allowed time. |
| 2051 | """ |
Tom Wai-Hong Tam | fe005c2 | 2014-12-03 09:25:44 +0800 | [diff] [blame] | 2052 | if shutdown_timeout is None: |
| 2053 | shutdown_timeout = self.SHUTDOWN_TIMEOUT |
| 2054 | |
| 2055 | if not self.ping_wait_down(timeout=shutdown_timeout): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2056 | raise error.TestFail( |
| 2057 | 'client failed to shut down after %d seconds' % |
Tom Wai-Hong Tam | fe005c2 | 2014-12-03 09:25:44 +0800 | [diff] [blame] | 2058 | shutdown_timeout) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2059 | |
| 2060 | |
| 2061 | def test_wait_for_boot(self, old_boot_id=None): |
| 2062 | """Wait for the client to boot from cold power. |
| 2063 | |
| 2064 | The `old_boot_id` parameter should be the value from |
| 2065 | `get_boot_id()` obtained prior to shutting down. A |
| 2066 | `TestFail` exception is raised if the boot id does not |
| 2067 | change. The boot id test is omitted if `old_boot_id` is not |
| 2068 | specified. |
| 2069 | |
| 2070 | See @ref test_wait_for_shutdown for more on this function's |
| 2071 | usage. |
| 2072 | |
J. Richard Barnette | 7214e0b | 2013-02-06 15:20:49 -0800 | [diff] [blame] | 2073 | @param old_boot_id A boot id value obtained before the |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2074 | shut down. |
| 2075 | |
| 2076 | @exception TestFail The host did not respond within the |
| 2077 | allowed time. |
| 2078 | @exception TestFail The host responded, but the boot id test |
| 2079 | indicated that there was no reboot. |
| 2080 | """ |
J. Richard Barnette | eb69d72 | 2012-06-18 17:29:44 -0700 | [diff] [blame] | 2081 | if not self.wait_up(timeout=self.REBOOT_TIMEOUT): |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2082 | raise error.TestFail( |
| 2083 | 'client failed to reboot after %d seconds' % |
J. Richard Barnette | eb69d72 | 2012-06-18 17:29:44 -0700 | [diff] [blame] | 2084 | self.REBOOT_TIMEOUT) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2085 | elif old_boot_id: |
| 2086 | if self.get_boot_id() == old_boot_id: |
Tom Wai-Hong Tam | 0179268 | 2015-01-06 08:00:46 +0800 | [diff] [blame] | 2087 | logging.error('client not rebooted (boot %s)', |
| 2088 | old_boot_id) |
J. Richard Barnette | 134ec2c | 2012-04-25 12:59:37 -0700 | [diff] [blame] | 2089 | raise error.TestFail( |
Tom Wai-Hong Tam | 0179268 | 2015-01-06 08:00:46 +0800 | [diff] [blame] | 2090 | 'client is back up, but did not reboot') |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 2091 | |
| 2092 | |
| 2093 | @staticmethod |
| 2094 | def check_for_rpm_support(hostname): |
| 2095 | """For a given hostname, return whether or not it is powered by an RPM. |
| 2096 | |
Simran Basi | 1df5511 | 2013-09-06 11:25:09 -0700 | [diff] [blame] | 2097 | @param hostname: hostname to check for rpm support. |
| 2098 | |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 2099 | @return None if this host does not follows the defined naming format |
| 2100 | for RPM powered DUT's in the lab. If it does follow the format, |
| 2101 | it returns a regular expression MatchObject instead. |
| 2102 | """ |
Fang Deng | baff908 | 2015-01-06 13:46:15 -0800 | [diff] [blame] | 2103 | return re.match(CrosHost._RPM_HOSTNAME_REGEX, hostname) |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 2104 | |
| 2105 | |
| 2106 | def has_power(self): |
| 2107 | """For this host, return whether or not it is powered by an RPM. |
| 2108 | |
| 2109 | @return True if this host is in the CROS lab and follows the defined |
| 2110 | naming format. |
| 2111 | """ |
Fang Deng | 0ca40e2 | 2013-08-27 17:47:44 -0700 | [diff] [blame] | 2112 | return CrosHost.check_for_rpm_support(self.hostname) |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 2113 | |
| 2114 | |
Ismail Noorbasha | 07fdb61 | 2013-02-14 14:13:31 -0800 | [diff] [blame] | 2115 | def _set_power(self, state, power_method): |
| 2116 | """Sets the power to the host via RPM, Servo or manual. |
| 2117 | |
| 2118 | @param state Specifies which power state to set to DUT |
| 2119 | @param power_method Specifies which method of power control to |
| 2120 | use. By default "RPM" will be used. Valid values |
| 2121 | are the strings "RPM", "manual", "servoj10". |
| 2122 | |
| 2123 | """ |
| 2124 | ACCEPTABLE_STATES = ['ON', 'OFF'] |
| 2125 | |
| 2126 | if state.upper() not in ACCEPTABLE_STATES: |
| 2127 | raise error.TestError('State must be one of: %s.' |
| 2128 | % (ACCEPTABLE_STATES,)) |
| 2129 | |
| 2130 | if power_method == self.POWER_CONTROL_SERVO: |
| 2131 | logging.info('Setting servo port J10 to %s', state) |
| 2132 | self.servo.set('prtctl3_pwren', state.lower()) |
| 2133 | time.sleep(self._USB_POWER_TIMEOUT) |
| 2134 | elif power_method == self.POWER_CONTROL_MANUAL: |
| 2135 | logging.info('You have %d seconds to set the AC power to %s.', |
| 2136 | self._POWER_CYCLE_TIMEOUT, state) |
| 2137 | time.sleep(self._POWER_CYCLE_TIMEOUT) |
| 2138 | else: |
| 2139 | if not self.has_power(): |
| 2140 | raise error.TestFail('DUT does not have RPM connected.') |
Simran Basi | 5e6339a | 2013-03-21 11:34:32 -0700 | [diff] [blame] | 2141 | afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10) |
| 2142 | afe.set_host_attribute(self._RPM_OUTLET_CHANGED, True, |
| 2143 | hostname=self.hostname) |
Simran Basi | 1df5511 | 2013-09-06 11:25:09 -0700 | [diff] [blame] | 2144 | rpm_client.set_power(self.hostname, state.upper(), timeout_mins=5) |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 2145 | |
| 2146 | |
Ismail Noorbasha | 07fdb61 | 2013-02-14 14:13:31 -0800 | [diff] [blame] | 2147 | def power_off(self, power_method=POWER_CONTROL_RPM): |
| 2148 | """Turn off power to this host via RPM, Servo or manual. |
| 2149 | |
| 2150 | @param power_method Specifies which method of power control to |
| 2151 | use. By default "RPM" will be used. Valid values |
| 2152 | are the strings "RPM", "manual", "servoj10". |
| 2153 | |
| 2154 | """ |
| 2155 | self._set_power('OFF', power_method) |
Simran Basi | d5e5e27 | 2012-09-24 15:23:59 -0700 | [diff] [blame] | 2156 | |
| 2157 | |
Ismail Noorbasha | 07fdb61 | 2013-02-14 14:13:31 -0800 | [diff] [blame] | 2158 | def power_on(self, power_method=POWER_CONTROL_RPM): |
| 2159 | """Turn on power to this host via RPM, Servo or manual. |
| 2160 | |
| 2161 | @param power_method Specifies which method of power control to |
| 2162 | use. By default "RPM" will be used. Valid values |
| 2163 | are the strings "RPM", "manual", "servoj10". |
| 2164 | |
| 2165 | """ |
| 2166 | self._set_power('ON', power_method) |
| 2167 | |
| 2168 | |
| 2169 | def power_cycle(self, power_method=POWER_CONTROL_RPM): |
| 2170 | """Cycle power to this host by turning it OFF, then ON. |
| 2171 | |
| 2172 | @param power_method Specifies which method of power control to |
| 2173 | use. By default "RPM" will be used. Valid values |
| 2174 | are the strings "RPM", "manual", "servoj10". |
| 2175 | |
| 2176 | """ |
| 2177 | if power_method in (self.POWER_CONTROL_SERVO, |
| 2178 | self.POWER_CONTROL_MANUAL): |
| 2179 | self.power_off(power_method=power_method) |
| 2180 | time.sleep(self._POWER_CYCLE_TIMEOUT) |
| 2181 | self.power_on(power_method=power_method) |
| 2182 | else: |
| 2183 | rpm_client.set_power(self.hostname, 'CYCLE') |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2184 | |
| 2185 | |
| 2186 | def get_platform(self): |
| 2187 | """Determine the correct platform label for this host. |
| 2188 | |
| 2189 | @returns a string representing this host's platform. |
| 2190 | """ |
| 2191 | crossystem = utils.Crossystem(self) |
| 2192 | crossystem.init() |
| 2193 | # Extract fwid value and use the leading part as the platform id. |
| 2194 | # fwid generally follow the format of {platform}.{firmware version} |
| 2195 | # Example: Alex.X.YYY.Z or Google_Alex.X.YYY.Z |
| 2196 | platform = crossystem.fwid().split('.')[0].lower() |
| 2197 | # Newer platforms start with 'Google_' while the older ones do not. |
| 2198 | return platform.replace('google_', '') |
| 2199 | |
| 2200 | |
Hung-ying Tyan | b132803 | 2014-04-01 14:18:54 +0800 | [diff] [blame] | 2201 | def get_architecture(self): |
| 2202 | """Determine the correct architecture label for this host. |
| 2203 | |
| 2204 | @returns a string representing this host's architecture. |
| 2205 | """ |
| 2206 | crossystem = utils.Crossystem(self) |
| 2207 | crossystem.init() |
| 2208 | return crossystem.arch() |
| 2209 | |
| 2210 | |
Luis Lozano | 40b7d0d | 2014-01-17 15:12:06 -0800 | [diff] [blame] | 2211 | def get_chrome_version(self): |
| 2212 | """Gets the Chrome version number and milestone as strings. |
| 2213 | |
| 2214 | Invokes "chrome --version" to get the version number and milestone. |
| 2215 | |
| 2216 | @return A tuple (chrome_ver, milestone) where "chrome_ver" is the |
| 2217 | current Chrome version number as a string (in the form "W.X.Y.Z") |
| 2218 | and "milestone" is the first component of the version number |
| 2219 | (the "W" from "W.X.Y.Z"). If the version number cannot be parsed |
| 2220 | in the "W.X.Y.Z" format, the "chrome_ver" will be the full output |
| 2221 | of "chrome --version" and the milestone will be the empty string. |
| 2222 | |
| 2223 | """ |
MK Ryu | 35d661e | 2014-09-25 17:44:10 -0700 | [diff] [blame] | 2224 | version_string = self.run(client_constants.CHROME_VERSION_COMMAND).stdout |
Luis Lozano | 40b7d0d | 2014-01-17 15:12:06 -0800 | [diff] [blame] | 2225 | return utils.parse_chrome_version(version_string) |
| 2226 | |
Aviv Keshet | 74c89a9 | 2013-02-04 15:18:30 -0800 | [diff] [blame] | 2227 | @label_decorator() |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2228 | def get_board(self): |
| 2229 | """Determine the correct board label for this host. |
| 2230 | |
| 2231 | @returns a string representing this host's board. |
| 2232 | """ |
| 2233 | release_info = utils.parse_cmd_output('cat /etc/lsb-release', |
| 2234 | run_method=self.run) |
| 2235 | board = release_info['CHROMEOS_RELEASE_BOARD'] |
| 2236 | # Devices in the lab generally have the correct board name but our own |
| 2237 | # development devices have {board_name}-signed-{key_type}. The board |
| 2238 | # name may also begin with 'x86-' which we need to keep. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 2239 | board_format_string = ds_constants.BOARD_PREFIX + '%s' |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2240 | if 'x86' not in board: |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 2241 | return board_format_string % board.split('-')[0] |
| 2242 | return board_format_string % '-'.join(board.split('-')[0:2]) |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2243 | |
| 2244 | |
Aviv Keshet | 74c89a9 | 2013-02-04 15:18:30 -0800 | [diff] [blame] | 2245 | @label_decorator('lightsensor') |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2246 | def has_lightsensor(self): |
| 2247 | """Determine the correct board label for this host. |
| 2248 | |
| 2249 | @returns the string 'lightsensor' if this host has a lightsensor or |
| 2250 | None if it does not. |
| 2251 | """ |
| 2252 | search_cmd = "find -L %s -maxdepth 4 | egrep '%s'" % ( |
Richard Barnette | 82c3591 | 2012-11-20 10:09:10 -0800 | [diff] [blame] | 2253 | self._LIGHTSENSOR_SEARCH_DIR, '|'.join(self._LIGHTSENSOR_FILES)) |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2254 | try: |
| 2255 | # Run the search cmd following the symlinks. Stderr_tee is set to |
| 2256 | # None as there can be a symlink loop, but the command will still |
| 2257 | # execute correctly with a few messages printed to stderr. |
| 2258 | self.run(search_cmd, stdout_tee=None, stderr_tee=None) |
| 2259 | return 'lightsensor' |
| 2260 | except error.AutoservRunError: |
| 2261 | # egrep exited with a return code of 1 meaning none of the possible |
| 2262 | # lightsensor files existed. |
| 2263 | return None |
| 2264 | |
| 2265 | |
Aviv Keshet | 74c89a9 | 2013-02-04 15:18:30 -0800 | [diff] [blame] | 2266 | @label_decorator('bluetooth') |
Simran Basi | c6f1f7a | 2012-10-16 10:47:46 -0700 | [diff] [blame] | 2267 | def has_bluetooth(self): |
| 2268 | """Determine the correct board label for this host. |
| 2269 | |
| 2270 | @returns the string 'bluetooth' if this host has bluetooth or |
| 2271 | None if it does not. |
| 2272 | """ |
| 2273 | try: |
| 2274 | self.run('test -d /sys/class/bluetooth/hci0') |
| 2275 | # test exited with a return code of 0. |
| 2276 | return 'bluetooth' |
| 2277 | except error.AutoservRunError: |
| 2278 | # test exited with a return code 1 meaning the directory did not |
| 2279 | # exist. |
| 2280 | return None |
| 2281 | |
| 2282 | |
Bill Richardson | 4f595f5 | 2014-02-13 16:20:26 -0800 | [diff] [blame] | 2283 | @label_decorator('ec') |
| 2284 | def get_ec(self): |
| 2285 | """ |
| 2286 | Determine the type of EC on this host. |
| 2287 | |
| 2288 | @returns a string representing this host's embedded controller type. |
| 2289 | At present, it only returns "ec:cros", for Chrome OS ECs. Other types |
| 2290 | of EC (or none) don't return any strings, since no tests depend on |
| 2291 | those. |
| 2292 | """ |
| 2293 | cmd = 'mosys ec info' |
| 2294 | # The output should look like these, so that the last field should |
| 2295 | # match our EC version scheme: |
| 2296 | # |
| 2297 | # stm | stm32f100 | snow_v1.3.139-375eb9f |
| 2298 | # ti | Unknown-10de | peppy_v1.5.114-5d52788 |
| 2299 | # |
| 2300 | # Non-Chrome OS ECs will look like these: |
| 2301 | # |
| 2302 | # ENE | KB932 | 00BE107A00 |
| 2303 | # ite | it8518 | 3.08 |
| 2304 | # |
| 2305 | # And some systems don't have ECs at all (Lumpy, for example). |
| 2306 | regexp = r'^.*\|\s*(\S+_v\d+\.\d+\.\d+-[0-9a-f]+)\s*$' |
| 2307 | |
| 2308 | ecinfo = self.run(command=cmd, ignore_status=True) |
| 2309 | if ecinfo.exit_status == 0: |
| 2310 | res = re.search(regexp, ecinfo.stdout) |
| 2311 | if res: |
| 2312 | logging.info("EC version is %s", res.groups()[0]) |
| 2313 | return 'ec:cros' |
| 2314 | logging.info("%s got: %s", cmd, ecinfo.stdout) |
| 2315 | # Has an EC, but it's not a Chrome OS EC |
| 2316 | return None |
| 2317 | logging.info("%s exited with status %d", cmd, ecinfo.exit_status) |
| 2318 | # No EC present |
| 2319 | return None |
| 2320 | |
| 2321 | |
Alec Berg | 31b932b | 2014-04-04 16:09:11 -0700 | [diff] [blame] | 2322 | @label_decorator('accels') |
| 2323 | def get_accels(self): |
| 2324 | """ |
| 2325 | Determine the type of accelerometers on this host. |
| 2326 | |
| 2327 | @returns a string representing this host's accelerometer type. |
| 2328 | At present, it only returns "accel:cros-ec", for accelerometers |
| 2329 | attached to a Chrome OS EC, or none, if no accelerometers. |
| 2330 | """ |
| 2331 | # Check to make sure we have ectool |
| 2332 | rv = self.run('which ectool', ignore_status=True) |
| 2333 | if rv.exit_status: |
| 2334 | logging.info("No ectool cmd found, assuming no EC accelerometers") |
| 2335 | return None |
| 2336 | |
| 2337 | # Check that the EC supports the motionsense command |
| 2338 | rv = self.run('ectool motionsense', ignore_status=True) |
| 2339 | if rv.exit_status: |
| 2340 | logging.info("EC does not support motionsense command " |
| 2341 | "assuming no EC accelerometers") |
| 2342 | return None |
| 2343 | |
| 2344 | # Check that EC motion sensors are active |
| 2345 | active = self.run('ectool motionsense active').stdout.split('\n') |
| 2346 | if active[0] == "0": |
| 2347 | logging.info("Motion sense inactive, assuming no EC accelerometers") |
| 2348 | return None |
| 2349 | |
| 2350 | logging.info("EC accelerometers found") |
| 2351 | return 'accel:cros-ec' |
| 2352 | |
| 2353 | |
Tom Wai-Hong Tam | 3d6790d | 2014-04-14 16:15:47 +0800 | [diff] [blame] | 2354 | @label_decorator('chameleon') |
| 2355 | def has_chameleon(self): |
| 2356 | """Determine if a Chameleon connected to this host. |
| 2357 | |
Tom Wai-Hong Tam | badbb33 | 2014-10-10 02:59:41 +0800 | [diff] [blame] | 2358 | @returns a list containing two strings ('chameleon' and |
| 2359 | 'chameleon:' + label, e.g. 'chameleon:hdmi') if this host |
| 2360 | has a Chameleon or None if it has not. |
Tom Wai-Hong Tam | 3d6790d | 2014-04-14 16:15:47 +0800 | [diff] [blame] | 2361 | """ |
| 2362 | if self._chameleon_host: |
Tom Wai-Hong Tam | badbb33 | 2014-10-10 02:59:41 +0800 | [diff] [blame] | 2363 | return ['chameleon', 'chameleon:' + self.chameleon.get_label()] |
Tom Wai-Hong Tam | 3d6790d | 2014-04-14 16:15:47 +0800 | [diff] [blame] | 2364 | else: |
| 2365 | return None |
| 2366 | |
| 2367 | |
Cheng-Yi Chiang | f4104ff | 2014-12-23 19:39:01 +0800 | [diff] [blame] | 2368 | @label_decorator('audio_loopback_dongle') |
| 2369 | def has_loopback_dongle(self): |
| 2370 | """Determine if an audio loopback dongle is plugged to this host. |
| 2371 | |
| 2372 | @returns 'audio_loopback_dongle' when there is an audio loopback dongle |
| 2373 | plugged to this host. |
| 2374 | None when there is no audio loopback dongle |
| 2375 | plugged to this host. |
| 2376 | """ |
Cheng-Yi Chiang | 8de7811 | 2015-05-27 14:47:08 +0800 | [diff] [blame] | 2377 | nodes_info = self.run(command=cras_utils.get_cras_nodes_cmd(), |
| 2378 | ignore_status=True).stdout |
| 2379 | if (cras_utils.node_type_is_plugged('HEADPHONE', nodes_info) and |
| 2380 | cras_utils.node_type_is_plugged('MIC', nodes_info)): |
Cheng-Yi Chiang | f4104ff | 2014-12-23 19:39:01 +0800 | [diff] [blame] | 2381 | return 'audio_loopback_dongle' |
| 2382 | else: |
| 2383 | return None |
| 2384 | |
| 2385 | |
Derek Basehore | c71ff62 | 2014-07-07 15:18:40 -0700 | [diff] [blame] | 2386 | @label_decorator('power_supply') |
| 2387 | def get_power_supply(self): |
| 2388 | """ |
| 2389 | Determine what type of power supply the host has |
| 2390 | |
| 2391 | @returns a string representing this host's power supply. |
| 2392 | 'power:battery' when the device has a battery intended for |
| 2393 | extended use |
| 2394 | 'power:AC_primary' when the device has a battery not intended |
| 2395 | for extended use (for moving the machine, etc) |
| 2396 | 'power:AC_only' when the device has no battery at all. |
| 2397 | """ |
| 2398 | psu = self.run(command='mosys psu type', ignore_status=True) |
| 2399 | if psu.exit_status: |
| 2400 | # The psu command for mosys is not included for all platforms. The |
| 2401 | # assumption is that the device will have a battery if the command |
| 2402 | # is not found. |
| 2403 | return 'power:battery' |
| 2404 | |
| 2405 | psu_str = psu.stdout.strip() |
| 2406 | if psu_str == 'unknown': |
| 2407 | return None |
| 2408 | |
| 2409 | return 'power:%s' % psu_str |
| 2410 | |
| 2411 | |
Puthikorn Voravootivat | fa01124 | 2014-03-14 18:45:11 -0700 | [diff] [blame] | 2412 | @label_decorator('storage') |
| 2413 | def get_storage(self): |
| 2414 | """ |
| 2415 | Determine the type of boot device for this host. |
| 2416 | |
| 2417 | Determine if the internal device is SCSI or dw_mmc device. |
| 2418 | Then check that it is SSD or HDD or eMMC or something else. |
| 2419 | |
| 2420 | @returns a string representing this host's internal device type. |
| 2421 | 'storage:ssd' when internal device is solid state drive |
| 2422 | 'storage:hdd' when internal device is hard disk drive |
| 2423 | 'storage:mmc' when internal device is mmc drive |
| 2424 | None When internal device is something else or |
| 2425 | when we are unable to determine the type |
| 2426 | """ |
| 2427 | # The output should be /dev/mmcblk* for SD/eMMC or /dev/sd* for scsi |
| 2428 | rootdev_cmd = ' '.join(['. /usr/sbin/write_gpt.sh;', |
| 2429 | '. /usr/share/misc/chromeos-common.sh;', |
| 2430 | 'load_base_vars;', |
| 2431 | 'get_fixed_dst_drive']) |
Puthikorn Voravootivat | 03c5168 | 2014-04-24 13:52:12 -0700 | [diff] [blame] | 2432 | rootdev = self.run(command=rootdev_cmd, ignore_status=True) |
| 2433 | if rootdev.exit_status: |
| 2434 | logging.info("Fail to run %s", rootdev_cmd) |
| 2435 | return None |
Puthikorn Voravootivat | fa01124 | 2014-03-14 18:45:11 -0700 | [diff] [blame] | 2436 | rootdev_str = rootdev.stdout.strip() |
| 2437 | |
| 2438 | if not rootdev_str: |
| 2439 | return None |
| 2440 | |
| 2441 | rootdev_base = os.path.basename(rootdev_str) |
| 2442 | |
| 2443 | mmc_pattern = '/dev/mmcblk[0-9]' |
| 2444 | if re.match(mmc_pattern, rootdev_str): |
| 2445 | # Use type to determine if the internal device is eMMC or somthing |
| 2446 | # else. We can assume that MMC is always an internal device. |
| 2447 | type_cmd = 'cat /sys/block/%s/device/type' % rootdev_base |
Puthikorn Voravootivat | 03c5168 | 2014-04-24 13:52:12 -0700 | [diff] [blame] | 2448 | type = self.run(command=type_cmd, ignore_status=True) |
| 2449 | if type.exit_status: |
| 2450 | logging.info("Fail to run %s", type_cmd) |
| 2451 | return None |
Puthikorn Voravootivat | fa01124 | 2014-03-14 18:45:11 -0700 | [diff] [blame] | 2452 | type_str = type.stdout.strip() |
| 2453 | |
| 2454 | if type_str == 'MMC': |
| 2455 | return 'storage:mmc' |
| 2456 | |
| 2457 | scsi_pattern = '/dev/sd[a-z]+' |
| 2458 | if re.match(scsi_pattern, rootdev.stdout): |
| 2459 | # Read symlink for /sys/block/sd* to determine if the internal |
| 2460 | # device is connected via ata or usb. |
| 2461 | link_cmd = 'readlink /sys/block/%s' % rootdev_base |
Puthikorn Voravootivat | 03c5168 | 2014-04-24 13:52:12 -0700 | [diff] [blame] | 2462 | link = self.run(command=link_cmd, ignore_status=True) |
| 2463 | if link.exit_status: |
| 2464 | logging.info("Fail to run %s", link_cmd) |
| 2465 | return None |
Puthikorn Voravootivat | fa01124 | 2014-03-14 18:45:11 -0700 | [diff] [blame] | 2466 | link_str = link.stdout.strip() |
| 2467 | if 'usb' in link_str: |
| 2468 | return None |
| 2469 | |
| 2470 | # Read rotation to determine if the internal device is ssd or hdd. |
| 2471 | rotate_cmd = str('cat /sys/block/%s/queue/rotational' |
| 2472 | % rootdev_base) |
Puthikorn Voravootivat | 03c5168 | 2014-04-24 13:52:12 -0700 | [diff] [blame] | 2473 | rotate = self.run(command=rotate_cmd, ignore_status=True) |
| 2474 | if rotate.exit_status: |
| 2475 | logging.info("Fail to run %s", rotate_cmd) |
| 2476 | return None |
Puthikorn Voravootivat | fa01124 | 2014-03-14 18:45:11 -0700 | [diff] [blame] | 2477 | rotate_str = rotate.stdout.strip() |
| 2478 | |
| 2479 | rotate_dict = {'0':'storage:ssd', '1':'storage:hdd'} |
| 2480 | return rotate_dict.get(rotate_str) |
| 2481 | |
| 2482 | # All other internal device / error case will always fall here |
| 2483 | return None |
| 2484 | |
| 2485 | |
Dan Shi | 4e9a2aa | 2014-03-24 14:28:42 -0700 | [diff] [blame] | 2486 | @label_decorator('servo') |
| 2487 | def get_servo(self): |
| 2488 | """Determine if the host has a servo attached. |
| 2489 | |
| 2490 | If the host has a working servo attached, it should have a servo label. |
| 2491 | |
| 2492 | @return: string 'servo' if the host has servo attached. Otherwise, |
| 2493 | returns None. |
| 2494 | """ |
| 2495 | return 'servo' if self._servo_host else None |
| 2496 | |
| 2497 | |
Dan Shi | 5beba47 | 2014-05-28 22:46:07 -0700 | [diff] [blame] | 2498 | @label_decorator('video_labels') |
| 2499 | def get_video_labels(self): |
| 2500 | """Run /usr/local/bin/avtest_label_detect to get a list of video labels. |
| 2501 | |
| 2502 | Sample output of avtest_label_detect: |
| 2503 | Detected label: hw_video_acc_vp8 |
| 2504 | Detected label: webcam |
| 2505 | |
| 2506 | @return: A list of labels detected by tool avtest_label_detect. |
| 2507 | """ |
| 2508 | try: |
| 2509 | result = self.run('/usr/local/bin/avtest_label_detect').stdout |
| 2510 | return re.findall('^Detected label: (\w+)$', result, re.M) |
| 2511 | except error.AutoservRunError: |
| 2512 | # The tool is not installed. |
| 2513 | return [] |
| 2514 | |
| 2515 | |
mussa | 584b446 | 2014-06-20 15:13:28 -0700 | [diff] [blame] | 2516 | @label_decorator('video_glitch_detection') |
| 2517 | def is_video_glitch_detection_supported(self): |
| 2518 | """ Determine if a board under test is supported for video glitch |
| 2519 | detection tests. |
| 2520 | |
| 2521 | @return: 'video_glitch_detection' if board is supported, None otherwise. |
| 2522 | """ |
Mussa | 5b58905 | 2015-10-26 17:55:26 -0700 | [diff] [blame] | 2523 | board = self.get_board().replace(ds_constants.BOARD_PREFIX, '') |
mussa | 584b446 | 2014-06-20 15:13:28 -0700 | [diff] [blame] | 2524 | |
Mussa | 5b58905 | 2015-10-26 17:55:26 -0700 | [diff] [blame] | 2525 | if board in video_test_constants.SUPPORTED_BOARDS: |
| 2526 | return 'video_glitch_detection' |
mussa | 584b446 | 2014-06-20 15:13:28 -0700 | [diff] [blame] | 2527 | |
Mussa | 5b58905 | 2015-10-26 17:55:26 -0700 | [diff] [blame] | 2528 | return None |
mussa | 584b446 | 2014-06-20 15:13:28 -0700 | [diff] [blame] | 2529 | |
mussa | 584b446 | 2014-06-20 15:13:28 -0700 | [diff] [blame] | 2530 | |
Katherine Threlkeld | 7b97a9f | 2014-06-24 13:47:14 -0700 | [diff] [blame] | 2531 | @label_decorator('touch_labels') |
| 2532 | def get_touch(self): |
| 2533 | """ |
| 2534 | Determine whether board under test has a touchpad or touchscreen. |
| 2535 | |
| 2536 | @return: A list of some combination of 'touchscreen' and 'touchpad', |
| 2537 | depending on what is present on the device. |
Katherine Threlkeld | ab83d39 | 2015-06-18 16:45:57 -0700 | [diff] [blame] | 2538 | |
Katherine Threlkeld | 7b97a9f | 2014-06-24 13:47:14 -0700 | [diff] [blame] | 2539 | """ |
| 2540 | labels = [] |
Katherine Threlkeld | ab83d39 | 2015-06-18 16:45:57 -0700 | [diff] [blame] | 2541 | looking_for = ['touchpad', 'touchscreen'] |
| 2542 | player = input_playback.InputPlayback() |
| 2543 | input_events = self.run('ls /dev/input/event*').stdout.strip().split() |
| 2544 | filename = '/tmp/touch_labels' |
| 2545 | for event in input_events: |
| 2546 | self.run('evtest %s > %s' % (event, filename), timeout=1, |
| 2547 | ignore_timeout=True) |
| 2548 | properties = self.run('cat %s' % filename).stdout |
| 2549 | input_type = player._determine_input_type(properties) |
| 2550 | if input_type in looking_for: |
| 2551 | labels.append(input_type) |
| 2552 | looking_for.remove(input_type) |
| 2553 | if len(looking_for) == 0: |
| 2554 | break |
| 2555 | self.run('rm %s' % filename) |
| 2556 | |
Katherine Threlkeld | 7b97a9f | 2014-06-24 13:47:14 -0700 | [diff] [blame] | 2557 | return labels |
| 2558 | |
Hung-ying Tyan | a39b054 | 2015-06-30 10:36:42 +0800 | [diff] [blame] | 2559 | |
| 2560 | @label_decorator('internal_display') |
| 2561 | def has_internal_display(self): |
| 2562 | """Determine if the device under test is equipped with an internal |
| 2563 | display. |
| 2564 | |
| 2565 | @return: 'internal_display' if one is present; None otherwise. |
| 2566 | """ |
| 2567 | from autotest_lib.client.cros.graphics import graphics_utils |
| 2568 | from autotest_lib.client.common_lib import utils as common_utils |
| 2569 | |
| 2570 | def __system_output(cmd): |
| 2571 | return self.run(cmd).stdout |
| 2572 | |
| 2573 | def __read_file(remote_path): |
| 2574 | return self.run('cat %s' % remote_path).stdout |
| 2575 | |
| 2576 | # Hijack the necessary client functions so that we can take advantage |
| 2577 | # of the client lib here. |
| 2578 | # FIXME: find a less hacky way than this |
| 2579 | original_system_output = utils.system_output |
| 2580 | original_read_file = common_utils.read_file |
| 2581 | utils.system_output = __system_output |
| 2582 | common_utils.read_file = __read_file |
| 2583 | try: |
| 2584 | return ('internal_display' if graphics_utils.has_internal_display() |
| 2585 | else None) |
| 2586 | finally: |
| 2587 | utils.system_output = original_system_output |
| 2588 | common_utils.read_file = original_read_file |
| 2589 | |
| 2590 | |
Eric Caruso | ee673ac | 2015-08-05 17:03:04 -0700 | [diff] [blame] | 2591 | @label_decorator('lucidsleep') |
| 2592 | def has_lucid_sleep_support(self): |
| 2593 | """Determine if the device under test has support for lucid sleep. |
| 2594 | |
| 2595 | @return 'lucidsleep' if this board supports lucid sleep; None otherwise |
| 2596 | """ |
| 2597 | board = self.get_board().replace(ds_constants.BOARD_PREFIX, '') |
| 2598 | return 'lucidsleep' if board in LUCID_SLEEP_BOARDS else None |
| 2599 | |
| 2600 | |
Dan Shi | 85276d4 | 2014-04-08 22:11:45 -0700 | [diff] [blame] | 2601 | def is_boot_from_usb(self): |
| 2602 | """Check if DUT is boot from USB. |
| 2603 | |
| 2604 | @return: True if DUT is boot from usb. |
| 2605 | """ |
| 2606 | device = self.run('rootdev -s -d').stdout.strip() |
| 2607 | removable = int(self.run('cat /sys/block/%s/removable' % |
| 2608 | os.path.basename(device)).stdout.strip()) |
| 2609 | return removable == 1 |
Helen Zhang | 17dae2b | 2014-11-11 09:25:52 -0800 | [diff] [blame] | 2610 | |
| 2611 | |
| 2612 | def read_from_meminfo(self, key): |
Dan Shi | 49ca093 | 2014-11-14 11:22:27 -0800 | [diff] [blame] | 2613 | """Return the memory info from /proc/meminfo |
Helen Zhang | 17dae2b | 2014-11-11 09:25:52 -0800 | [diff] [blame] | 2614 | |
| 2615 | @param key: meminfo requested |
| 2616 | |
| 2617 | @return the memory value as a string |
| 2618 | |
| 2619 | """ |
Helen Zhang | 17dae2b | 2014-11-11 09:25:52 -0800 | [diff] [blame] | 2620 | meminfo = self.run('grep %s /proc/meminfo' % key).stdout.strip() |
| 2621 | logging.debug('%s', meminfo) |
| 2622 | return int(re.search(r'\d+', meminfo).group(0)) |
Rohit Makasana | 8a4923c | 2015-08-13 17:04:26 -0700 | [diff] [blame] | 2623 | |
| 2624 | |
| 2625 | def get_board_type(self): |
| 2626 | """ |
| 2627 | Get the DUT's device type from /etc/lsb-release. |
Danny Chan | 471a8d1 | 2015-08-18 14:57:41 -0700 | [diff] [blame] | 2628 | DEVICETYPE can be one of CHROMEBOX, CHROMEBASE, CHROMEBOOK or more. |
| 2629 | |
| 2630 | @return value of DEVICETYPE param from lsb-release. |
Rohit Makasana | 8a4923c | 2015-08-13 17:04:26 -0700 | [diff] [blame] | 2631 | """ |
Danny Chan | 471a8d1 | 2015-08-18 14:57:41 -0700 | [diff] [blame] | 2632 | device_type = self.run('grep DEVICETYPE /etc/lsb-release', |
| 2633 | ignore_status=True).stdout |
| 2634 | if device_type: |
Kalin Stoyanov | 524310b | 2015-08-21 16:24:04 -0700 | [diff] [blame] | 2635 | return device_type.split('=')[-1].strip() |
Danny Chan | 471a8d1 | 2015-08-18 14:57:41 -0700 | [diff] [blame] | 2636 | return '' |
Gilad Arnold | a76bef0 | 2015-09-29 13:55:15 -0700 | [diff] [blame] | 2637 | |
| 2638 | |
| 2639 | def get_os_type(self): |
| 2640 | return 'cros' |
Simran Basi | a5522a3 | 2015-10-06 11:01:24 -0700 | [diff] [blame] | 2641 | |
| 2642 | |
| 2643 | def enable_adb_testing(self): |
| 2644 | """Mark this host as an adb tester.""" |
Dan Shi | a287217 | 2015-10-31 01:16:51 -0700 | [diff] [blame] | 2645 | self.run('touch %s' % constants.ANDROID_TESTER_FILEFLAG) |