blob: e77033122a234bad7c0160a881e5821f9b5bcc4d [file] [log] [blame]
J. Richard Barnette24adbf42012-04-11 15:04:53 -07001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Dale Curtisaa5eedb2011-08-23 16:18:52 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Aviv Keshet74c89a92013-02-04 15:18:30 -08005import functools
Darren Krahn0bd18e82015-10-28 23:30:46 +00006import json
J. Richard Barnette1d78b012012-05-15 13:56:30 -07007import logging
Dan Shi0f466e82013-02-22 15:44:58 -08008import os
Simran Basid5e5e272012-09-24 15:23:59 -07009import re
J. Richard Barnette134ec2c2012-04-25 12:59:37 -070010import time
11
mussa584b4462014-06-20 15:13:28 -070012import common
J. Richard Barnette45e93de2012-04-11 17:24:15 -070013from autotest_lib.client.bin import utils
Dan Shi9cb0eec2014-06-03 09:04:50 -070014from autotest_lib.client.common_lib import autotemp
Richard Barnette0c73ffc2012-11-19 15:21:18 -080015from autotest_lib.client.common_lib import error
16from autotest_lib.client.common_lib import global_config
Dan Shi549fb822015-03-24 18:01:11 -070017from autotest_lib.client.common_lib import lsbrelease_utils
J. Richard Barnette45e93de2012-04-11 17:24:15 -070018from autotest_lib.client.common_lib.cros import autoupdater
Richard Barnette03a0c132012-11-05 12:40:35 -080019from autotest_lib.client.common_lib.cros import dev_server
Gabe Blackb72f4fb2015-01-20 16:47:13 -080020from autotest_lib.client.common_lib.cros.graphite import autotest_es
Gabe Black1e1c41b2015-02-04 23:55:15 -080021from autotest_lib.client.common_lib.cros.graphite import autotest_stats
Hsinyu Chaoe0b08e62015-08-11 10:50:37 +000022from autotest_lib.client.cros import constants as client_constants
J. Richard Barnette84890bd2014-02-21 11:05:47 -080023from autotest_lib.client.cros import cros_ui
Cheng-Yi Chiangf4104ff2014-12-23 19:39:01 +080024from autotest_lib.client.cros.audio import cras_utils
Katherine Threlkeldab83d392015-06-18 16:45:57 -070025from autotest_lib.client.cros.input_playback import input_playback
Mussa5b589052015-10-26 17:55:26 -070026from autotest_lib.client.cros.video import constants as video_test_constants
MK Ryu35d661e2014-09-25 17:44:10 -070027from autotest_lib.server import autoserv_parser
28from autotest_lib.server import autotest
29from autotest_lib.server import constants
30from autotest_lib.server import crashcollect
Dan Shia1ecd5c2013-06-06 11:21:31 -070031from autotest_lib.server import utils as server_utils
Dan Shi9cb0eec2014-06-03 09:04:50 -070032from autotest_lib.server.cros import provision
Scott Zawalski89c44dd2013-02-26 09:28:02 -050033from autotest_lib.server.cros.dynamic_suite import constants as ds_constants
Simran Basi5e6339a2013-03-21 11:34:32 -070034from autotest_lib.server.cros.dynamic_suite import tools, frontend_wrappers
Dan Shi9cb0eec2014-06-03 09:04:50 -070035from autotest_lib.server.cros.faft.config.config import Config as FAFTConfig
Fang Deng96667ca2013-08-01 17:46:18 -070036from autotest_lib.server.hosts import abstract_ssh
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +080037from autotest_lib.server.hosts import chameleon_host
Fang Deng5d518f42013-08-02 14:04:32 -070038from autotest_lib.server.hosts import servo_host
Simran Basidcff4252012-11-20 16:13:20 -080039from autotest_lib.site_utils.rpm_control_system import rpm_client
Simran Basid5e5e272012-09-24 15:23:59 -070040
41
Dan Shib8540a52015-07-16 14:18:23 -070042CONFIG = global_config.global_config
43
Eric Carusoee673ac2015-08-05 17:03:04 -070044LUCID_SLEEP_BOARDS = ['samus', 'lulu']
45
Dan Shid07ee2e2015-09-24 14:49:25 -070046# A file to indicate provision failure and require Repair job to powerwash the
47# dut.
48PROVISION_FAILED = '/var/tmp/provision_failed'
49
beepsc87ff602013-07-31 21:53:00 -070050class FactoryImageCheckerException(error.AutoservError):
51 """Exception raised when an image is a factory image."""
52 pass
53
54
Fang Deng0ca40e22013-08-27 17:47:44 -070055class CrosHost(abstract_ssh.AbstractSSHHost):
J. Richard Barnette45e93de2012-04-11 17:24:15 -070056 """Chromium OS specific subclass of Host."""
57
58 _parser = autoserv_parser.autoserv_parser
Scott Zawalski62bacae2013-03-05 10:40:32 -050059 _AFE = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
J. Richard Barnette45e93de2012-04-11 17:24:15 -070060
Richard Barnette03a0c132012-11-05 12:40:35 -080061 # Timeout values (in seconds) associated with various Chrome OS
62 # state changes.
J. Richard Barnette134ec2c2012-04-25 12:59:37 -070063 #
Richard Barnette0c73ffc2012-11-19 15:21:18 -080064 # In general, a good rule of thumb is that the timeout can be up
65 # to twice the typical measured value on the slowest platform.
66 # The times here have not necessarily been empirically tested to
67 # meet this criterion.
J. Richard Barnetteeb69d722012-06-18 17:29:44 -070068 #
69 # SLEEP_TIMEOUT: Time to allow for suspend to memory.
Richard Barnette0c73ffc2012-11-19 15:21:18 -080070 # RESUME_TIMEOUT: Time to allow for resume after suspend, plus
71 # time to restart the netwowrk.
J. Richard Barnette84890bd2014-02-21 11:05:47 -080072 # SHUTDOWN_TIMEOUT: Time to allow for shut down.
J. Richard Barnetteeb69d722012-06-18 17:29:44 -070073 # BOOT_TIMEOUT: Time to allow for boot from power off. Among
Richard Barnette0c73ffc2012-11-19 15:21:18 -080074 # other things, this must account for the 30 second dev-mode
J. Richard Barnette417cc792015-10-01 09:56:36 -070075 # screen delay, time to start the network on the DUT, and the
76 # ssh timeout of 120 seconds.
J. Richard Barnetteeb69d722012-06-18 17:29:44 -070077 # USB_BOOT_TIMEOUT: Time to allow for boot from a USB device,
Richard Barnette0c73ffc2012-11-19 15:21:18 -080078 # including the 30 second dev-mode delay and time to start the
J. Richard Barnetted4649c62013-03-06 17:42:27 -080079 # network.
beepsf079cfb2013-09-18 17:49:51 -070080 # INSTALL_TIMEOUT: Time to allow for chromeos-install.
J. Richard Barnette84890bd2014-02-21 11:05:47 -080081 # POWERWASH_BOOT_TIMEOUT: Time to allow for a reboot that
82 # includes powerwash.
J. Richard Barnetteeb69d722012-06-18 17:29:44 -070083
84 SLEEP_TIMEOUT = 2
J. Richard Barnetted4649c62013-03-06 17:42:27 -080085 RESUME_TIMEOUT = 10
Tom Wai-Hong Tamfe005c22014-12-03 09:25:44 +080086 SHUTDOWN_TIMEOUT = 10
J. Richard Barnette417cc792015-10-01 09:56:36 -070087 BOOT_TIMEOUT = 150
J. Richard Barnette5bab5f52015-08-03 13:14:38 -070088 USB_BOOT_TIMEOUT = 300
J. Richard Barnette7817b052014-08-28 09:47:29 -070089 INSTALL_TIMEOUT = 480
Dan Shi2c88eed2013-11-12 10:18:38 -080090 POWERWASH_BOOT_TIMEOUT = 60
Chris Sosab76e0ee2013-05-22 16:55:41 -070091
Dan Shica503482015-03-30 17:23:25 -070092 # Minimum OS version that supports server side packaging. Older builds may
93 # not have server side package built or with Autotest code change to support
94 # server-side packaging.
Dan Shib8540a52015-07-16 14:18:23 -070095 MIN_VERSION_SUPPORT_SSP = CONFIG.get_config_value(
Dan Shiced09e42015-04-17 16:09:34 -070096 'AUTOSERV', 'min_version_support_ssp', type=int)
Dan Shica503482015-03-30 17:23:25 -070097
J. Richard Barnette84890bd2014-02-21 11:05:47 -080098 # REBOOT_TIMEOUT: How long to wait for a reboot.
99 #
Chris Sosab76e0ee2013-05-22 16:55:41 -0700100 # We have a long timeout to ensure we don't flakily fail due to other
101 # issues. Shorter timeouts are vetted in platform_RebootAfterUpdate.
Simran Basi1160e2c2013-10-04 16:00:24 -0700102 # TODO(sbasi - crbug.com/276094) Restore to 5 mins once the 'host did not
103 # return from reboot' bug is solved.
104 REBOOT_TIMEOUT = 480
Chris Sosab76e0ee2013-05-22 16:55:41 -0700105
Ismail Noorbasha07fdb612013-02-14 14:13:31 -0800106 # _USB_POWER_TIMEOUT: Time to allow for USB to power toggle ON and OFF.
107 # _POWER_CYCLE_TIMEOUT: Time to allow for manual power cycle.
108 _USB_POWER_TIMEOUT = 5
109 _POWER_CYCLE_TIMEOUT = 10
110
Dan Shib8540a52015-07-16 14:18:23 -0700111 _RPM_RECOVERY_BOARDS = CONFIG.get_config_value('CROS',
Richard Barnette82c35912012-11-20 10:09:10 -0800112 'rpm_recovery_boards', type=str).split(',')
113
114 _MAX_POWER_CYCLE_ATTEMPTS = 6
115 _LAB_MACHINE_FILE = '/mnt/stateful_partition/.labmachine'
Fang Dengdeba14f2014-11-14 11:54:09 -0800116 _RPM_HOSTNAME_REGEX = ('chromeos(\d+)(-row(\d+))?-rack(\d+[a-z]*)'
117 '-host(\d+)')
Katherine Threlkeldab83d392015-06-18 16:45:57 -0700118 _LIGHTSENSOR_FILES = [ "in_illuminance0_input",
119 "in_illuminance_input",
120 "in_illuminance0_raw",
121 "in_illuminance_raw",
122 "illuminance0_input"]
Richard Barnette82c35912012-11-20 10:09:10 -0800123 _LIGHTSENSOR_SEARCH_DIR = '/sys/bus/iio/devices'
124 _LABEL_FUNCTIONS = []
Aviv Keshet74c89a92013-02-04 15:18:30 -0800125 _DETECTABLE_LABELS = []
Kevin Cheng3a4a57a2015-09-30 12:09:50 -0700126 label_decorator = functools.partial(server_utils.add_label_detector,
127 _LABEL_FUNCTIONS,
Aviv Keshet74c89a92013-02-04 15:18:30 -0800128 _DETECTABLE_LABELS)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -0700129
J. Richard Barnetteb6de7e32013-02-14 13:28:04 -0800130 # Constants used in ping_wait_up() and ping_wait_down().
131 #
132 # _PING_WAIT_COUNT is the approximate number of polling
133 # cycles to use when waiting for a host state change.
134 #
135 # _PING_STATUS_DOWN and _PING_STATUS_UP are names used
136 # for arguments to the internal _ping_wait_for_status()
137 # method.
138 _PING_WAIT_COUNT = 40
139 _PING_STATUS_DOWN = False
140 _PING_STATUS_UP = True
141
Ismail Noorbasha07fdb612013-02-14 14:13:31 -0800142 # Allowed values for the power_method argument.
143
144 # POWER_CONTROL_RPM: Passed as default arg for power_off/on/cycle() methods.
145 # POWER_CONTROL_SERVO: Used in set_power() and power_cycle() methods.
146 # POWER_CONTROL_MANUAL: Used in set_power() and power_cycle() methods.
147 POWER_CONTROL_RPM = 'RPM'
148 POWER_CONTROL_SERVO = 'servoj10'
149 POWER_CONTROL_MANUAL = 'manual'
150
151 POWER_CONTROL_VALID_ARGS = (POWER_CONTROL_RPM,
152 POWER_CONTROL_SERVO,
153 POWER_CONTROL_MANUAL)
Richard Barnette0c73ffc2012-11-19 15:21:18 -0800154
Simran Basi5e6339a2013-03-21 11:34:32 -0700155 _RPM_OUTLET_CHANGED = 'outlet_changed'
156
Dan Shi9cb0eec2014-06-03 09:04:50 -0700157 # URL pattern to download firmware image.
Dan Shib8540a52015-07-16 14:18:23 -0700158 _FW_IMAGE_URL_PATTERN = CONFIG.get_config_value(
Dan Shi9cb0eec2014-06-03 09:04:50 -0700159 'CROS', 'firmware_url_pattern', type=str)
beeps687243d2013-07-18 15:29:27 -0700160
MK Ryu35d661e2014-09-25 17:44:10 -0700161 # File that has a list of directories to be collected
162 _LOGS_TO_COLLECT_FILE = os.path.join(
163 common.client_dir, 'common_lib', 'logs_to_collect')
164
165 # Prefix of logging message w.r.t. crash collection
166 _CRASHLOGS_PREFIX = 'collect_crashlogs'
167
168 # Time duration waiting for host up/down check
169 _CHECK_HOST_UP_TIMEOUT_SECS = 15
170
171 # A command that interacts with kernel and hardware (e.g., rm, mkdir, etc)
172 # might not be completely done deep through the hardware when the machine
173 # is powered down right after the command returns.
174 # We should wait for a few seconds to make them done. Finger crossed.
175 _SAFE_WAIT_SECS = 10
176
177
J. Richard Barnette964fba02012-10-24 17:34:29 -0700178 @staticmethod
beeps46dadc92013-11-07 14:07:10 -0800179 def check_host(host, timeout=10):
180 """
181 Check if the given host is a chrome-os host.
182
183 @param host: An ssh host representing a device.
184 @param timeout: The timeout for the run command.
185
186 @return: True if the host device is chromeos.
187
beeps46dadc92013-11-07 14:07:10 -0800188 """
189 try:
Simran Basi933c8af2015-04-29 14:05:07 -0700190 result = host.run(
191 'grep -q CHROMEOS /etc/lsb-release && '
192 '! test -f /mnt/stateful_partition/.android_tester && '
193 '! grep -q moblab /etc/lsb-release',
194 ignore_status=True, timeout=timeout)
beeps46dadc92013-11-07 14:07:10 -0800195 except (error.AutoservRunError, error.AutoservSSHTimeout):
196 return False
197 return result.exit_status == 0
198
199
200 @staticmethod
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800201 def _extract_arguments(args_dict, key_subset):
202 """Extract options from `args_dict` and return a subset result.
J. Richard Barnette7214e0b2013-02-06 15:20:49 -0800203
204 Take the provided dictionary of argument options and return
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800205 a subset that represent standard arguments needed to construct
206 a test-assistant object (chameleon or servo) for a host. The
207 intent is to provide standard argument processing from
Christopher Wiley644ef3e2015-05-15 13:14:14 -0700208 CrosHost for tests that require a test-assistant board
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800209 to operate.
210
211 @param args_dict Dictionary from which to extract the arguments.
212 @param key_subset Tuple of keys to extract from the args_dict, e.g.
213 ('servo_host', 'servo_port').
214 """
215 result = {}
216 for arg in key_subset:
217 if arg in args_dict:
218 result[arg] = args_dict[arg]
219 return result
220
221
222 @staticmethod
223 def get_chameleon_arguments(args_dict):
224 """Extract chameleon options from `args_dict` and return the result.
225
226 Recommended usage:
227 ~~~~~~~~
228 args_dict = utils.args_to_dict(args)
229 chameleon_args = hosts.CrosHost.get_chameleon_arguments(args_dict)
230 host = hosts.create_host(machine, chameleon_args=chameleon_args)
231 ~~~~~~~~
232
233 @param args_dict Dictionary from which to extract the chameleon
234 arguments.
235 """
236 return CrosHost._extract_arguments(
237 args_dict, ('chameleon_host', 'chameleon_port'))
238
239
240 @staticmethod
241 def get_servo_arguments(args_dict):
242 """Extract servo options from `args_dict` and return the result.
J. Richard Barnette7214e0b2013-02-06 15:20:49 -0800243
244 Recommended usage:
245 ~~~~~~~~
246 args_dict = utils.args_to_dict(args)
Fang Deng0ca40e22013-08-27 17:47:44 -0700247 servo_args = hosts.CrosHost.get_servo_arguments(args_dict)
J. Richard Barnette7214e0b2013-02-06 15:20:49 -0800248 host = hosts.create_host(machine, servo_args=servo_args)
249 ~~~~~~~~
250
251 @param args_dict Dictionary from which to extract the servo
252 arguments.
253 """
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800254 return CrosHost._extract_arguments(
255 args_dict, ('servo_host', 'servo_port'))
J. Richard Barnette134ec2c2012-04-25 12:59:37 -0700256
J. Richard Barnette964fba02012-10-24 17:34:29 -0700257
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800258 def _initialize(self, hostname, chameleon_args=None, servo_args=None,
Fang Denge545abb2014-12-30 18:43:47 -0800259 try_lab_servo=False, ssh_verbosity_flag='', ssh_options='',
Fang Dengd1c2b732013-08-20 12:59:46 -0700260 *args, **dargs):
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800261 """Initialize superclasses, |self.chameleon|, and |self.servo|.
J. Richard Barnette67ccb872012-04-19 16:34:56 -0700262
Fang Denge545abb2014-12-30 18:43:47 -0800263 This method will attempt to create the test-assistant object
264 (chameleon/servo) when it is needed by the test. Check
265 the docstring of chameleon_host.create_chameleon_host and
266 servo_host.create_servo_host for how this is determined.
Fang Deng5d518f42013-08-02 14:04:32 -0700267
Fang Denge545abb2014-12-30 18:43:47 -0800268 @param hostname: Hostname of the dut.
269 @param chameleon_args: A dictionary that contains args for creating
270 a ChameleonHost. See chameleon_host for details.
271 @param servo_args: A dictionary that contains args for creating
272 a ServoHost object. See servo_host for details.
273 @param try_lab_servo: Boolean, False indicates that ServoHost should
274 not be created for a device in Cros test lab.
275 See servo_host for details.
276 @param ssh_verbosity_flag: String, to pass to the ssh command to control
277 verbosity.
278 @param ssh_options: String, other ssh options to pass to the ssh
279 command.
J. Richard Barnette67ccb872012-04-19 16:34:56 -0700280 """
Fang Deng0ca40e22013-08-27 17:47:44 -0700281 super(CrosHost, self)._initialize(hostname=hostname,
J. Richard Barnette45e93de2012-04-11 17:24:15 -0700282 *args, **dargs)
J. Richard Barnettef0859852012-08-20 14:55:50 -0700283 # self.env is a dictionary of environment variable settings
284 # to be exported for commands run on the host.
285 # LIBC_FATAL_STDERR_ can be useful for diagnosing certain
286 # errors that might happen.
287 self.env['LIBC_FATAL_STDERR_'] = '1'
Fang Dengd1c2b732013-08-20 12:59:46 -0700288 self._ssh_verbosity_flag = ssh_verbosity_flag
Aviv Keshetc5947fa2013-09-04 14:06:29 -0700289 self._ssh_options = ssh_options
Fang Deng5d518f42013-08-02 14:04:32 -0700290 # TODO(fdeng): We need to simplify the
291 # process of servo and servo_host initialization.
292 # crbug.com/298432
Fang Denge545abb2014-12-30 18:43:47 -0800293 self._servo_host = servo_host.create_servo_host(
294 dut=self.hostname, servo_args=servo_args,
295 try_lab_servo=try_lab_servo)
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800296 # TODO(waihong): Do the simplication on Chameleon too.
Tom Wai-Hong Tam3d6790d2014-04-14 16:15:47 +0800297 self._chameleon_host = chameleon_host.create_chameleon_host(
298 dut=self.hostname, chameleon_args=chameleon_args)
299
Dan Shi4d478522014-02-14 13:46:32 -0800300 if self._servo_host is not None:
301 self.servo = self._servo_host.get_servo()
302 else:
303 self.servo = None
304
Tom Wai-Hong Tam3d6790d2014-04-14 16:15:47 +0800305 if self._chameleon_host:
Tom Wai-Hong Tameaee3402014-01-22 08:52:10 +0800306 self.chameleon = self._chameleon_host.create_chameleon_board()
Tom Wai-Hong Tamefe1c7f2014-01-02 14:00:11 +0800307 else:
Tom Wai-Hong Tam3d6790d2014-04-14 16:15:47 +0800308 self.chameleon = None
Fang Deng5d518f42013-08-02 14:04:32 -0700309
310
Dan Shi3d7a0e12015-10-12 11:55:45 -0700311 def get_repair_image_name(self, image_type='cros'):
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500312 """Generate a image_name from variables in the global config.
313
Dan Shi3d7a0e12015-10-12 11:55:45 -0700314 image_type is used to differentiate different images. Default is CrOS,
315 in which case, repair image's name follows the naming convention defined
316 in global setting CROS/stable_build_pattern.
317 If the image_type is not `cros`, the repair image will be looked up
318 using key `board_name/image_type`, e.g., daisy_spring/firmware.
319
320 @param image_type: Type of the image. Default is `cros`.
321
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500322 @returns a str of $board-version/$BUILD.
323
324 """
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500325 board = self._get_board_from_afe()
326 if board is None:
327 raise error.AutoservError('DUT has no board attribute, '
328 'cannot be repaired.')
Dan Shi3d7a0e12015-10-12 11:55:45 -0700329 if image_type != 'cros':
330 board = '%s/%s' % (board, image_type)
Dan Shi6964fa52014-12-18 11:04:27 -0800331 stable_version = self._AFE.run('get_stable_version', board=board)
Dan Shi3d7a0e12015-10-12 11:55:45 -0700332 if image_type == 'cros':
333 build_pattern = CONFIG.get_config_value(
334 'CROS', 'stable_build_pattern')
335 stable_version = build_pattern % (board, stable_version)
336 return stable_version
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500337
338
Scott Zawalski62bacae2013-03-05 10:40:32 -0500339 def _host_in_AFE(self):
340 """Check if the host is an object the AFE knows.
341
342 @returns the host object.
343 """
344 return self._AFE.get_hosts(hostname=self.hostname)
345
346
Chris Sosab76e0ee2013-05-22 16:55:41 -0700347 def lookup_job_repo_url(self):
348 """Looks up the job_repo_url for the host.
349
350 @returns job_repo_url from AFE or None if not found.
351
352 @raises KeyError if the host does not have a job_repo_url
353 """
Chris Sosab76e0ee2013-05-22 16:55:41 -0700354 hosts = self._AFE.get_hosts(hostname=self.hostname)
beepsb5efc532013-06-04 11:29:34 -0700355 if hosts and ds_constants.JOB_REPO_URL in hosts[0].attributes:
356 return hosts[0].attributes[ds_constants.JOB_REPO_URL]
J. Richard Barnette85d0aac2015-08-20 10:34:39 -0700357 else:
358 return None
Chris Sosab76e0ee2013-05-22 16:55:41 -0700359
360
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500361 def clear_cros_version_labels_and_job_repo_url(self):
362 """Clear cros_version labels and host attribute job_repo_url."""
Scott Zawalski62bacae2013-03-05 10:40:32 -0500363 if not self._host_in_AFE():
Scott Zawalskieadbf702013-03-14 09:23:06 -0400364 return
365
Scott Zawalski62bacae2013-03-05 10:40:32 -0500366 host_list = [self.hostname]
367 labels = self._AFE.get_labels(
368 name__startswith=ds_constants.VERSION_PREFIX,
369 host__hostname=self.hostname)
Dan Shi0f466e82013-02-22 15:44:58 -0800370
Scott Zawalski62bacae2013-03-05 10:40:32 -0500371 for label in labels:
372 label.remove_hosts(hosts=host_list)
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500373
beepscb6f1e22013-06-28 19:14:10 -0700374 self.update_job_repo_url(None, None)
375
376
377 def update_job_repo_url(self, devserver_url, image_name):
378 """
379 Updates the job_repo_url host attribute and asserts it's value.
380
381 @param devserver_url: The devserver to use in the job_repo_url.
382 @param image_name: The name of the image to use in the job_repo_url.
383
384 @raises AutoservError: If we failed to update the job_repo_url.
385 """
386 repo_url = None
387 if devserver_url and image_name:
388 repo_url = tools.get_package_url(devserver_url, image_name)
389 self._AFE.set_host_attribute(ds_constants.JOB_REPO_URL, repo_url,
Scott Zawalski62bacae2013-03-05 10:40:32 -0500390 hostname=self.hostname)
beepscb6f1e22013-06-28 19:14:10 -0700391 if self.lookup_job_repo_url() != repo_url:
392 raise error.AutoservError('Failed to update job_repo_url with %s, '
393 'host %s' % (repo_url, self.hostname))
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500394
395
Dan Shie9309262013-06-19 22:50:21 -0700396 def add_cros_version_labels_and_job_repo_url(self, image_name):
Scott Zawalskieadbf702013-03-14 09:23:06 -0400397 """Add cros_version labels and host attribute job_repo_url.
398
399 @param image_name: The name of the image e.g.
400 lumpy-release/R27-3837.0.0
Dan Shi7458bf62013-06-10 12:50:16 -0700401
Scott Zawalskieadbf702013-03-14 09:23:06 -0400402 """
Scott Zawalski62bacae2013-03-05 10:40:32 -0500403 if not self._host_in_AFE():
Scott Zawalskieadbf702013-03-14 09:23:06 -0400404 return
Scott Zawalski62bacae2013-03-05 10:40:32 -0500405
Scott Zawalskieadbf702013-03-14 09:23:06 -0400406 cros_label = '%s%s' % (ds_constants.VERSION_PREFIX, image_name)
Dan Shie9309262013-06-19 22:50:21 -0700407 devserver_url = dev_server.ImageServer.resolve(image_name).url()
Scott Zawalski62bacae2013-03-05 10:40:32 -0500408
MK Ryufb5e3a82015-07-01 12:21:20 -0700409 self._AFE.run('label_add_hosts', id=cros_label, hosts=[self.hostname])
beepscb6f1e22013-06-28 19:14:10 -0700410 self.update_job_repo_url(devserver_url, image_name)
411
412
beepsdae65fd2013-07-26 16:24:41 -0700413 def verify_job_repo_url(self, tag=''):
beepscb6f1e22013-06-28 19:14:10 -0700414 """
415 Make sure job_repo_url of this host is valid.
416
joychen03eaad92013-06-26 09:55:21 -0700417 Eg: The job_repo_url "http://lmn.cd.ab.xyx:8080/static/\
beepscb6f1e22013-06-28 19:14:10 -0700418 lumpy-release/R29-4279.0.0/autotest/packages" claims to have the
419 autotest package for lumpy-release/R29-4279.0.0. If this isn't the case,
420 download and extract it. If the devserver embedded in the url is
421 unresponsive, update the job_repo_url of the host after staging it on
422 another devserver.
423
424 @param job_repo_url: A url pointing to the devserver where the autotest
425 package for this build should be staged.
beepsdae65fd2013-07-26 16:24:41 -0700426 @param tag: The tag from the server job, in the format
427 <job_id>-<user>/<hostname>, or <hostless> for a server job.
beepscb6f1e22013-06-28 19:14:10 -0700428
429 @raises DevServerException: If we could not resolve a devserver.
430 @raises AutoservError: If we're unable to save the new job_repo_url as
431 a result of choosing a new devserver because the old one failed to
432 respond to a health check.
beeps0c865032013-07-30 11:37:06 -0700433 @raises urllib2.URLError: If the devserver embedded in job_repo_url
434 doesn't respond within the timeout.
beepscb6f1e22013-06-28 19:14:10 -0700435 """
436 job_repo_url = self.lookup_job_repo_url()
437 if not job_repo_url:
438 logging.warning('No job repo url set on host %s', self.hostname)
439 return
440
441 logging.info('Verifying job repo url %s', job_repo_url)
442 devserver_url, image_name = tools.get_devserver_build_from_package_url(
443 job_repo_url)
444
beeps0c865032013-07-30 11:37:06 -0700445 ds = dev_server.ImageServer(devserver_url)
beepscb6f1e22013-06-28 19:14:10 -0700446
447 logging.info('Staging autotest artifacts for %s on devserver %s',
448 image_name, ds.url())
beeps687243d2013-07-18 15:29:27 -0700449
450 start_time = time.time()
Simran Basi25e7a922014-10-31 11:56:10 -0700451 ds.stage_artifacts(image_name, ['autotest_packages'])
beeps687243d2013-07-18 15:29:27 -0700452 stage_time = time.time() - start_time
453
454 # Record how much of the verification time comes from a devserver
455 # restage. If we're doing things right we should not see multiple
456 # devservers for a given board/build/branch path.
457 try:
J. Richard Barnette3cbd76b2013-11-27 12:11:25 -0800458 board, build_type, branch = server_utils.ParseBuildName(
beeps687243d2013-07-18 15:29:27 -0700459 image_name)[:3]
J. Richard Barnette3cbd76b2013-11-27 12:11:25 -0800460 except server_utils.ParseBuildNameException:
beeps687243d2013-07-18 15:29:27 -0700461 pass
462 else:
beeps0c865032013-07-30 11:37:06 -0700463 devserver = devserver_url[
Chris Sosa65425082013-10-16 13:26:22 -0700464 devserver_url.find('/') + 2:devserver_url.rfind(':')]
beeps687243d2013-07-18 15:29:27 -0700465 stats_key = {
466 'board': board,
467 'build_type': build_type,
468 'branch': branch,
beeps0c865032013-07-30 11:37:06 -0700469 'devserver': devserver.replace('.', '_'),
beeps687243d2013-07-18 15:29:27 -0700470 }
Gabe Black1e1c41b2015-02-04 23:55:15 -0800471 autotest_stats.Gauge('verify_job_repo_url').send(
beeps687243d2013-07-18 15:29:27 -0700472 '%(board)s.%(build_type)s.%(branch)s.%(devserver)s' % stats_key,
473 stage_time)
beepscb6f1e22013-06-28 19:14:10 -0700474
Scott Zawalskieadbf702013-03-14 09:23:06 -0400475
Dan Shicf4d2032015-03-12 15:04:21 -0700476 def stage_server_side_package(self, image=None):
477 """Stage autotest server-side package on devserver.
478
479 @param image: Full path of an OS image to install or a build name.
480
481 @return: A url to the autotest server-side package.
482 """
483 if image:
484 image_name = tools.get_build_from_image(image)
485 if not image_name:
486 raise error.AutoservError(
487 'Failed to parse build name from %s' % image)
488 ds = dev_server.ImageServer.resolve(image_name)
489 else:
490 job_repo_url = self.lookup_job_repo_url()
491 if job_repo_url:
492 devserver_url, image_name = (
493 tools.get_devserver_build_from_package_url(job_repo_url))
494 ds = dev_server.ImageServer(devserver_url)
495 else:
496 labels = self._AFE.get_labels(
497 name__startswith=ds_constants.VERSION_PREFIX,
498 host__hostname=self.hostname)
499 if not labels:
500 raise error.AutoservError(
501 'Failed to stage server-side package. The host has '
502 'no job_report_url attribute or version label.')
503 image_name = labels[0].name[len(ds_constants.VERSION_PREFIX):]
504 ds = dev_server.ImageServer.resolve(image_name)
Dan Shica503482015-03-30 17:23:25 -0700505
506 # Get the OS version of the build, for any build older than
507 # MIN_VERSION_SUPPORT_SSP, server side packaging is not supported.
508 match = re.match('.*/R\d+-(\d+)\.', image_name)
509 if match and int(match.group(1)) < self.MIN_VERSION_SUPPORT_SSP:
510 logging.warn('Build %s is older than %s. Server side packaging is '
511 'disabled.', image_name, self.MIN_VERSION_SUPPORT_SSP)
512 return None
513
Dan Shicf4d2032015-03-12 15:04:21 -0700514 ds.stage_artifacts(image_name, ['autotest_server_package'])
515 return '%s/static/%s/%s' % (ds.url(), image_name,
516 'autotest_server_package.tar.bz2')
517
518
Dan Shi0f466e82013-02-22 15:44:58 -0800519 def _try_stateful_update(self, update_url, force_update, updater):
520 """Try to use stateful update to initialize DUT.
521
522 When DUT is already running the same version that machine_install
523 tries to install, stateful update is a much faster way to clean up
524 the DUT for testing, compared to a full reimage. It is implemeted
525 by calling autoupdater.run_update, but skipping updating root, as
526 updating the kernel is time consuming and not necessary.
527
528 @param update_url: url of the image.
529 @param force_update: Set to True to update the image even if the DUT
530 is running the same version.
531 @param updater: ChromiumOSUpdater instance used to update the DUT.
532 @returns: True if the DUT was updated with stateful update.
533
534 """
J. Richard Barnette3f731032014-04-07 17:42:59 -0700535 # TODO(jrbarnette): Yes, I hate this re.match() test case.
536 # It's better than the alternative: see crbug.com/360944.
537 image_name = autoupdater.url_to_image_name(update_url)
538 release_pattern = r'^.*-release/R[0-9]+-[0-9]+\.[0-9]+\.0$'
539 if not re.match(release_pattern, image_name):
540 return False
Dan Shi0f466e82013-02-22 15:44:58 -0800541 if not updater.check_version():
542 return False
543 if not force_update:
544 logging.info('Canceling stateful update because the new and '
545 'old versions are the same.')
546 return False
547 # Following folders should be rebuilt after stateful update.
548 # A test file is used to confirm each folder gets rebuilt after
549 # the stateful update.
550 folders_to_check = ['/var', '/home', '/mnt/stateful_partition']
551 test_file = '.test_file_to_be_deleted'
552 for folder in folders_to_check:
553 touch_path = os.path.join(folder, test_file)
554 self.run('touch %s' % touch_path)
555
Chris Sosae92399e2015-04-24 11:32:59 -0700556 updater.run_update(update_root=False)
Dan Shi0f466e82013-02-22 15:44:58 -0800557
558 # Reboot to complete stateful update.
Chris Sosab76e0ee2013-05-22 16:55:41 -0700559 self.reboot(timeout=self.REBOOT_TIMEOUT, wait=True)
Dan Shi0f466e82013-02-22 15:44:58 -0800560 check_file_cmd = 'test -f %s; echo $?'
561 for folder in folders_to_check:
562 test_file_path = os.path.join(folder, test_file)
563 result = self.run(check_file_cmd % test_file_path,
564 ignore_status=True)
565 if result.exit_status == 1:
566 return False
567 return True
568
569
J. Richard Barnette7275b612013-06-04 18:13:11 -0700570 def _post_update_processing(self, updater, expected_kernel=None):
Dan Shi0f466e82013-02-22 15:44:58 -0800571 """After the DUT is updated, confirm machine_install succeeded.
572
573 @param updater: ChromiumOSUpdater instance used to update the DUT.
J. Richard Barnette7275b612013-06-04 18:13:11 -0700574 @param expected_kernel: kernel expected to be active after reboot,
575 or `None` to skip rollback checking.
Dan Shi0f466e82013-02-22 15:44:58 -0800576
577 """
J. Richard Barnette7275b612013-06-04 18:13:11 -0700578 # Touch the lab machine file to leave a marker that
579 # distinguishes this image from other test images.
580 # Afterwards, we must re-run the autoreboot script because
581 # it depends on the _LAB_MACHINE_FILE.
Dan Shi0f466e82013-02-22 15:44:58 -0800582 self.run('touch %s' % self._LAB_MACHINE_FILE)
Dan Shi0f466e82013-02-22 15:44:58 -0800583 self.run('start autoreboot')
Chris Sosa65425082013-10-16 13:26:22 -0700584 updater.verify_boot_expectations(
585 expected_kernel, rollback_message=
Gilad Arnoldc26ae1f2015-10-22 16:09:41 -0700586 'Build %s failed to boot on %s; system rolled back to previous '
Chris Sosa65425082013-10-16 13:26:22 -0700587 'build' % (updater.update_version, self.hostname))
J. Richard Barnette7275b612013-06-04 18:13:11 -0700588 # Check that we've got the build we meant to install.
589 if not updater.check_version_to_confirm_install():
590 raise autoupdater.ChromiumOSError(
591 'Failed to update %s to build %s; found build '
592 '%s instead' % (self.hostname,
Chris Sosa65425082013-10-16 13:26:22 -0700593 updater.update_version,
Dan Shi0942b1d2015-03-31 11:07:00 -0700594 self.get_release_version()))
Dan Shi0f466e82013-02-22 15:44:58 -0800595
Chris Sosae92399e2015-04-24 11:32:59 -0700596 logging.debug('Cleaning up old autotest directories.')
597 try:
598 installed_autodir = autotest.Autotest.get_installed_autodir(self)
599 self.run('rm -rf ' + installed_autodir)
600 except autotest.AutodirNotFoundError:
601 logging.debug('No autotest installed directory found.')
602
Dan Shi0f466e82013-02-22 15:44:58 -0800603
J. Richard Barnettee4af8b92013-05-01 13:16:12 -0700604 def _stage_image_for_update(self, image_name=None):
Chris Sosae92399e2015-04-24 11:32:59 -0700605 """Stage a build on a devserver and return the update_url and devserver.
Scott Zawalskieadbf702013-03-14 09:23:06 -0400606
607 @param image_name: a name like lumpy-release/R27-3837.0.0
Chris Sosae92399e2015-04-24 11:32:59 -0700608 @returns a tuple with an update URL like:
Scott Zawalskieadbf702013-03-14 09:23:06 -0400609 http://172.22.50.205:8082/update/lumpy-release/R27-3837.0.0
Chris Sosae92399e2015-04-24 11:32:59 -0700610 and the devserver instance.
Scott Zawalskieadbf702013-03-14 09:23:06 -0400611 """
J. Richard Barnettee4af8b92013-05-01 13:16:12 -0700612 if not image_name:
613 image_name = self.get_repair_image_name()
Chris Sosae92399e2015-04-24 11:32:59 -0700614
J. Richard Barnettee4af8b92013-05-01 13:16:12 -0700615 logging.info('Staging build for AU: %s', image_name)
Scott Zawalskieadbf702013-03-14 09:23:06 -0400616 devserver = dev_server.ImageServer.resolve(image_name)
617 devserver.trigger_download(image_name, synchronous=False)
Chris Sosae92399e2015-04-24 11:32:59 -0700618 return (tools.image_url_pattern() % (devserver.url(), image_name),
619 devserver)
Scott Zawalskieadbf702013-03-14 09:23:06 -0400620
621
J. Richard Barnettee4af8b92013-05-01 13:16:12 -0700622 def stage_image_for_servo(self, image_name=None):
623 """Stage a build on a devserver and return the update_url.
624
625 @param image_name: a name like lumpy-release/R27-3837.0.0
626 @returns an update URL like:
627 http://172.22.50.205:8082/update/lumpy-release/R27-3837.0.0
628 """
629 if not image_name:
630 image_name = self.get_repair_image_name()
631 logging.info('Staging build for servo install: %s', image_name)
632 devserver = dev_server.ImageServer.resolve(image_name)
633 devserver.stage_artifacts(image_name, ['test_image'])
634 return devserver.get_test_image_url(image_name)
635
636
beepse539be02013-07-31 21:57:39 -0700637 def stage_factory_image_for_servo(self, image_name):
638 """Stage a build on a devserver and return the update_url.
639
640 @param image_name: a name like <baord>/4262.204.0
beeps12c0a3c2013-09-03 11:58:27 -0700641
beepse539be02013-07-31 21:57:39 -0700642 @return: An update URL, eg:
643 http://<devserver>/static/canary-channel/\
644 <board>/4262.204.0/factory_test/chromiumos_factory_image.bin
beeps12c0a3c2013-09-03 11:58:27 -0700645
646 @raises: ValueError if the factory artifact name is missing from
647 the config.
648
beepse539be02013-07-31 21:57:39 -0700649 """
650 if not image_name:
651 logging.error('Need an image_name to stage a factory image.')
652 return
653
Dan Shib8540a52015-07-16 14:18:23 -0700654 factory_artifact = CONFIG.get_config_value(
beeps12c0a3c2013-09-03 11:58:27 -0700655 'CROS', 'factory_artifact', type=str, default='')
656 if not factory_artifact:
657 raise ValueError('Cannot retrieve the factory artifact name from '
658 'autotest config, and hence cannot stage factory '
659 'artifacts.')
660
beepse539be02013-07-31 21:57:39 -0700661 logging.info('Staging build for servo install: %s', image_name)
662 devserver = dev_server.ImageServer.resolve(image_name)
663 devserver.stage_artifacts(
664 image_name,
beeps12c0a3c2013-09-03 11:58:27 -0700665 [factory_artifact],
666 archive_url=None)
beepse539be02013-07-31 21:57:39 -0700667
668 return tools.factory_image_url_pattern() % (devserver.url(), image_name)
669
670
Chris Sosaa3ac2152012-05-23 22:23:13 -0700671 def machine_install(self, update_url=None, force_update=False,
Richard Barnette0b023a72015-04-24 16:07:30 +0000672 local_devserver=False, repair=False,
673 force_full_update=False):
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500674 """Install the DUT.
675
Dan Shi0f466e82013-02-22 15:44:58 -0800676 Use stateful update if the DUT is already running the same build.
677 Stateful update does not update kernel and tends to run much faster
678 than a full reimage. If the DUT is running a different build, or it
679 failed to do a stateful update, full update, including kernel update,
680 will be applied to the DUT.
681
Scott Zawalskieadbf702013-03-14 09:23:06 -0400682 Once a host enters machine_install its cros_version label will be
683 removed as well as its host attribute job_repo_url (used for
684 package install).
685
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500686 @param update_url: The url to use for the update
687 pattern: http://$devserver:###/update/$build
688 If update_url is None and repair is True we will install the
Dan Shi6964fa52014-12-18 11:04:27 -0800689 stable image listed in afe_stable_versions table. If the table
690 is not setup, global_config value under CROS.stable_cros_version
691 will be used instead.
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500692 @param force_update: Force an update even if the version installed
693 is the same. Default:False
Christopher Wiley6a4ff932015-05-15 14:00:47 -0700694 @param local_devserver: Used by test_that to allow people to
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500695 use their local devserver. Default: False
Chris Sosae92399e2015-04-24 11:32:59 -0700696 @param repair: Forces update to repair image. Implies force_update.
Fang Deng3d3b9272014-12-22 12:20:28 -0800697 @param force_full_update: If True, do not attempt to run stateful
698 update, force a full reimage. If False, try stateful update
699 first when the dut is already installed with the same version.
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500700 @raises autoupdater.ChromiumOSError
701
702 """
Chris Sosae92399e2015-04-24 11:32:59 -0700703 devserver = None
Richard Barnette0b023a72015-04-24 16:07:30 +0000704 if repair:
Chris Sosae92399e2015-04-24 11:32:59 -0700705 update_url, devserver = self._stage_image_for_update()
Richard Barnette0b023a72015-04-24 16:07:30 +0000706 force_update = True
Dan Shi0f466e82013-02-22 15:44:58 -0800707
Chris Sosae92399e2015-04-24 11:32:59 -0700708 if not update_url and not self._parser.options.image:
709 raise error.AutoservError(
Dan Shid07ee2e2015-09-24 14:49:25 -0700710 'There is no update URL, nor a method to get one.')
Chris Sosae92399e2015-04-24 11:32:59 -0700711
712 if not update_url and self._parser.options.image:
713 # This is the base case where we have no given update URL i.e.
714 # dynamic suites logic etc. This is the most flexible case where we
715 # can serve an update from any of our fleet of devservers.
716 requested_build = self._parser.options.image
717 if not requested_build.startswith('http://'):
718 logging.debug('Update will be staged for this installation')
719 update_url, devserver = self._stage_image_for_update(
Dan Shid07ee2e2015-09-24 14:49:25 -0700720 requested_build)
Chris Sosae92399e2015-04-24 11:32:59 -0700721 else:
722 update_url = requested_build
723
724 logging.debug('Update URL is %s', update_url)
725
Scott Zawalskieadbf702013-03-14 09:23:06 -0400726 # Remove cros-version and job_repo_url host attribute from host.
727 self.clear_cros_version_labels_and_job_repo_url()
Chris Sosae92399e2015-04-24 11:32:59 -0700728
Dan Shid07ee2e2015-09-24 14:49:25 -0700729 # Create a file to indicate if provision fails. The file will be removed
730 # by stateful update or full install.
731 self.run('touch %s' % PROVISION_FAILED)
732
Chris Sosae92399e2015-04-24 11:32:59 -0700733 update_complete = False
734 updater = autoupdater.ChromiumOSUpdater(
735 update_url, host=self, local_devserver=local_devserver)
Fang Deng3d3b9272014-12-22 12:20:28 -0800736 if not force_full_update:
737 try:
Chris Sosae92399e2015-04-24 11:32:59 -0700738 # If the DUT is already running the same build, try stateful
739 # update first as it's much quicker than a full re-image.
740 update_complete = self._try_stateful_update(
Dan Shid07ee2e2015-09-24 14:49:25 -0700741 update_url, force_update, updater)
Fang Deng3d3b9272014-12-22 12:20:28 -0800742 except Exception as e:
743 logging.exception(e)
J. Richard Barnette45e93de2012-04-11 17:24:15 -0700744
Dan Shi0f466e82013-02-22 15:44:58 -0800745 inactive_kernel = None
Chris Sosae92399e2015-04-24 11:32:59 -0700746 if update_complete or (not force_update and updater.check_version()):
747 logging.info('Install complete without full update')
748 else:
749 logging.info('DUT requires full update.')
750 self.reboot(timeout=self.REBOOT_TIMEOUT, wait=True)
751 num_of_attempts = provision.FLAKY_DEVSERVER_ATTEMPTS
Chris Sosab7612bc2013-03-21 10:32:37 -0700752
Chris Sosae92399e2015-04-24 11:32:59 -0700753 while num_of_attempts > 0:
754 num_of_attempts -= 1
755 try:
756 updater.run_update()
757 except Exception:
758 logging.warn('Autoupdate did not complete.')
759 # Do additional check for the devserver health. Ideally,
760 # the autoupdater.py could raise an exception when it
761 # detected network flake but that would require
762 # instrumenting the update engine and parsing it log.
763 if (num_of_attempts <= 0 or
764 devserver is None or
765 dev_server.DevServer.devserver_healthy(
766 devserver.url())):
Dan Shid07ee2e2015-09-24 14:49:25 -0700767 raise
J. Richard Barnette45e93de2012-04-11 17:24:15 -0700768
Chris Sosae92399e2015-04-24 11:32:59 -0700769 logging.warn('Devserver looks unhealthy. Trying another')
770 update_url, devserver = self._stage_image_for_update(
771 requested_build)
772 logging.debug('New Update URL is %s', update_url)
773 updater = autoupdater.ChromiumOSUpdater(
774 update_url, host=self,
775 local_devserver=local_devserver)
776 else:
777 break
J. Richard Barnette45e93de2012-04-11 17:24:15 -0700778
Chris Sosae92399e2015-04-24 11:32:59 -0700779 # Give it some time in case of IO issues.
780 time.sleep(10)
Dan Shi5699ac22014-12-19 10:55:49 -0800781
Chris Sosae92399e2015-04-24 11:32:59 -0700782 # Figure out active and inactive kernel.
783 active_kernel, inactive_kernel = updater.get_kernel_state()
Simran Basi13fa1ba2013-03-04 10:56:47 -0800784
Chris Sosae92399e2015-04-24 11:32:59 -0700785 # Ensure inactive kernel has higher priority than active.
786 if (updater.get_kernel_priority(inactive_kernel)
787 < updater.get_kernel_priority(active_kernel)):
788 raise autoupdater.ChromiumOSError(
789 'Update failed. The priority of the inactive kernel'
790 ' partition is less than that of the active kernel'
791 ' partition.')
792
793 # Updater has returned successfully; reboot the host.
794 self.reboot(timeout=self.REBOOT_TIMEOUT, wait=True)
795
796 self._post_update_processing(updater, inactive_kernel)
797 self.add_cros_version_labels_and_job_repo_url(
798 autoupdater.url_to_image_name(update_url))
J. Richard Barnette45e93de2012-04-11 17:24:15 -0700799
800
Dan Shi9cb0eec2014-06-03 09:04:50 -0700801 def _clear_fw_version_labels(self):
802 """Clear firmware version labels from the machine."""
803 labels = self._AFE.get_labels(
Dan Shi0723bf52015-06-24 10:52:38 -0700804 name__startswith=provision.FW_RW_VERSION_PREFIX,
Dan Shi9cb0eec2014-06-03 09:04:50 -0700805 host__hostname=self.hostname)
806 for label in labels:
807 label.remove_hosts(hosts=[self.hostname])
808
809
810 def _add_fw_version_label(self, build):
811 """Add firmware version label to the machine.
812
813 @param build: Build of firmware.
814
815 """
816 fw_label = provision.fw_version_to_label(build)
MK Ryu73be9862015-07-06 12:25:00 -0700817 self._AFE.run('label_add_hosts', id=fw_label, hosts=[self.hostname])
Dan Shi9cb0eec2014-06-03 09:04:50 -0700818
819
820 def firmware_install(self, build=None):
821 """Install firmware to the DUT.
822
823 Use stateful update if the DUT is already running the same build.
824 Stateful update does not update kernel and tends to run much faster
825 than a full reimage. If the DUT is running a different build, or it
826 failed to do a stateful update, full update, including kernel update,
827 will be applied to the DUT.
828
829 Once a host enters firmware_install its fw_version label will be
830 removed. After the firmware is updated successfully, a new fw_version
831 label will be added to the host.
832
833 @param build: The build version to which we want to provision the
834 firmware of the machine,
835 e.g. 'link-firmware/R22-2695.1.144'.
836
837 TODO(dshi): After bug 381718 is fixed, update here with corresponding
838 exceptions that could be raised.
839
840 """
841 if not self.servo:
842 raise error.TestError('Host %s does not have servo.' %
843 self.hostname)
844
845 # TODO(fdeng): use host.get_board() after
846 # crbug.com/271834 is fixed.
847 board = self._get_board_from_afe()
848
Chris Sosae92399e2015-04-24 11:32:59 -0700849 # If build is not set, try to install firmware from stable CrOS.
Dan Shi9cb0eec2014-06-03 09:04:50 -0700850 if not build:
Dan Shi3d7a0e12015-10-12 11:55:45 -0700851 build = self.get_repair_image_name(image_type='firmware')
852 if not build:
853 raise error.TestError(
854 'Failed to find stable firmware build for %s.',
855 self.hostname)
856 logging.info('Will install firmware from build %s.', build)
Dan Shi9cb0eec2014-06-03 09:04:50 -0700857
858 config = FAFTConfig(board)
859 if config.use_u_boot:
860 ap_image = 'image-%s.bin' % board
861 else: # Depthcharge platform
862 ap_image = 'image.bin'
863 ec_image = 'ec.bin'
864 ds = dev_server.ImageServer.resolve(build)
865 ds.stage_artifacts(build, ['firmware'])
866
867 tmpd = autotemp.tempdir(unique_id='fwimage')
868 try:
869 fwurl = self._FW_IMAGE_URL_PATTERN % (ds.url(), build)
870 local_tarball = os.path.join(tmpd.name, os.path.basename(fwurl))
871 server_utils.system('wget -O %s %s' % (local_tarball, fwurl),
872 timeout=60)
873 server_utils.system('tar xf %s -C %s %s %s' %
874 (local_tarball, tmpd.name, ap_image, ec_image),
875 timeout=60)
876 server_utils.system('tar xf %s --wildcards -C %s "dts/*"' %
877 (local_tarball, tmpd.name),
878 timeout=60, ignore_status=True)
879
880 self._clear_fw_version_labels()
881 logging.info('Will re-program EC now')
882 self.servo.program_ec(os.path.join(tmpd.name, ec_image))
883 logging.info('Will re-program BIOS now')
884 self.servo.program_bios(os.path.join(tmpd.name, ap_image))
885 self.servo.get_power_state_controller().reset()
886 time.sleep(self.servo.BOOT_DELAY)
Dan Shia5fef052015-05-18 23:28:47 -0700887 self._add_fw_version_label(build)
Dan Shi9cb0eec2014-06-03 09:04:50 -0700888 finally:
889 tmpd.clean()
890
891
Dan Shi10e992b2013-08-30 11:02:59 -0700892 def show_update_engine_log(self):
893 """Output update engine log."""
MK Ryu35d661e2014-09-25 17:44:10 -0700894 logging.debug('Dumping %s', client_constants.UPDATE_ENGINE_LOG)
895 self.run('cat %s' % client_constants.UPDATE_ENGINE_LOG)
Dan Shi10e992b2013-08-30 11:02:59 -0700896
897
Richard Barnette82c35912012-11-20 10:09:10 -0800898 def _get_board_from_afe(self):
899 """Retrieve this host's board from its labels in the AFE.
900
901 Looks for a host label of the form "board:<board>", and
902 returns the "<board>" part of the label. `None` is returned
903 if there is not a single, unique label matching the pattern.
904
905 @returns board from label, or `None`.
906 """
Dan Shia1ecd5c2013-06-06 11:21:31 -0700907 return server_utils.get_board_from_afe(self.hostname, self._AFE)
Simran Basi833814b2013-01-29 13:13:43 -0800908
909
910 def get_build(self):
911 """Retrieve the current build for this Host from the AFE.
912
913 Looks through this host's labels in the AFE to determine its build.
914
915 @returns The current build or None if it could not find it or if there
916 were multiple build labels assigned to this host.
917 """
Dan Shia1ecd5c2013-06-06 11:21:31 -0700918 return server_utils.get_build_from_afe(self.hostname, self._AFE)
Richard Barnette82c35912012-11-20 10:09:10 -0800919
920
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500921 def _install_repair(self):
Chris Sosae92399e2015-04-24 11:32:59 -0700922 """Attempt to repair this host using the update-engine.
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500923
924 If the host is up, try installing the DUT with a stable
Dan Shi6964fa52014-12-18 11:04:27 -0800925 "repair" version of Chrome OS as defined in afe_stable_versions table.
926 If the table is not setup, global_config value under
927 CROS.stable_cros_version will be used instead.
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500928
Scott Zawalski62bacae2013-03-05 10:40:32 -0500929 @raises AutoservRepairMethodNA if the DUT is not reachable.
930 @raises ChromiumOSError if the install failed for some reason.
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500931
932 """
933 if not self.is_up():
Scott Zawalski62bacae2013-03-05 10:40:32 -0500934 raise error.AutoservRepairMethodNA('DUT unreachable for install.')
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500935 logging.info('Attempting to reimage machine to repair image.')
936 try:
Richard Barnette0b023a72015-04-24 16:07:30 +0000937 self.machine_install(repair=True)
Fang Dengd0672f32013-03-18 17:18:09 -0700938 except autoupdater.ChromiumOSError as e:
939 logging.exception(e)
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500940 logging.info('Repair via install failed.')
Scott Zawalski62bacae2013-03-05 10:40:32 -0500941 raise
Scott Zawalski89c44dd2013-02-26 09:28:02 -0500942
943
Dan Shi2c88eed2013-11-12 10:18:38 -0800944 def _install_repair_with_powerwash(self):
Dan Shi9cc48452013-11-12 12:39:26 -0800945 """Attempt to powerwash first then repair this host using update-engine.
Dan Shi2c88eed2013-11-12 10:18:38 -0800946
Dan Shi9cc48452013-11-12 12:39:26 -0800947 update-engine may fail due to a bad image. In such case, powerwash
948 may help to cleanup the DUT for update-engine to work again.
Dan Shi2c88eed2013-11-12 10:18:38 -0800949
950 @raises AutoservRepairMethodNA if the DUT is not reachable.
951 @raises ChromiumOSError if the install failed for some reason.
952
953 """
954 if not self.is_up():
955 raise error.AutoservRepairMethodNA('DUT unreachable for install.')
956
957 logging.info('Attempting to powerwash the DUT.')
958 self.run('echo "fast safe" > '
959 '/mnt/stateful_partition/factory_install_reset')
960 self.reboot(timeout=self.POWERWASH_BOOT_TIMEOUT, wait=True)
961 if not self.is_up():
Dan Shi9cc48452013-11-12 12:39:26 -0800962 logging.error('Powerwash failed. DUT did not come back after '
Dan Shi2c88eed2013-11-12 10:18:38 -0800963 'reboot.')
964 raise error.AutoservRepairFailure(
965 'DUT failed to boot from powerwash after %d seconds' %
966 self.POWERWASH_BOOT_TIMEOUT)
967
968 logging.info('Powerwash succeeded.')
969 self._install_repair()
970
971
beepsf079cfb2013-09-18 17:49:51 -0700972 def servo_install(self, image_url=None, usb_boot_timeout=USB_BOOT_TIMEOUT,
973 install_timeout=INSTALL_TIMEOUT):
Scott Zawalski62bacae2013-03-05 10:40:32 -0500974 """
975 Re-install the OS on the DUT by:
976 1) installing a test image on a USB storage device attached to the Servo
977 board,
Richard Barnette03a0c132012-11-05 12:40:35 -0800978 2) booting that image in recovery mode, and then
J. Richard Barnette31b2e312013-04-04 16:05:22 -0700979 3) installing the image with chromeos-install.
980
Scott Zawalski62bacae2013-03-05 10:40:32 -0500981 @param image_url: If specified use as the url to install on the DUT.
982 otherwise boot the currently staged image on the USB stick.
beepsf079cfb2013-09-18 17:49:51 -0700983 @param usb_boot_timeout: The usb_boot_timeout to use during reimage.
984 Factory images need a longer usb_boot_timeout than regular
985 cros images.
986 @param install_timeout: The timeout to use when installing the chromeos
987 image. Factory images need a longer install_timeout.
Richard Barnette03a0c132012-11-05 12:40:35 -0800988
Scott Zawalski62bacae2013-03-05 10:40:32 -0500989 @raises AutoservError if the image fails to boot.
beepsf079cfb2013-09-18 17:49:51 -0700990
J. Richard Barnette0199cc82014-12-05 17:08:40 -0800991 """
beepsf079cfb2013-09-18 17:49:51 -0700992 usb_boot_timer_key = ('servo_install.usb_boot_timeout_%s'
993 % usb_boot_timeout)
994 logging.info('Downloading image to USB, then booting from it. Usb boot '
995 'timeout = %s', usb_boot_timeout)
Gabe Black1e1c41b2015-02-04 23:55:15 -0800996 timer = autotest_stats.Timer(usb_boot_timer_key)
beepsf079cfb2013-09-18 17:49:51 -0700997 timer.start()
J. Richard Barnette31b2e312013-04-04 16:05:22 -0700998 self.servo.install_recovery_image(image_url)
beepsf079cfb2013-09-18 17:49:51 -0700999 if not self.wait_up(timeout=usb_boot_timeout):
Scott Zawalski62bacae2013-03-05 10:40:32 -05001000 raise error.AutoservRepairFailure(
1001 'DUT failed to boot from USB after %d seconds' %
beepsf079cfb2013-09-18 17:49:51 -07001002 usb_boot_timeout)
1003 timer.stop()
Scott Zawalski62bacae2013-03-05 10:40:32 -05001004
Tom Wai-Hong Tamf6b4f812015-08-08 04:14:59 +08001005 # The new chromeos-tpm-recovery has been merged since R44-7073.0.0.
1006 # In old CrOS images, this command fails. Skip the error.
Tom Wai-Hong Tam27af7332015-07-25 06:09:39 +08001007 logging.info('Resetting the TPM status')
Tom Wai-Hong Tamf6b4f812015-08-08 04:14:59 +08001008 try:
1009 self.run('chromeos-tpm-recovery')
1010 except error.AutoservRunError:
1011 logging.warn('chromeos-tpm-recovery is too old.')
1012
Tom Wai-Hong Tam27af7332015-07-25 06:09:39 +08001013
beepsf079cfb2013-09-18 17:49:51 -07001014 install_timer_key = ('servo_install.install_timeout_%s'
1015 % install_timeout)
Gabe Black1e1c41b2015-02-04 23:55:15 -08001016 timer = autotest_stats.Timer(install_timer_key)
beepsf079cfb2013-09-18 17:49:51 -07001017 timer.start()
1018 logging.info('Installing image through chromeos-install.')
J. Richard Barnette9af19632015-09-25 12:18:03 -07001019 self.run('chromeos-install --yes', timeout=install_timeout)
1020 self.halt()
beepsf079cfb2013-09-18 17:49:51 -07001021 timer.stop()
1022
1023 logging.info('Power cycling DUT through servo.')
J. Richard Barnette0199cc82014-12-05 17:08:40 -08001024 self.servo.get_power_state_controller().power_off()
Fang Dengafb88142013-05-30 17:44:31 -07001025 self.servo.switch_usbkey('off')
J. Richard Barnette0199cc82014-12-05 17:08:40 -08001026 # N.B. The Servo API requires that we use power_on() here
1027 # for two reasons:
1028 # 1) After turning on a DUT in recovery mode, you must turn
1029 # it off and then on with power_on() once more to
1030 # disable recovery mode (this is a Parrot specific
1031 # requirement).
1032 # 2) After power_off(), the only way to turn on is with
1033 # power_on() (this is a Storm specific requirement).
J. Richard Barnettefbcc7122013-07-24 18:24:59 -07001034 self.servo.get_power_state_controller().power_on()
beepsf079cfb2013-09-18 17:49:51 -07001035
1036 logging.info('Waiting for DUT to come back up.')
Richard Barnette03a0c132012-11-05 12:40:35 -08001037 if not self.wait_up(timeout=self.BOOT_TIMEOUT):
1038 raise error.AutoservError('DUT failed to reboot installed '
1039 'test image after %d seconds' %
Scott Zawalski62bacae2013-03-05 10:40:32 -05001040 self.BOOT_TIMEOUT)
1041
1042
Dan Shic1b8bdd2015-09-14 23:11:24 -07001043 def _setup_servo(self):
1044 """Try to force to create servo object if it's not set up yet.
1045 """
1046 if self.servo:
1047 return
1048
1049 try:
1050 # Setting servo_args to {} will force it to create the servo_host
1051 # object if possible.
1052 self._servo_host = servo_host.create_servo_host(
1053 dut=self.hostname, servo_args={})
1054 if self._servo_host:
1055 self.servo = self._servo_host.get_servo()
1056 else:
1057 logging.error('Failed to create servo_host object.')
1058 except Exception as e:
1059 logging.error('Failed to create servo object: %s', e)
1060
1061
J. Richard Barnettee4af8b92013-05-01 13:16:12 -07001062 def _servo_repair_reinstall(self):
Scott Zawalski62bacae2013-03-05 10:40:32 -05001063 """Reinstall the DUT utilizing servo and a test image.
1064
1065 Re-install the OS on the DUT by:
1066 1) installing a test image on a USB storage device attached to the Servo
1067 board,
Tom Wai-Hong Tam27af7332015-07-25 06:09:39 +08001068 2) booting that image in recovery mode,
1069 3) resetting the TPM status, and then
1070 4) installing the image with chromeos-install.
Scott Zawalski62bacae2013-03-05 10:40:32 -05001071
Scott Zawalski62bacae2013-03-05 10:40:32 -05001072 @raises AutoservRepairMethodNA if the device does not have servo
1073 support.
1074
1075 """
Dan Shic1b8bdd2015-09-14 23:11:24 -07001076 # To repair a DUT connected to a moblab, try to create a servo object if
1077 # it was failed to be created earlier as there may be a servo_host host
1078 # attribute for this host.
1079 if utils.is_moblab():
1080 self._setup_servo()
1081
Scott Zawalski62bacae2013-03-05 10:40:32 -05001082 if not self.servo:
1083 raise error.AutoservRepairMethodNA('Repair Reinstall NA: '
1084 'DUT has no servo support.')
1085
1086 logging.info('Attempting to recovery servo enabled device with '
1087 'servo_repair_reinstall')
1088
J. Richard Barnettee4af8b92013-05-01 13:16:12 -07001089 image_url = self.stage_image_for_servo()
Scott Zawalski62bacae2013-03-05 10:40:32 -05001090 self.servo_install(image_url)
1091
1092
Dan Shi3d7a0e12015-10-12 11:55:45 -07001093 def _firmware_repair(self):
1094 """Reinstall the firmware image using servo.
1095
1096 This repair function attempts to install the stable firmware specified
1097 by the stable firmware version.
1098 Then reset the DUT and try to verify it. If verify fails, it will try to
1099 install the CrOS image using servo.
1100
1101 Note that the firmware repair is only applicable to DUTs in pools listed
1102 in global config CROS/pools_support_firmware_repair.
1103 """
1104 logging.info('Checking if host %s can be repaired with firmware '
1105 'repair.', self.hostname)
1106 pools = server_utils.get_labels_from_afe(self.hostname, 'pool:',
1107 self._AFE)
1108 pools_support_firmware_repair = CONFIG.get_config_value('CROS',
1109 'pools_support_firmware_repair', type=str).split(',')
1110 if (not pools or not pools_support_firmware_repair or
1111 not set(pools).intersection(set(pools_support_firmware_repair))):
1112 logging.info('Host %s is not in pools that support firmware repair.'
1113 ' pools supporting firmware repair are: %s.',
1114 self.hostname, pools_support_firmware_repair)
1115 raise error.AutoservRepairMethodNA(
1116 'Firmware repair is not applicable to host %s.' %
1117 self.hostname)
1118
1119 # To repair a DUT connected to a moblab, try to create a servo object if
1120 # it was failed to be created earlier as there may be a servo_host host
1121 # attribute for this host.
1122 if utils.is_moblab():
1123 self._setup_servo()
1124
1125 if not self.servo:
1126 raise error.AutoservRepairMethodNA('Repair Reinstall NA: '
1127 'DUT has no servo support.')
1128
1129 logging.info('Attempting to recovery servo enabled device with '
1130 'firmware_repair.')
1131 self.firmware_install()
1132
1133 logging.info('Firmware repaired. Check if the DUT can boot. If not, '
1134 'reinstall the CrOS using servo.')
1135 try:
1136 self.servo.reset()
1137 self.verify()
1138 except Exception as e:
1139 logging.warn('Failed to verify DUT, error: %s. Will try to repair '
1140 'the DUT with servo_repair_reinstall.', e)
1141 self._servo_repair_reinstall()
1142
1143
Scott Zawalski62bacae2013-03-05 10:40:32 -05001144 def _servo_repair_power(self):
1145 """Attempt to repair DUT using an attached Servo.
1146
1147 Attempt to power on the DUT via power_long_press.
1148
1149 @raises AutoservRepairMethodNA if the device does not have servo
1150 support.
1151 @raises AutoservRepairFailure if the repair fails for any reason.
1152 """
1153 if not self.servo:
1154 raise error.AutoservRepairMethodNA('Repair Power NA: '
1155 'DUT has no servo support.')
1156
1157 logging.info('Attempting to recover servo enabled device by '
1158 'powering it off and on.')
1159 self.servo.get_power_state_controller().power_off()
1160 self.servo.get_power_state_controller().power_on()
1161 if self.wait_up(self.BOOT_TIMEOUT):
1162 return
1163
1164 raise error.AutoservRepairFailure('DUT did not boot after long_press.')
Richard Barnette03a0c132012-11-05 12:40:35 -08001165
1166
Richard Barnette82c35912012-11-20 10:09:10 -08001167 def _powercycle_to_repair(self):
1168 """Utilize the RPM Infrastructure to bring the host back up.
1169
1170 If the host is not up/repaired after the first powercycle we utilize
1171 auto fallback to the last good install by powercycling and rebooting the
1172 host 6 times.
Scott Zawalski62bacae2013-03-05 10:40:32 -05001173
1174 @raises AutoservRepairMethodNA if the device does not support remote
1175 power.
1176 @raises AutoservRepairFailure if the repair fails for any reason.
1177
Richard Barnette82c35912012-11-20 10:09:10 -08001178 """
Scott Zawalski62bacae2013-03-05 10:40:32 -05001179 if not self.has_power():
1180 raise error.AutoservRepairMethodNA('Device does not support power.')
1181
Richard Barnette82c35912012-11-20 10:09:10 -08001182 logging.info('Attempting repair via RPM powercycle.')
1183 failed_cycles = 0
1184 self.power_cycle()
1185 while not self.wait_up(timeout=self.BOOT_TIMEOUT):
1186 failed_cycles += 1
1187 if failed_cycles >= self._MAX_POWER_CYCLE_ATTEMPTS:
Scott Zawalski62bacae2013-03-05 10:40:32 -05001188 raise error.AutoservRepairFailure(
1189 'Powercycled host %s %d times; device did not come back'
1190 ' online.' % (self.hostname, failed_cycles))
Richard Barnette82c35912012-11-20 10:09:10 -08001191 self.power_cycle()
1192 if failed_cycles == 0:
1193 logging.info('Powercycling was successful first time.')
1194 else:
1195 logging.info('Powercycling was successful after %d failures.',
1196 failed_cycles)
1197
1198
MK Ryu35d661e2014-09-25 17:44:10 -07001199 def _reboot_repair(self):
1200 """SSH to this host and reboot."""
1201 if not self.is_up(self._CHECK_HOST_UP_TIMEOUT_SECS):
1202 raise error.AutoservRepairMethodNA('DUT unreachable for reboot.')
1203 logging.info('Attempting repair via SSH reboot.')
1204 self.reboot(timeout=self.BOOT_TIMEOUT, wait=True)
1205
1206
Prashanth B4d8184f2014-05-05 12:22:02 -07001207 def check_device(self):
1208 """Check if a device is ssh-able, and if so, clean and verify it.
1209
1210 @raise AutoservSSHTimeout: If the ssh ping times out.
1211 @raise AutoservSshPermissionDeniedError: If ssh ping fails due to
1212 permissions.
1213 @raise AutoservSshPingHostError: For other AutoservRunErrors during
1214 ssh_ping.
1215 @raises AutoservError: As appropriate, during cleanup and verify.
1216 """
1217 self.ssh_ping()
1218 self.cleanup()
1219 self.verify()
1220
1221
Dan Shi90466352015-09-22 15:01:05 -07001222 def confirm_servo(self):
1223 """Confirm servo is initialized and verified.
1224
1225 @raise AutoservError: If servo is not initialized and verified.
1226 """
1227 if self._servo_host.required_by_test and self.servo:
1228 return
1229
1230 # Force to re-create the servo object to make sure servo is verified.
1231 logging.debug('Rebuilding the servo object.')
1232 self.servo = None
1233 self._servo_host = None
1234 self._setup_servo()
1235 if not self.servo:
1236 raise error.AutoservError('Failed to create servo object.')
1237
1238
Dan Shid07ee2e2015-09-24 14:49:25 -07001239 def _is_last_provision_failed(self):
1240 """Checks if the last provision job failed.
1241
1242 @return: True if there exists file /var/tmp/provision_failed, which
1243 indicates the last provision job failed.
1244 False if the file does not exist or the dut can't be reached.
1245 """
1246 try:
1247 result = self.run('test -f %s' % PROVISION_FAILED,
1248 ignore_status=True, timeout=5)
1249 return result.exit_status == 0
1250 except (error.AutoservRunError, error.AutoservSSHTimeout):
1251 # Default to False, for repair to try all repair method if the dut
1252 # can't be reached.
1253 return False
1254
1255
Richard Barnette82c35912012-11-20 10:09:10 -08001256 def repair_full(self):
1257 """Repair a host for repair level NO_PROTECTION.
1258
1259 This overrides the base class function for repair; it does
1260 not call back to the parent class, but instead offers a
1261 simplified implementation based on the capabilities in the
1262 Chrome OS test lab.
1263
Fang Deng5d518f42013-08-02 14:04:32 -07001264 It first verifies and repairs servo if it is a DUT in CrOS
Fang Deng03590af2013-10-07 17:34:20 -07001265 lab and a servo is attached.
Fang Deng5d518f42013-08-02 14:04:32 -07001266
Jakob Juelich82b7d1c2014-09-15 16:10:57 -07001267 This escalates in order through the following procedures and verifies
1268 the status using `self.check_device()` after each of them. This is done
1269 until both the repair and the veryfing step succeed.
1270
MK Ryu35d661e2014-09-25 17:44:10 -07001271 Escalation order of repair procedures from less intrusive to
1272 more intrusive repairs:
1273 1. SSH to the DUT and reboot.
Scott Zawalski62bacae2013-03-05 10:40:32 -05001274 2. If there's a servo for the DUT, try to power the DUT off and
1275 on.
MK Ryu35d661e2014-09-25 17:44:10 -07001276 3. If the DUT can be power-cycled via RPM, try to repair
Richard Barnette82c35912012-11-20 10:09:10 -08001277 by power-cycling.
MK Ryu35d661e2014-09-25 17:44:10 -07001278 4. Try to re-install to a known stable image using
1279 auto-update.
1280 5. If there's a servo for the DUT, try to re-install via
1281 the servo.
Richard Barnette82c35912012-11-20 10:09:10 -08001282
1283 As with the parent method, the last operation performed on
Prashanth B4d8184f2014-05-05 12:22:02 -07001284 the DUT must be to call `self.check_device()`; If that call fails the
1285 exception it raises is passed back to the caller.
J. Richard Barnettefde55fc2013-03-15 17:47:01 -07001286
Scott Zawalski62bacae2013-03-05 10:40:32 -05001287 @raises AutoservRepairTotalFailure if the repair process fails to
1288 fix the DUT.
Fang Deng5d518f42013-08-02 14:04:32 -07001289 @raises ServoHostRepairTotalFailure if the repair process fails to
1290 fix the servo host if one is attached to the DUT.
1291 @raises AutoservSshPermissionDeniedError if it is unable
1292 to ssh to the servo host due to permission error.
1293
Richard Barnette82c35912012-11-20 10:09:10 -08001294 """
Jakob Juelich82b7d1c2014-09-15 16:10:57 -07001295 # Caution: Deleting shards relies on repair to always reboot the DUT.
1296
Dan Shi4d478522014-02-14 13:46:32 -08001297 if self._servo_host and not self.servo:
Fang Deng03590af2013-10-07 17:34:20 -07001298 try:
Dan Shi4d478522014-02-14 13:46:32 -08001299 self._servo_host.repair_full()
Fang Deng03590af2013-10-07 17:34:20 -07001300 except Exception as e:
Fang Deng03590af2013-10-07 17:34:20 -07001301 logging.error('Could not create a healthy servo: %s', e)
Dan Shi4d478522014-02-14 13:46:32 -08001302 self.servo = self._servo_host.get_servo()
Fang Deng5d518f42013-08-02 14:04:32 -07001303
MK Ryu35d661e2014-09-25 17:44:10 -07001304 self.try_collect_crashlogs()
1305
Scott Zawalski62bacae2013-03-05 10:40:32 -05001306 # TODO(scottz): This should use something similar to label_decorator,
1307 # but needs to be populated in order so DUTs are repaired with the
1308 # least amount of effort.
Dan Shid07ee2e2015-09-24 14:49:25 -07001309 force_powerwash = self._is_last_provision_failed()
1310 if force_powerwash:
1311 logging.info('Last provision failed, try powerwash first.')
1312 autotest_stats.Counter(
1313 'repair_force_powerwash.TOTAL').increment()
1314 repair_funcs = [self._install_repair_with_powerwash,
Dan Shi3d7a0e12015-10-12 11:55:45 -07001315 self._servo_repair_reinstall,
1316 self._firmware_repair]
Dan Shid07ee2e2015-09-24 14:49:25 -07001317 else:
1318 repair_funcs = [self._reboot_repair,
1319 self._servo_repair_power,
1320 self._powercycle_to_repair,
1321 self._install_repair,
1322 self._install_repair_with_powerwash,
Dan Shi3d7a0e12015-10-12 11:55:45 -07001323 self._servo_repair_reinstall,
1324 self._firmware_repair]
Scott Zawalski62bacae2013-03-05 10:40:32 -05001325 errors = []
Simran Basie6130932013-10-01 14:07:52 -07001326 board = self._get_board_from_afe()
Scott Zawalski62bacae2013-03-05 10:40:32 -05001327 for repair_func in repair_funcs:
1328 try:
1329 repair_func()
MK Ryu35d661e2014-09-25 17:44:10 -07001330 self.try_collect_crashlogs()
Prashanth B4d8184f2014-05-05 12:22:02 -07001331 self.check_device()
Gabe Black1e1c41b2015-02-04 23:55:15 -08001332 autotest_stats.Counter(
Simran Basie6130932013-10-01 14:07:52 -07001333 '%s.SUCCEEDED' % repair_func.__name__).increment()
1334 if board:
Gabe Black1e1c41b2015-02-04 23:55:15 -08001335 autotest_stats.Counter(
Dan Shid07ee2e2015-09-24 14:49:25 -07001336 '%s.%s.SUCCEEDED' % (repair_func.__name__,
Simran Basie6130932013-10-01 14:07:52 -07001337 board)).increment()
Dan Shid07ee2e2015-09-24 14:49:25 -07001338 if force_powerwash:
1339 autotest_stats.Counter(
1340 'repair_force_powerwash.SUCCEEDED').increment()
Scott Zawalski62bacae2013-03-05 10:40:32 -05001341 return
Simran Basie6130932013-10-01 14:07:52 -07001342 except error.AutoservRepairMethodNA as e:
Gabe Black1e1c41b2015-02-04 23:55:15 -08001343 autotest_stats.Counter(
Simran Basie6130932013-10-01 14:07:52 -07001344 '%s.RepairNA' % repair_func.__name__).increment()
1345 if board:
Gabe Black1e1c41b2015-02-04 23:55:15 -08001346 autotest_stats.Counter(
Dan Shid07ee2e2015-09-24 14:49:25 -07001347 '%s.%s.RepairNA' % (repair_func.__name__,
1348 board)).increment()
Ilja H. Friedel04be2bd2014-05-07 21:29:59 -07001349 logging.warning('Repair function NA: %s', e)
Simran Basie6130932013-10-01 14:07:52 -07001350 errors.append(str(e))
Scott Zawalski62bacae2013-03-05 10:40:32 -05001351 except Exception as e:
Gabe Black1e1c41b2015-02-04 23:55:15 -08001352 autotest_stats.Counter(
Simran Basie6130932013-10-01 14:07:52 -07001353 '%s.FAILED' % repair_func.__name__).increment()
1354 if board:
Gabe Black1e1c41b2015-02-04 23:55:15 -08001355 autotest_stats.Counter(
Dan Shid07ee2e2015-09-24 14:49:25 -07001356 '%s.%s.FAILED' % (repair_func.__name__,
1357 board)).increment()
Ilja H. Friedel04be2bd2014-05-07 21:29:59 -07001358 logging.warning('Failed to repair device: %s', e)
Scott Zawalski62bacae2013-03-05 10:40:32 -05001359 errors.append(str(e))
Scott Zawalski89c44dd2013-02-26 09:28:02 -05001360
Dan Shid07ee2e2015-09-24 14:49:25 -07001361 if force_powerwash:
1362 autotest_stats.Counter(
1363 'repair_force_powerwash.FAILED').increment()
Gabe Black1e1c41b2015-02-04 23:55:15 -08001364 autotest_stats.Counter('Full_Repair_Failed').increment()
Simran Basie6130932013-10-01 14:07:52 -07001365 if board:
Gabe Black1e1c41b2015-02-04 23:55:15 -08001366 autotest_stats.Counter(
Dan Shid07ee2e2015-09-24 14:49:25 -07001367 'Full_Repair_Failed.%s' % board).increment()
Scott Zawalski62bacae2013-03-05 10:40:32 -05001368 raise error.AutoservRepairTotalFailure(
1369 'All attempts at repairing the device failed:\n%s' %
1370 '\n'.join(errors))
Richard Barnette82c35912012-11-20 10:09:10 -08001371
1372
MK Ryu35d661e2014-09-25 17:44:10 -07001373 def try_collect_crashlogs(self, check_host_up=True):
1374 """
1375 Check if a host is up and logs need to be collected from the host,
1376 if yes, collect them.
1377
1378 @param check_host_up: Flag for checking host is up. Default is True.
1379 """
1380 try:
1381 crash_job = self._need_crash_logs()
1382 if crash_job:
1383 logging.debug('%s: Job %s was crashed', self._CRASHLOGS_PREFIX,
1384 crash_job)
1385 if not check_host_up or self.is_up(
1386 self._CHECK_HOST_UP_TIMEOUT_SECS):
1387 self._collect_crashlogs(crash_job)
1388 logging.debug('%s: Completed collecting logs for the '
1389 'crashed job %s', self._CRASHLOGS_PREFIX,
1390 crash_job)
1391 except Exception as e:
1392 # Exception should not result in repair failure.
1393 # Therefore, suppress all exceptions here.
1394 logging.error('%s: Failed while trying to collect crash-logs: %s',
1395 self._CRASHLOGS_PREFIX, e)
1396
1397
1398 def _need_crash_logs(self):
1399 """Get the value of need_crash_logs attribute of this host.
1400
1401 @return: Value string of need_crash_logs attribute
1402 None if there is no need_crash_logs attribute
1403 """
1404 attrs = self._AFE.get_host_attribute(constants.CRASHLOGS_HOST_ATTRIBUTE,
1405 hostname=self.hostname)
1406 assert len(attrs) < 2
1407 return attrs[0].value if attrs else None
1408
1409
1410 def _collect_crashlogs(self, job_id):
1411 """Grab logs from the host where a job was crashed.
1412
1413 First, check if PRIOR_LOGS_DIR exists in the host.
1414 If yes, collect them.
1415 Otherwise, check if a lab-machine marker (_LAB_MACHINE_FILE) exists
1416 in the host.
1417 If yes, the host was repaired automatically, and we collect normal
1418 system logs.
1419
1420 @param job_id: Id of the job that was crashed.
1421 """
1422 crashlogs_dir = crashcollect.get_crashinfo_dir(self,
1423 constants.CRASHLOGS_DEST_DIR_PREFIX)
1424 flag_prior_logs = False
1425
1426 if self.path_exists(client_constants.PRIOR_LOGS_DIR):
1427 flag_prior_logs = True
1428 self._collect_prior_logs(crashlogs_dir)
1429 elif self.path_exists(self._LAB_MACHINE_FILE):
1430 self._collect_system_logs(crashlogs_dir)
1431 else:
1432 logging.warning('%s: Host was manually re-installed without '
1433 '--lab_preserve_log option. Skip collecting '
1434 'crash-logs.', self._CRASHLOGS_PREFIX)
1435
1436 # We make crash collection be one-time effort.
1437 # _collect_prior_logs() and _collect_system_logs() will not throw
1438 # any exception, and following codes will be executed even when
1439 # those methods fail.
1440 # _collect_crashlogs() is called only when the host is up (refer
1441 # to try_collect_crashlogs()). We assume _collect_prior_logs() and
1442 # _collect_system_logs() fail rarely when the host is up.
1443 # In addition, it is not clear how many times we should try crash
1444 # collection again while not triggering next repair unnecessarily.
1445 # Threfore, we try crash collection one time.
1446
1447 # Create a marker file as soon as log collection is done.
1448 # Leave the job id to this marker for gs_offloader to consume.
1449 marker_file = os.path.join(crashlogs_dir, constants.CRASHLOGS_MARKER)
1450 with open(marker_file, 'a') as f:
1451 f.write('%s\n' % job_id)
1452
1453 # Remove need_crash_logs attribute
1454 logging.debug('%s: Remove attribute need_crash_logs from host %s',
1455 self._CRASHLOGS_PREFIX, self.hostname)
1456 self._AFE.set_host_attribute(constants.CRASHLOGS_HOST_ATTRIBUTE,
1457 None, hostname=self.hostname)
1458
1459 if flag_prior_logs:
1460 logging.debug('%s: Remove %s from host %s', self._CRASHLOGS_PREFIX,
1461 client_constants.PRIOR_LOGS_DIR, self.hostname)
1462 self.run('rm -rf %s; sync' % client_constants.PRIOR_LOGS_DIR)
1463 # Wait for a few seconds to make sure the prior command is
1464 # done deep through storage.
1465 time.sleep(self._SAFE_WAIT_SECS)
1466
1467
1468 def _collect_prior_logs(self, crashlogs_dir):
1469 """Grab prior logs that were stashed before re-installing a host.
1470
1471 @param crashlogs_dir: Directory path where crash-logs are stored.
1472 """
1473 logging.debug('%s: Found %s, collecting them...',
1474 self._CRASHLOGS_PREFIX, client_constants.PRIOR_LOGS_DIR)
1475 try:
1476 self.collect_logs(client_constants.PRIOR_LOGS_DIR,
1477 crashlogs_dir, False)
1478 logging.debug('%s: %s is collected',
1479 self._CRASHLOGS_PREFIX, client_constants.PRIOR_LOGS_DIR)
1480 except Exception as e:
1481 logging.error('%s: Failed to collect %s: %s',
1482 self._CRASHLOGS_PREFIX, client_constants.PRIOR_LOGS_DIR,
1483 e)
1484
1485
1486 def _collect_system_logs(self, crashlogs_dir):
1487 """Grab normal system logs from a host.
1488
1489 @param crashlogs_dir: Directory path where crash-logs are stored.
1490 """
1491 logging.debug('%s: Found %s, collecting system logs...',
1492 self._CRASHLOGS_PREFIX, self._LAB_MACHINE_FILE)
1493 sources = server_utils.parse_simple_config(self._LOGS_TO_COLLECT_FILE)
1494 for src in sources:
1495 try:
1496 if self.path_exists(src):
1497 logging.debug('%s: Collecting %s...',
1498 self._CRASHLOGS_PREFIX, src)
1499 dest = server_utils.concat_path_except_last(
1500 crashlogs_dir, src)
1501 self.collect_logs(src, dest, False)
1502 logging.debug('%s: %s is collected',
1503 self._CRASHLOGS_PREFIX, src)
1504 except Exception as e:
1505 logging.error('%s: Failed to collect %s: %s',
1506 self._CRASHLOGS_PREFIX, src, e)
1507
1508
J. Richard Barnette1d78b012012-05-15 13:56:30 -07001509 def close(self):
Fang Deng0ca40e22013-08-27 17:47:44 -07001510 super(CrosHost, self).close()
J. Richard Barnette1d78b012012-05-15 13:56:30 -07001511
1512
Dan Shi49ca0932014-11-14 11:22:27 -08001513 def get_power_supply_info(self):
1514 """Get the output of power_supply_info.
1515
1516 power_supply_info outputs the info of each power supply, e.g.,
1517 Device: Line Power
1518 online: no
1519 type: Mains
1520 voltage (V): 0
1521 current (A): 0
1522 Device: Battery
1523 state: Discharging
1524 percentage: 95.9276
1525 technology: Li-ion
1526
1527 Above output shows two devices, Line Power and Battery, with details of
1528 each device listed. This function parses the output into a dictionary,
1529 with key being the device name, and value being a dictionary of details
1530 of the device info.
1531
1532 @return: The dictionary of power_supply_info, e.g.,
1533 {'Line Power': {'online': 'yes', 'type': 'main'},
1534 'Battery': {'vendor': 'xyz', 'percentage': '100'}}
Dan Shie9b765d2014-12-29 16:59:49 -08001535 @raise error.AutoservRunError if power_supply_info tool is not found in
1536 the DUT. Caller should handle this error to avoid false failure
1537 on verification.
Dan Shi49ca0932014-11-14 11:22:27 -08001538 """
1539 result = self.run('power_supply_info').stdout.strip()
1540 info = {}
1541 device_name = None
1542 device_info = {}
1543 for line in result.split('\n'):
1544 pair = [v.strip() for v in line.split(':')]
1545 if len(pair) != 2:
1546 continue
1547 if pair[0] == 'Device':
1548 if device_name:
1549 info[device_name] = device_info
1550 device_name = pair[1]
1551 device_info = {}
1552 else:
1553 device_info[pair[0]] = pair[1]
1554 if device_name and not device_name in info:
1555 info[device_name] = device_info
1556 return info
1557
1558
1559 def get_battery_percentage(self):
1560 """Get the battery percentage.
1561
1562 @return: The percentage of battery level, value range from 0-100. Return
1563 None if the battery info cannot be retrieved.
1564 """
1565 try:
1566 info = self.get_power_supply_info()
1567 logging.info(info)
1568 return float(info['Battery']['percentage'])
Dan Shie9b765d2014-12-29 16:59:49 -08001569 except (KeyError, ValueError, error.AutoservRunError):
Dan Shi49ca0932014-11-14 11:22:27 -08001570 return None
1571
1572
1573 def is_ac_connected(self):
1574 """Check if the dut has power adapter connected and charging.
1575
1576 @return: True if power adapter is connected and charging.
1577 """
1578 try:
1579 info = self.get_power_supply_info()
1580 return info['Line Power']['online'] == 'yes'
Dan Shie9b765d2014-12-29 16:59:49 -08001581 except (KeyError, error.AutoservRunError):
1582 return None
Dan Shi49ca0932014-11-14 11:22:27 -08001583
1584
Simran Basi5e6339a2013-03-21 11:34:32 -07001585 def _cleanup_poweron(self):
1586 """Special cleanup method to make sure hosts always get power back."""
1587 afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
1588 hosts = afe.get_hosts(hostname=self.hostname)
1589 if not hosts or not (self._RPM_OUTLET_CHANGED in
1590 hosts[0].attributes):
1591 return
1592 logging.debug('This host has recently interacted with the RPM'
1593 ' Infrastructure. Ensuring power is on.')
1594 try:
1595 self.power_on()
Dan Shi7dca56e2014-11-11 17:07:56 -08001596 afe.set_host_attribute(self._RPM_OUTLET_CHANGED, None,
1597 hostname=self.hostname)
Simran Basi5e6339a2013-03-21 11:34:32 -07001598 except rpm_client.RemotePowerException:
Simran Basi5e6339a2013-03-21 11:34:32 -07001599 logging.error('Failed to turn Power On for this host after '
1600 'cleanup through the RPM Infrastructure.')
Gabe Blackb72f4fb2015-01-20 16:47:13 -08001601 autotest_es.post(
Dan Shi7dca56e2014-11-11 17:07:56 -08001602 type_str='RPM_poweron_failure',
1603 metadata={'hostname': self.hostname})
Dan Shi49ca0932014-11-14 11:22:27 -08001604
1605 battery_percentage = self.get_battery_percentage()
Dan Shif01ebe22014-12-05 13:10:57 -08001606 if battery_percentage and battery_percentage < 50:
Dan Shi49ca0932014-11-14 11:22:27 -08001607 raise
1608 elif self.is_ac_connected():
1609 logging.info('The device has power adapter connected and '
1610 'charging. No need to try to turn RPM on '
1611 'again.')
1612 afe.set_host_attribute(self._RPM_OUTLET_CHANGED, None,
1613 hostname=self.hostname)
1614 logging.info('Battery level is now at %s%%. The device may '
1615 'still have enough power to run test, so no '
1616 'exception will be raised.', battery_percentage)
1617
Simran Basi5e6339a2013-03-21 11:34:32 -07001618
beepsc87ff602013-07-31 21:53:00 -07001619 def _is_factory_image(self):
1620 """Checks if the image on the DUT is a factory image.
1621
1622 @return: True if the image on the DUT is a factory image.
1623 False otherwise.
1624 """
1625 result = self.run('[ -f /root/.factory_test ]', ignore_status=True)
1626 return result.exit_status == 0
1627
1628
1629 def _restart_ui(self):
J. Richard Barnette84890bd2014-02-21 11:05:47 -08001630 """Restart the Chrome UI.
beepsc87ff602013-07-31 21:53:00 -07001631
1632 @raises: FactoryImageCheckerException for factory images, since
1633 we cannot attempt to restart ui on them.
1634 error.AutoservRunError for any other type of error that
1635 occurs while restarting ui.
1636 """
1637 if self._is_factory_image():
Dan Shi549fb822015-03-24 18:01:11 -07001638 raise FactoryImageCheckerException('Cannot restart ui on factory '
1639 'images')
beepsc87ff602013-07-31 21:53:00 -07001640
J. Richard Barnette84890bd2014-02-21 11:05:47 -08001641 # TODO(jrbarnette): The command to stop/start the ui job
1642 # should live inside cros_ui, too. However that would seem
1643 # to imply interface changes to the existing start()/restart()
1644 # functions, which is a bridge too far (for now).
J. Richard Barnette6069aa12015-06-08 09:10:24 -07001645 prompt = cros_ui.get_chrome_session_ident(self)
J. Richard Barnette84890bd2014-02-21 11:05:47 -08001646 self.run('stop ui; start ui')
1647 cros_ui.wait_for_chrome_ready(prompt, self)
beepsc87ff602013-07-31 21:53:00 -07001648
1649
Dan Shi549fb822015-03-24 18:01:11 -07001650 def get_release_version(self):
1651 """Get the value of attribute CHROMEOS_RELEASE_VERSION from lsb-release.
1652
1653 @returns The version string in lsb-release, under attribute
1654 CHROMEOS_RELEASE_VERSION.
1655 """
1656 lsb_release_content = self.run(
1657 'cat "%s"' % client_constants.LSB_RELEASE).stdout.strip()
1658 return lsbrelease_utils.get_chromeos_release_version(
1659 lsb_release_content=lsb_release_content)
1660
1661
1662 def verify_cros_version_label(self):
1663 """ Make sure host's cros-version label match the actual image in dut.
1664
1665 Remove any cros-version: label that doesn't match that installed in
1666 the dut.
1667
1668 @param raise_error: Set to True to raise exception if any mismatch found
1669
1670 @raise error.AutoservError: If any mismatch between cros-version label
1671 and the build installed in dut is found.
1672 """
1673 labels = self._AFE.get_labels(
1674 name__startswith=ds_constants.VERSION_PREFIX,
1675 host__hostname=self.hostname)
1676 mismatch_found = False
1677 if labels:
1678 # Get CHROMEOS_RELEASE_VERSION from lsb-release, e.g., 6908.0.0.
1679 # Note that it's different from cros-version label, which has
1680 # builder and branch info, e.g.,
1681 # cros-version:peppy-release/R43-6908.0.0
1682 release_version = self.get_release_version()
1683 host_list = [self.hostname]
1684 for label in labels:
1685 # Remove any cros-version label that does not match
1686 # release_version.
1687 build_version = label.name[len(ds_constants.VERSION_PREFIX):]
1688 if not utils.version_match(build_version, release_version):
1689 logging.warn('cros-version label "%s" does not match '
1690 'release version %s. Removing the label.',
1691 label.name, release_version)
1692 label.remove_hosts(hosts=host_list)
1693 mismatch_found = True
1694 if mismatch_found:
Dan Shi1057bae2015-03-30 11:35:09 -07001695 autotest_es.post(use_http=True,
1696 type_str='cros_version_label_mismatch',
1697 metadata={'hostname': self.hostname})
Dan Shi549fb822015-03-24 18:01:11 -07001698 raise error.AutoservError('The host has wrong cros-version label.')
1699
1700
Darren Krahn0bd18e82015-10-28 23:30:46 +00001701 def verify_tpm_status(self):
1702 """ Verify the host's TPM is in a good state.
1703
1704 @raise error.AutoservError: If state is not good.
1705 """
1706 # This cryptohome command emits status information in JSON format. It
1707 # looks something like this:
1708 # {
1709 # "installattrs": {
1710 # "first_install": false,
1711 # "initialized": true,
1712 # "invalid": false,
1713 # "lockbox_index": 536870916,
1714 # "lockbox_nvram_version": 2,
1715 # "secure": true,
1716 # "size": 0,
1717 # "version": 1
1718 # },
1719 # "mounts": [ {
1720 # "enterprise": false,
1721 # "keysets": [ {
1722 # "current": true,
1723 # "index": 0,
1724 # "last_activity": 1330111359,
1725 # "ok": true,
1726 # "scrypt": true,
1727 # "tpm": false
1728 # } ],
1729 # "mounted": true,
1730 # "owner": "dbb3dd34edb181245130e136be51fa08478d3909"
1731 # } ],
1732 # "tpm": {
1733 # "being_owned": false,
1734 # "can_connect": true,
1735 # "can_decrypt": false,
1736 # "can_encrypt": false,
1737 # "can_load_srk": true,
1738 # "can_load_srk_pubkey": true,
1739 # "enabled": true,
1740 # "has_context": true,
1741 # "has_cryptohome_key": false,
1742 # "has_key_handle": false,
1743 # "last_error": 0,
1744 # "owned": true
1745 # }
1746 # }
1747 output = self.run('cryptohome --action=status').stdout.strip()
1748 try:
1749 status = json.loads(output)
1750 except ValueError:
1751 logging.error('TPM_VERIFY: Cryptohome did not return valid status.')
1752 return
1753 try:
1754 tpm = status['tpm']
1755 if (not tpm['enabled'] or not tpm['can_connect'] or
1756 (tpm['owned'] and not tpm['can_load_srk']) or
1757 (tpm['can_load_srk'] and not tpm['can_load_srk_pubkey'])):
1758 logging.error('TPM_VERIFY: The host TPM is in a bad state.')
1759 raise error.AutoservError('The host TPM is in a bad state.')
1760 else:
1761 logging.debug('TPM_VERIFY: The host TPM is in a good state.')
1762 except KeyError:
1763 logging.error('TPM_VERIFY: Cryptohome did not return valid status.')
1764
1765
beepsc87ff602013-07-31 21:53:00 -07001766 def cleanup(self):
MK Ryu35d661e2014-09-25 17:44:10 -07001767 self.run('rm -f %s' % client_constants.CLEANUP_LOGS_PAUSED_FILE)
Scott Zawalskiddbc31e2012-11-15 11:29:01 -05001768 try:
beepsc87ff602013-07-31 21:53:00 -07001769 self._restart_ui()
1770 except (error.AutotestRunError, error.AutoservRunError,
1771 FactoryImageCheckerException):
Ilja H. Friedel04be2bd2014-05-07 21:29:59 -07001772 logging.warning('Unable to restart ui, rebooting device.')
Scott Zawalskiddbc31e2012-11-15 11:29:01 -05001773 # Since restarting the UI fails fall back to normal Autotest
1774 # cleanup routines, i.e. reboot the machine.
Fang Deng0ca40e22013-08-27 17:47:44 -07001775 super(CrosHost, self).cleanup()
Simran Basi5e6339a2013-03-21 11:34:32 -07001776 # Check if the rpm outlet was manipulated.
Simran Basid5e5e272012-09-24 15:23:59 -07001777 if self.has_power():
Simran Basi5e6339a2013-03-21 11:34:32 -07001778 self._cleanup_poweron()
Dan Shi549fb822015-03-24 18:01:11 -07001779 self.verify_cros_version_label()
J. Richard Barnette45e93de2012-04-11 17:24:15 -07001780
1781
Yu-Ju Honga2be94a2012-07-31 09:48:52 -07001782 def reboot(self, **dargs):
1783 """
1784 This function reboots the site host. The more generic
1785 RemoteHost.reboot() performs sync and sleeps for 5
1786 seconds. This is not necessary for Chrome OS devices as the
1787 sync should be finished in a short time during the reboot
1788 command.
1789 """
Tom Wai-Hong Tamf5cd1d42012-08-13 12:04:08 +08001790 if 'reboot_cmd' not in dargs:
Doug Anderson7d5aeb22014-02-27 15:12:17 -08001791 reboot_timeout = dargs.get('reboot_timeout', 10)
J. Richard Barnette9af19632015-09-25 12:18:03 -07001792 dargs['reboot_cmd'] = ('sleep 1; '
1793 'reboot & sleep %d; '
1794 'reboot -f' % reboot_timeout)
Yu-Ju Honga2be94a2012-07-31 09:48:52 -07001795 # Enable fastsync to avoid running extra sync commands before reboot.
Tom Wai-Hong Tamf5cd1d42012-08-13 12:04:08 +08001796 if 'fastsync' not in dargs:
1797 dargs['fastsync'] = True
Michael Liangda8c60a2014-06-03 13:24:51 -07001798
Charlie Mooneya8e6dab2014-05-29 14:37:55 -07001799 # For purposes of logging reboot times:
1800 # Get the board name i.e. 'daisy_spring'
Michael Liangca4f5a62014-07-10 15:45:13 -07001801 board_fullname = self.get_board()
1802
1803 # Strip the prefix and add it to dargs.
1804 dargs['board'] = board_fullname[board_fullname.find(':')+1:]
Fang Deng0ca40e22013-08-27 17:47:44 -07001805 super(CrosHost, self).reboot(**dargs)
Yu-Ju Honga2be94a2012-07-31 09:48:52 -07001806
1807
Gwendal Grignou7a61d2f2014-05-23 11:05:51 -07001808 def suspend(self, **dargs):
1809 """
1810 This function suspends the site host.
1811 """
1812 suspend_time = dargs.get('suspend_time', 60)
1813 dargs['timeout'] = suspend_time
1814 if 'suspend_cmd' not in dargs:
J. Richard Barnette9af19632015-09-25 12:18:03 -07001815 dargs['suspend_cmd'] = ' && '.join([
1816 'echo 0 > /sys/class/rtc/rtc0/wakealarm',
Gwendal Grignou7a61d2f2014-05-23 11:05:51 -07001817 'echo +%d > /sys/class/rtc/rtc0/wakealarm' % suspend_time,
J. Richard Barnette9af19632015-09-25 12:18:03 -07001818 'powerd_dbus_suspend --delay=0'])
Gwendal Grignou7a61d2f2014-05-23 11:05:51 -07001819 super(CrosHost, self).suspend(**dargs)
1820
1821
Simran Basiec564392014-08-25 16:48:09 -07001822 def upstart_status(self, service_name):
1823 """Check the status of an upstart init script.
1824
1825 @param service_name: Service to look up.
1826
1827 @returns True if the service is running, False otherwise.
1828 """
1829 return self.run('status %s | grep start/running' %
1830 service_name).stdout.strip() != ''
1831
1832
J. Richard Barnette45e93de2012-04-11 17:24:15 -07001833 def verify_software(self):
Richard Barnetteb2bc13c2013-01-08 17:32:51 -08001834 """Verify working software on a Chrome OS system.
J. Richard Barnette45e93de2012-04-11 17:24:15 -07001835
Richard Barnetteb2bc13c2013-01-08 17:32:51 -08001836 Tests for the following conditions:
1837 1. All conditions tested by the parent version of this
1838 function.
1839 2. Sufficient space in /mnt/stateful_partition.
Fang Deng6b05f5b2013-03-20 13:42:11 -07001840 3. Sufficient space in /mnt/stateful_partition/encrypted.
1841 4. update_engine answers a simple status request over DBus.
J. Richard Barnette45e93de2012-04-11 17:24:15 -07001842
J. Richard Barnette45e93de2012-04-11 17:24:15 -07001843 """
MK Ryu35d661e2014-09-25 17:44:10 -07001844 # Check if a job was crashed on this host.
1845 # If yes, avoid verification until crash-logs are collected.
1846 if self._need_crash_logs():
1847 raise error.AutoservCrashLogCollectRequired(
1848 'Need to collect crash-logs before verification')
1849
Fang Deng0ca40e22013-08-27 17:47:44 -07001850 super(CrosHost, self).verify_software()
Dan Shib8540a52015-07-16 14:18:23 -07001851 default_kilo_inodes_required = CONFIG.get_config_value(
1852 'SERVER', 'kilo_inodes_required', type=int, default=100)
1853 board = self.get_board().replace(ds_constants.BOARD_PREFIX, '')
1854 kilo_inodes_required = CONFIG.get_config_value(
1855 'SERVER', 'kilo_inodes_required_%s' % board,
1856 type=int, default=default_kilo_inodes_required)
1857 self.check_inodes('/mnt/stateful_partition', kilo_inodes_required)
J. Richard Barnette45e93de2012-04-11 17:24:15 -07001858 self.check_diskspace(
1859 '/mnt/stateful_partition',
Dan Shib8540a52015-07-16 14:18:23 -07001860 CONFIG.get_config_value(
Fang Deng6b05f5b2013-03-20 13:42:11 -07001861 'SERVER', 'gb_diskspace_required', type=float,
1862 default=20.0))
Gaurav Shahe448af82014-06-19 15:18:59 -07001863 encrypted_stateful_path = '/mnt/stateful_partition/encrypted'
1864 # Not all targets build with encrypted stateful support.
1865 if self.path_exists(encrypted_stateful_path):
1866 self.check_diskspace(
1867 encrypted_stateful_path,
Dan Shib8540a52015-07-16 14:18:23 -07001868 CONFIG.get_config_value(
Gaurav Shahe448af82014-06-19 15:18:59 -07001869 'SERVER', 'gb_encrypted_diskspace_required', type=float,
1870 default=0.1))
beepsc87ff602013-07-31 21:53:00 -07001871
Simran Basiec564392014-08-25 16:48:09 -07001872 if not self.upstart_status('system-services'):
Prashanth B5d0a0512014-04-25 12:26:08 -07001873 raise error.AutoservError('Chrome failed to reach login. '
1874 'System services not running.')
1875
beepsc87ff602013-07-31 21:53:00 -07001876 # Factory images don't run update engine,
1877 # goofy controls dbus on these DUTs.
1878 if not self._is_factory_image():
1879 self.run('update_engine_client --status')
Scott Zawalskifbca4a92013-03-04 15:56:42 -05001880 # Makes sure python is present, loads and can use built in functions.
1881 # We have seen cases where importing cPickle fails with undefined
1882 # symbols in cPickle.so.
1883 self.run('python -c "import cPickle"')
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07001884
Dan Shi549fb822015-03-24 18:01:11 -07001885 self.verify_cros_version_label()
1886
Darren Krahn0bd18e82015-10-28 23:30:46 +00001887 self.verify_tpm_status()
1888
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07001889
Dan Shi49ca0932014-11-14 11:22:27 -08001890 def verify_hardware(self):
1891 """Verify hardware system of a Chrome OS system.
1892
1893 Check following hardware conditions:
1894 1. Battery level.
1895 2. Is power adapter connected.
1896 """
1897 logging.info('Battery percentage: %s', self.get_battery_percentage())
Dan Shie9b765d2014-12-29 16:59:49 -08001898 if self.is_ac_connected() is None:
1899 logging.info('Can not determine if the device has power adapter '
1900 'connected.')
1901 else:
1902 logging.info('Device %s power adapter connected and charging.',
1903 'has' if self.is_ac_connected() else 'does not have')
Dan Shi49ca0932014-11-14 11:22:27 -08001904
1905
Fang Deng96667ca2013-08-01 17:46:18 -07001906 def make_ssh_command(self, user='root', port=22, opts='', hosts_file=None,
1907 connect_timeout=None, alive_interval=None):
1908 """Override default make_ssh_command to use options tuned for Chrome OS.
1909
1910 Tuning changes:
1911 - ConnectTimeout=30; maximum of 30 seconds allowed for an SSH
1912 connection failure. Consistency with remote_access.sh.
1913
Samuel Tan2ce155b2015-06-23 18:24:38 -07001914 - ServerAliveInterval=900; which causes SSH to ping connection every
1915 900 seconds. In conjunction with ServerAliveCountMax ensures
1916 that if the connection dies, Autotest will bail out.
Fang Deng96667ca2013-08-01 17:46:18 -07001917 Originally tried 60 secs, but saw frequent job ABORTS where
Samuel Tan2ce155b2015-06-23 18:24:38 -07001918 the test completed successfully. Later increased from 180 seconds to
1919 900 seconds to account for tests where the DUT is suspended for
1920 longer periods of time.
Fang Deng96667ca2013-08-01 17:46:18 -07001921
1922 - ServerAliveCountMax=3; consistency with remote_access.sh.
1923
1924 - ConnectAttempts=4; reduce flakiness in connection errors;
1925 consistency with remote_access.sh.
1926
1927 - UserKnownHostsFile=/dev/null; we don't care about the keys.
1928 Host keys change with every new installation, don't waste
1929 memory/space saving them.
1930
1931 - SSH protocol forced to 2; needed for ServerAliveInterval.
1932
1933 @param user User name to use for the ssh connection.
1934 @param port Port on the target host to use for ssh connection.
1935 @param opts Additional options to the ssh command.
1936 @param hosts_file Ignored.
1937 @param connect_timeout Ignored.
1938 @param alive_interval Ignored.
1939 """
Aviv Keshetc5947fa2013-09-04 14:06:29 -07001940 base_command = ('/usr/bin/ssh -a -x %s %s %s'
1941 ' -o StrictHostKeyChecking=no'
Fang Deng96667ca2013-08-01 17:46:18 -07001942 ' -o UserKnownHostsFile=/dev/null -o BatchMode=yes'
Samuel Tan2ce155b2015-06-23 18:24:38 -07001943 ' -o ConnectTimeout=30 -o ServerAliveInterval=900'
Fang Deng96667ca2013-08-01 17:46:18 -07001944 ' -o ServerAliveCountMax=3 -o ConnectionAttempts=4'
1945 ' -o Protocol=2 -l %s -p %d')
Aviv Keshetc5947fa2013-09-04 14:06:29 -07001946 return base_command % (self._ssh_verbosity_flag, self._ssh_options,
1947 opts, user, port)
Jason Abeleb6f924f2013-11-13 16:01:54 -08001948 def syslog(self, message, tag='autotest'):
1949 """Logs a message to syslog on host.
1950
1951 @param message String message to log into syslog
1952 @param tag String tag prefix for syslog
1953
1954 """
1955 self.run('logger -t "%s" "%s"' % (tag, message))
1956
1957
J. Richard Barnetteb6de7e32013-02-14 13:28:04 -08001958 def _ping_check_status(self, status):
1959 """Ping the host once, and return whether it has a given status.
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07001960
J. Richard Barnetteb6de7e32013-02-14 13:28:04 -08001961 @param status Check the ping status against this value.
1962 @return True iff `status` and the result of ping are the same
1963 (i.e. both True or both False).
1964
1965 """
1966 ping_val = utils.ping(self.hostname, tries=1, deadline=1)
1967 return not (status ^ (ping_val == 0))
1968
1969 def _ping_wait_for_status(self, status, timeout):
1970 """Wait for the host to have a given status (UP or DOWN).
1971
1972 Status is checked by polling. Polling will not last longer
1973 than the number of seconds in `timeout`. The polling
1974 interval will be long enough that only approximately
1975 _PING_WAIT_COUNT polling cycles will be executed, subject
1976 to a maximum interval of about one minute.
1977
1978 @param status Waiting will stop immediately if `ping` of the
1979 host returns this status.
1980 @param timeout Poll for at most this many seconds.
1981 @return True iff the host status from `ping` matched the
1982 requested status at the time of return.
1983
1984 """
1985 # _ping_check_status() takes about 1 second, hence the
1986 # "- 1" in the formula below.
1987 poll_interval = min(int(timeout / self._PING_WAIT_COUNT), 60) - 1
1988 end_time = time.time() + timeout
1989 while time.time() <= end_time:
1990 if self._ping_check_status(status):
1991 return True
1992 if poll_interval > 0:
1993 time.sleep(poll_interval)
1994
1995 # The last thing we did was sleep(poll_interval), so it may
1996 # have been too long since the last `ping`. Check one more
1997 # time, just to be sure.
1998 return self._ping_check_status(status)
1999
2000 def ping_wait_up(self, timeout):
2001 """Wait for the host to respond to `ping`.
2002
2003 N.B. This method is not a reliable substitute for
2004 `wait_up()`, because a host that responds to ping will not
2005 necessarily respond to ssh. This method should only be used
2006 if the target DUT can be considered functional even if it
2007 can't be reached via ssh.
2008
2009 @param timeout Minimum time to allow before declaring the
2010 host to be non-responsive.
2011 @return True iff the host answered to ping before the timeout.
2012
2013 """
2014 return self._ping_wait_for_status(self._PING_STATUS_UP, timeout)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002015
Andrew Bresticker678c0c72013-01-22 10:44:09 -08002016 def ping_wait_down(self, timeout):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002017 """Wait until the host no longer responds to `ping`.
2018
J. Richard Barnetteb6de7e32013-02-14 13:28:04 -08002019 This function can be used as a slightly faster version of
2020 `wait_down()`, by avoiding potentially long ssh timeouts.
2021
2022 @param timeout Minimum time to allow for the host to become
2023 non-responsive.
2024 @return True iff the host quit answering ping before the
2025 timeout.
2026
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002027 """
J. Richard Barnetteb6de7e32013-02-14 13:28:04 -08002028 return self._ping_wait_for_status(self._PING_STATUS_DOWN, timeout)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002029
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002030 def test_wait_for_sleep(self, sleep_timeout=None):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002031 """Wait for the client to enter low-power sleep mode.
2032
2033 The test for "is asleep" can't distinguish a system that is
2034 powered off; to confirm that the unit was asleep, it is
2035 necessary to force resume, and then call
2036 `test_wait_for_resume()`.
2037
2038 This function is expected to be called from a test as part
2039 of a sequence like the following:
2040
2041 ~~~~~~~~
2042 boot_id = host.get_boot_id()
2043 # trigger sleep on the host
2044 host.test_wait_for_sleep()
2045 # trigger resume on the host
2046 host.test_wait_for_resume(boot_id)
2047 ~~~~~~~~
2048
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002049 @param sleep_timeout time limit in seconds to allow the host sleep.
2050
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002051 @exception TestFail The host did not go to sleep within
2052 the allowed time.
2053 """
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002054 if sleep_timeout is None:
2055 sleep_timeout = self.SLEEP_TIMEOUT
2056
2057 if not self.ping_wait_down(timeout=sleep_timeout):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002058 raise error.TestFail(
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002059 'client failed to sleep after %d seconds' % sleep_timeout)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002060
2061
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002062 def test_wait_for_resume(self, old_boot_id, resume_timeout=None):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002063 """Wait for the client to resume from low-power sleep mode.
2064
2065 The `old_boot_id` parameter should be the value from
2066 `get_boot_id()` obtained prior to entering sleep mode. A
2067 `TestFail` exception is raised if the boot id changes.
2068
2069 See @ref test_wait_for_sleep for more on this function's
2070 usage.
2071
J. Richard Barnette7214e0b2013-02-06 15:20:49 -08002072 @param old_boot_id A boot id value obtained before the
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002073 target host went to sleep.
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002074 @param resume_timeout time limit in seconds to allow the host up.
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002075
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 a reboot rather than a sleep
2080 cycle.
2081 """
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002082 if resume_timeout is None:
2083 resume_timeout = self.RESUME_TIMEOUT
2084
2085 if not self.wait_up(timeout=resume_timeout):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002086 raise error.TestFail(
2087 'client failed to resume from sleep after %d seconds' %
Tom Wai-Hong Tamfced4f62014-04-17 10:56:30 +08002088 resume_timeout)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002089 else:
2090 new_boot_id = self.get_boot_id()
2091 if new_boot_id != old_boot_id:
Tom Wai-Hong Tam01792682015-01-06 08:00:46 +08002092 logging.error('client rebooted (old boot %s, new boot %s)',
2093 old_boot_id, new_boot_id)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002094 raise error.TestFail(
Tom Wai-Hong Tam01792682015-01-06 08:00:46 +08002095 'client rebooted, but sleep was expected')
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002096
2097
Tom Wai-Hong Tamfe005c22014-12-03 09:25:44 +08002098 def test_wait_for_shutdown(self, shutdown_timeout=None):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002099 """Wait for the client to shut down.
2100
2101 The test for "has shut down" can't distinguish a system that
2102 is merely asleep; to confirm that the unit was down, it is
2103 necessary to force boot, and then call test_wait_for_boot().
2104
2105 This function is expected to be called from a test as part
2106 of a sequence like the following:
2107
2108 ~~~~~~~~
2109 boot_id = host.get_boot_id()
2110 # trigger shutdown on the host
2111 host.test_wait_for_shutdown()
2112 # trigger boot on the host
2113 host.test_wait_for_boot(boot_id)
2114 ~~~~~~~~
2115
Tom Wai-Hong Tamfe005c22014-12-03 09:25:44 +08002116 @param shutdown_timeout time limit in seconds to allow the host down.
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002117 @exception TestFail The host did not shut down within the
2118 allowed time.
2119 """
Tom Wai-Hong Tamfe005c22014-12-03 09:25:44 +08002120 if shutdown_timeout is None:
2121 shutdown_timeout = self.SHUTDOWN_TIMEOUT
2122
2123 if not self.ping_wait_down(timeout=shutdown_timeout):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002124 raise error.TestFail(
2125 'client failed to shut down after %d seconds' %
Tom Wai-Hong Tamfe005c22014-12-03 09:25:44 +08002126 shutdown_timeout)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002127
2128
2129 def test_wait_for_boot(self, old_boot_id=None):
2130 """Wait for the client to boot from cold power.
2131
2132 The `old_boot_id` parameter should be the value from
2133 `get_boot_id()` obtained prior to shutting down. A
2134 `TestFail` exception is raised if the boot id does not
2135 change. The boot id test is omitted if `old_boot_id` is not
2136 specified.
2137
2138 See @ref test_wait_for_shutdown for more on this function's
2139 usage.
2140
J. Richard Barnette7214e0b2013-02-06 15:20:49 -08002141 @param old_boot_id A boot id value obtained before the
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002142 shut down.
2143
2144 @exception TestFail The host did not respond within the
2145 allowed time.
2146 @exception TestFail The host responded, but the boot id test
2147 indicated that there was no reboot.
2148 """
J. Richard Barnetteeb69d722012-06-18 17:29:44 -07002149 if not self.wait_up(timeout=self.REBOOT_TIMEOUT):
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002150 raise error.TestFail(
2151 'client failed to reboot after %d seconds' %
J. Richard Barnetteeb69d722012-06-18 17:29:44 -07002152 self.REBOOT_TIMEOUT)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002153 elif old_boot_id:
2154 if self.get_boot_id() == old_boot_id:
Tom Wai-Hong Tam01792682015-01-06 08:00:46 +08002155 logging.error('client not rebooted (boot %s)',
2156 old_boot_id)
J. Richard Barnette134ec2c2012-04-25 12:59:37 -07002157 raise error.TestFail(
Tom Wai-Hong Tam01792682015-01-06 08:00:46 +08002158 'client is back up, but did not reboot')
Simran Basid5e5e272012-09-24 15:23:59 -07002159
2160
2161 @staticmethod
2162 def check_for_rpm_support(hostname):
2163 """For a given hostname, return whether or not it is powered by an RPM.
2164
Simran Basi1df55112013-09-06 11:25:09 -07002165 @param hostname: hostname to check for rpm support.
2166
Simran Basid5e5e272012-09-24 15:23:59 -07002167 @return None if this host does not follows the defined naming format
2168 for RPM powered DUT's in the lab. If it does follow the format,
2169 it returns a regular expression MatchObject instead.
2170 """
Fang Dengbaff9082015-01-06 13:46:15 -08002171 return re.match(CrosHost._RPM_HOSTNAME_REGEX, hostname)
Simran Basid5e5e272012-09-24 15:23:59 -07002172
2173
2174 def has_power(self):
2175 """For this host, return whether or not it is powered by an RPM.
2176
2177 @return True if this host is in the CROS lab and follows the defined
2178 naming format.
2179 """
Fang Deng0ca40e22013-08-27 17:47:44 -07002180 return CrosHost.check_for_rpm_support(self.hostname)
Simran Basid5e5e272012-09-24 15:23:59 -07002181
2182
Ismail Noorbasha07fdb612013-02-14 14:13:31 -08002183 def _set_power(self, state, power_method):
2184 """Sets the power to the host via RPM, Servo or manual.
2185
2186 @param state Specifies which power state to set to DUT
2187 @param power_method Specifies which method of power control to
2188 use. By default "RPM" will be used. Valid values
2189 are the strings "RPM", "manual", "servoj10".
2190
2191 """
2192 ACCEPTABLE_STATES = ['ON', 'OFF']
2193
2194 if state.upper() not in ACCEPTABLE_STATES:
2195 raise error.TestError('State must be one of: %s.'
2196 % (ACCEPTABLE_STATES,))
2197
2198 if power_method == self.POWER_CONTROL_SERVO:
2199 logging.info('Setting servo port J10 to %s', state)
2200 self.servo.set('prtctl3_pwren', state.lower())
2201 time.sleep(self._USB_POWER_TIMEOUT)
2202 elif power_method == self.POWER_CONTROL_MANUAL:
2203 logging.info('You have %d seconds to set the AC power to %s.',
2204 self._POWER_CYCLE_TIMEOUT, state)
2205 time.sleep(self._POWER_CYCLE_TIMEOUT)
2206 else:
2207 if not self.has_power():
2208 raise error.TestFail('DUT does not have RPM connected.')
Simran Basi5e6339a2013-03-21 11:34:32 -07002209 afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
2210 afe.set_host_attribute(self._RPM_OUTLET_CHANGED, True,
2211 hostname=self.hostname)
Simran Basi1df55112013-09-06 11:25:09 -07002212 rpm_client.set_power(self.hostname, state.upper(), timeout_mins=5)
Simran Basid5e5e272012-09-24 15:23:59 -07002213
2214
Ismail Noorbasha07fdb612013-02-14 14:13:31 -08002215 def power_off(self, power_method=POWER_CONTROL_RPM):
2216 """Turn off power to this host via RPM, Servo or manual.
2217
2218 @param power_method Specifies which method of power control to
2219 use. By default "RPM" will be used. Valid values
2220 are the strings "RPM", "manual", "servoj10".
2221
2222 """
2223 self._set_power('OFF', power_method)
Simran Basid5e5e272012-09-24 15:23:59 -07002224
2225
Ismail Noorbasha07fdb612013-02-14 14:13:31 -08002226 def power_on(self, power_method=POWER_CONTROL_RPM):
2227 """Turn on power to this host via RPM, Servo or manual.
2228
2229 @param power_method Specifies which method of power control to
2230 use. By default "RPM" will be used. Valid values
2231 are the strings "RPM", "manual", "servoj10".
2232
2233 """
2234 self._set_power('ON', power_method)
2235
2236
2237 def power_cycle(self, power_method=POWER_CONTROL_RPM):
2238 """Cycle power to this host by turning it OFF, then ON.
2239
2240 @param power_method Specifies which method of power control to
2241 use. By default "RPM" will be used. Valid values
2242 are the strings "RPM", "manual", "servoj10".
2243
2244 """
2245 if power_method in (self.POWER_CONTROL_SERVO,
2246 self.POWER_CONTROL_MANUAL):
2247 self.power_off(power_method=power_method)
2248 time.sleep(self._POWER_CYCLE_TIMEOUT)
2249 self.power_on(power_method=power_method)
2250 else:
2251 rpm_client.set_power(self.hostname, 'CYCLE')
Simran Basic6f1f7a2012-10-16 10:47:46 -07002252
2253
2254 def get_platform(self):
2255 """Determine the correct platform label for this host.
2256
2257 @returns a string representing this host's platform.
2258 """
2259 crossystem = utils.Crossystem(self)
2260 crossystem.init()
2261 # Extract fwid value and use the leading part as the platform id.
2262 # fwid generally follow the format of {platform}.{firmware version}
2263 # Example: Alex.X.YYY.Z or Google_Alex.X.YYY.Z
2264 platform = crossystem.fwid().split('.')[0].lower()
2265 # Newer platforms start with 'Google_' while the older ones do not.
2266 return platform.replace('google_', '')
2267
2268
Hung-ying Tyanb1328032014-04-01 14:18:54 +08002269 def get_architecture(self):
2270 """Determine the correct architecture label for this host.
2271
2272 @returns a string representing this host's architecture.
2273 """
2274 crossystem = utils.Crossystem(self)
2275 crossystem.init()
2276 return crossystem.arch()
2277
2278
Luis Lozano40b7d0d2014-01-17 15:12:06 -08002279 def get_chrome_version(self):
2280 """Gets the Chrome version number and milestone as strings.
2281
2282 Invokes "chrome --version" to get the version number and milestone.
2283
2284 @return A tuple (chrome_ver, milestone) where "chrome_ver" is the
2285 current Chrome version number as a string (in the form "W.X.Y.Z")
2286 and "milestone" is the first component of the version number
2287 (the "W" from "W.X.Y.Z"). If the version number cannot be parsed
2288 in the "W.X.Y.Z" format, the "chrome_ver" will be the full output
2289 of "chrome --version" and the milestone will be the empty string.
2290
2291 """
MK Ryu35d661e2014-09-25 17:44:10 -07002292 version_string = self.run(client_constants.CHROME_VERSION_COMMAND).stdout
Luis Lozano40b7d0d2014-01-17 15:12:06 -08002293 return utils.parse_chrome_version(version_string)
2294
Aviv Keshet74c89a92013-02-04 15:18:30 -08002295 @label_decorator()
Simran Basic6f1f7a2012-10-16 10:47:46 -07002296 def get_board(self):
2297 """Determine the correct board label for this host.
2298
2299 @returns a string representing this host's board.
2300 """
2301 release_info = utils.parse_cmd_output('cat /etc/lsb-release',
2302 run_method=self.run)
2303 board = release_info['CHROMEOS_RELEASE_BOARD']
2304 # Devices in the lab generally have the correct board name but our own
2305 # development devices have {board_name}-signed-{key_type}. The board
2306 # name may also begin with 'x86-' which we need to keep.
Simran Basi833814b2013-01-29 13:13:43 -08002307 board_format_string = ds_constants.BOARD_PREFIX + '%s'
Simran Basic6f1f7a2012-10-16 10:47:46 -07002308 if 'x86' not in board:
Simran Basi833814b2013-01-29 13:13:43 -08002309 return board_format_string % board.split('-')[0]
2310 return board_format_string % '-'.join(board.split('-')[0:2])
Simran Basic6f1f7a2012-10-16 10:47:46 -07002311
2312
Aviv Keshet74c89a92013-02-04 15:18:30 -08002313 @label_decorator('lightsensor')
Simran Basic6f1f7a2012-10-16 10:47:46 -07002314 def has_lightsensor(self):
2315 """Determine the correct board label for this host.
2316
2317 @returns the string 'lightsensor' if this host has a lightsensor or
2318 None if it does not.
2319 """
2320 search_cmd = "find -L %s -maxdepth 4 | egrep '%s'" % (
Richard Barnette82c35912012-11-20 10:09:10 -08002321 self._LIGHTSENSOR_SEARCH_DIR, '|'.join(self._LIGHTSENSOR_FILES))
Simran Basic6f1f7a2012-10-16 10:47:46 -07002322 try:
2323 # Run the search cmd following the symlinks. Stderr_tee is set to
2324 # None as there can be a symlink loop, but the command will still
2325 # execute correctly with a few messages printed to stderr.
2326 self.run(search_cmd, stdout_tee=None, stderr_tee=None)
2327 return 'lightsensor'
2328 except error.AutoservRunError:
2329 # egrep exited with a return code of 1 meaning none of the possible
2330 # lightsensor files existed.
2331 return None
2332
2333
Aviv Keshet74c89a92013-02-04 15:18:30 -08002334 @label_decorator('bluetooth')
Simran Basic6f1f7a2012-10-16 10:47:46 -07002335 def has_bluetooth(self):
2336 """Determine the correct board label for this host.
2337
2338 @returns the string 'bluetooth' if this host has bluetooth or
2339 None if it does not.
2340 """
2341 try:
2342 self.run('test -d /sys/class/bluetooth/hci0')
2343 # test exited with a return code of 0.
2344 return 'bluetooth'
2345 except error.AutoservRunError:
2346 # test exited with a return code 1 meaning the directory did not
2347 # exist.
2348 return None
2349
2350
Bill Richardson4f595f52014-02-13 16:20:26 -08002351 @label_decorator('ec')
2352 def get_ec(self):
2353 """
2354 Determine the type of EC on this host.
2355
2356 @returns a string representing this host's embedded controller type.
2357 At present, it only returns "ec:cros", for Chrome OS ECs. Other types
2358 of EC (or none) don't return any strings, since no tests depend on
2359 those.
2360 """
2361 cmd = 'mosys ec info'
2362 # The output should look like these, so that the last field should
2363 # match our EC version scheme:
2364 #
2365 # stm | stm32f100 | snow_v1.3.139-375eb9f
2366 # ti | Unknown-10de | peppy_v1.5.114-5d52788
2367 #
2368 # Non-Chrome OS ECs will look like these:
2369 #
2370 # ENE | KB932 | 00BE107A00
2371 # ite | it8518 | 3.08
2372 #
2373 # And some systems don't have ECs at all (Lumpy, for example).
2374 regexp = r'^.*\|\s*(\S+_v\d+\.\d+\.\d+-[0-9a-f]+)\s*$'
2375
2376 ecinfo = self.run(command=cmd, ignore_status=True)
2377 if ecinfo.exit_status == 0:
2378 res = re.search(regexp, ecinfo.stdout)
2379 if res:
2380 logging.info("EC version is %s", res.groups()[0])
2381 return 'ec:cros'
2382 logging.info("%s got: %s", cmd, ecinfo.stdout)
2383 # Has an EC, but it's not a Chrome OS EC
2384 return None
2385 logging.info("%s exited with status %d", cmd, ecinfo.exit_status)
2386 # No EC present
2387 return None
2388
2389
Alec Berg31b932b2014-04-04 16:09:11 -07002390 @label_decorator('accels')
2391 def get_accels(self):
2392 """
2393 Determine the type of accelerometers on this host.
2394
2395 @returns a string representing this host's accelerometer type.
2396 At present, it only returns "accel:cros-ec", for accelerometers
2397 attached to a Chrome OS EC, or none, if no accelerometers.
2398 """
2399 # Check to make sure we have ectool
2400 rv = self.run('which ectool', ignore_status=True)
2401 if rv.exit_status:
2402 logging.info("No ectool cmd found, assuming no EC accelerometers")
2403 return None
2404
2405 # Check that the EC supports the motionsense command
2406 rv = self.run('ectool motionsense', ignore_status=True)
2407 if rv.exit_status:
2408 logging.info("EC does not support motionsense command "
2409 "assuming no EC accelerometers")
2410 return None
2411
2412 # Check that EC motion sensors are active
2413 active = self.run('ectool motionsense active').stdout.split('\n')
2414 if active[0] == "0":
2415 logging.info("Motion sense inactive, assuming no EC accelerometers")
2416 return None
2417
2418 logging.info("EC accelerometers found")
2419 return 'accel:cros-ec'
2420
2421
Tom Wai-Hong Tam3d6790d2014-04-14 16:15:47 +08002422 @label_decorator('chameleon')
2423 def has_chameleon(self):
2424 """Determine if a Chameleon connected to this host.
2425
Tom Wai-Hong Tambadbb332014-10-10 02:59:41 +08002426 @returns a list containing two strings ('chameleon' and
2427 'chameleon:' + label, e.g. 'chameleon:hdmi') if this host
2428 has a Chameleon or None if it has not.
Tom Wai-Hong Tam3d6790d2014-04-14 16:15:47 +08002429 """
2430 if self._chameleon_host:
Tom Wai-Hong Tambadbb332014-10-10 02:59:41 +08002431 return ['chameleon', 'chameleon:' + self.chameleon.get_label()]
Tom Wai-Hong Tam3d6790d2014-04-14 16:15:47 +08002432 else:
2433 return None
2434
2435
Cheng-Yi Chiangf4104ff2014-12-23 19:39:01 +08002436 @label_decorator('audio_loopback_dongle')
2437 def has_loopback_dongle(self):
2438 """Determine if an audio loopback dongle is plugged to this host.
2439
2440 @returns 'audio_loopback_dongle' when there is an audio loopback dongle
2441 plugged to this host.
2442 None when there is no audio loopback dongle
2443 plugged to this host.
2444 """
Cheng-Yi Chiang8de78112015-05-27 14:47:08 +08002445 nodes_info = self.run(command=cras_utils.get_cras_nodes_cmd(),
2446 ignore_status=True).stdout
2447 if (cras_utils.node_type_is_plugged('HEADPHONE', nodes_info) and
2448 cras_utils.node_type_is_plugged('MIC', nodes_info)):
Cheng-Yi Chiangf4104ff2014-12-23 19:39:01 +08002449 return 'audio_loopback_dongle'
2450 else:
2451 return None
2452
2453
Derek Basehorec71ff622014-07-07 15:18:40 -07002454 @label_decorator('power_supply')
2455 def get_power_supply(self):
2456 """
2457 Determine what type of power supply the host has
2458
2459 @returns a string representing this host's power supply.
2460 'power:battery' when the device has a battery intended for
2461 extended use
2462 'power:AC_primary' when the device has a battery not intended
2463 for extended use (for moving the machine, etc)
2464 'power:AC_only' when the device has no battery at all.
2465 """
2466 psu = self.run(command='mosys psu type', ignore_status=True)
2467 if psu.exit_status:
2468 # The psu command for mosys is not included for all platforms. The
2469 # assumption is that the device will have a battery if the command
2470 # is not found.
2471 return 'power:battery'
2472
2473 psu_str = psu.stdout.strip()
2474 if psu_str == 'unknown':
2475 return None
2476
2477 return 'power:%s' % psu_str
2478
2479
Puthikorn Voravootivatfa011242014-03-14 18:45:11 -07002480 @label_decorator('storage')
2481 def get_storage(self):
2482 """
2483 Determine the type of boot device for this host.
2484
2485 Determine if the internal device is SCSI or dw_mmc device.
2486 Then check that it is SSD or HDD or eMMC or something else.
2487
2488 @returns a string representing this host's internal device type.
2489 'storage:ssd' when internal device is solid state drive
2490 'storage:hdd' when internal device is hard disk drive
2491 'storage:mmc' when internal device is mmc drive
2492 None When internal device is something else or
2493 when we are unable to determine the type
2494 """
2495 # The output should be /dev/mmcblk* for SD/eMMC or /dev/sd* for scsi
2496 rootdev_cmd = ' '.join(['. /usr/sbin/write_gpt.sh;',
2497 '. /usr/share/misc/chromeos-common.sh;',
2498 'load_base_vars;',
2499 'get_fixed_dst_drive'])
Puthikorn Voravootivat03c51682014-04-24 13:52:12 -07002500 rootdev = self.run(command=rootdev_cmd, ignore_status=True)
2501 if rootdev.exit_status:
2502 logging.info("Fail to run %s", rootdev_cmd)
2503 return None
Puthikorn Voravootivatfa011242014-03-14 18:45:11 -07002504 rootdev_str = rootdev.stdout.strip()
2505
2506 if not rootdev_str:
2507 return None
2508
2509 rootdev_base = os.path.basename(rootdev_str)
2510
2511 mmc_pattern = '/dev/mmcblk[0-9]'
2512 if re.match(mmc_pattern, rootdev_str):
2513 # Use type to determine if the internal device is eMMC or somthing
2514 # else. We can assume that MMC is always an internal device.
2515 type_cmd = 'cat /sys/block/%s/device/type' % rootdev_base
Puthikorn Voravootivat03c51682014-04-24 13:52:12 -07002516 type = self.run(command=type_cmd, ignore_status=True)
2517 if type.exit_status:
2518 logging.info("Fail to run %s", type_cmd)
2519 return None
Puthikorn Voravootivatfa011242014-03-14 18:45:11 -07002520 type_str = type.stdout.strip()
2521
2522 if type_str == 'MMC':
2523 return 'storage:mmc'
2524
2525 scsi_pattern = '/dev/sd[a-z]+'
2526 if re.match(scsi_pattern, rootdev.stdout):
2527 # Read symlink for /sys/block/sd* to determine if the internal
2528 # device is connected via ata or usb.
2529 link_cmd = 'readlink /sys/block/%s' % rootdev_base
Puthikorn Voravootivat03c51682014-04-24 13:52:12 -07002530 link = self.run(command=link_cmd, ignore_status=True)
2531 if link.exit_status:
2532 logging.info("Fail to run %s", link_cmd)
2533 return None
Puthikorn Voravootivatfa011242014-03-14 18:45:11 -07002534 link_str = link.stdout.strip()
2535 if 'usb' in link_str:
2536 return None
2537
2538 # Read rotation to determine if the internal device is ssd or hdd.
2539 rotate_cmd = str('cat /sys/block/%s/queue/rotational'
2540 % rootdev_base)
Puthikorn Voravootivat03c51682014-04-24 13:52:12 -07002541 rotate = self.run(command=rotate_cmd, ignore_status=True)
2542 if rotate.exit_status:
2543 logging.info("Fail to run %s", rotate_cmd)
2544 return None
Puthikorn Voravootivatfa011242014-03-14 18:45:11 -07002545 rotate_str = rotate.stdout.strip()
2546
2547 rotate_dict = {'0':'storage:ssd', '1':'storage:hdd'}
2548 return rotate_dict.get(rotate_str)
2549
2550 # All other internal device / error case will always fall here
2551 return None
2552
2553
Dan Shi4e9a2aa2014-03-24 14:28:42 -07002554 @label_decorator('servo')
2555 def get_servo(self):
2556 """Determine if the host has a servo attached.
2557
2558 If the host has a working servo attached, it should have a servo label.
2559
2560 @return: string 'servo' if the host has servo attached. Otherwise,
2561 returns None.
2562 """
2563 return 'servo' if self._servo_host else None
2564
2565
Dan Shi5beba472014-05-28 22:46:07 -07002566 @label_decorator('video_labels')
2567 def get_video_labels(self):
2568 """Run /usr/local/bin/avtest_label_detect to get a list of video labels.
2569
2570 Sample output of avtest_label_detect:
2571 Detected label: hw_video_acc_vp8
2572 Detected label: webcam
2573
2574 @return: A list of labels detected by tool avtest_label_detect.
2575 """
2576 try:
2577 result = self.run('/usr/local/bin/avtest_label_detect').stdout
2578 return re.findall('^Detected label: (\w+)$', result, re.M)
2579 except error.AutoservRunError:
2580 # The tool is not installed.
2581 return []
2582
2583
mussa584b4462014-06-20 15:13:28 -07002584 @label_decorator('video_glitch_detection')
2585 def is_video_glitch_detection_supported(self):
2586 """ Determine if a board under test is supported for video glitch
2587 detection tests.
2588
2589 @return: 'video_glitch_detection' if board is supported, None otherwise.
2590 """
Mussa5b589052015-10-26 17:55:26 -07002591 board = self.get_board().replace(ds_constants.BOARD_PREFIX, '')
mussa584b4462014-06-20 15:13:28 -07002592
Mussa5b589052015-10-26 17:55:26 -07002593 if board in video_test_constants.SUPPORTED_BOARDS:
2594 return 'video_glitch_detection'
mussa584b4462014-06-20 15:13:28 -07002595
Mussa5b589052015-10-26 17:55:26 -07002596 return None
mussa584b4462014-06-20 15:13:28 -07002597
mussa584b4462014-06-20 15:13:28 -07002598
Katherine Threlkeld7b97a9f2014-06-24 13:47:14 -07002599 @label_decorator('touch_labels')
2600 def get_touch(self):
2601 """
2602 Determine whether board under test has a touchpad or touchscreen.
2603
2604 @return: A list of some combination of 'touchscreen' and 'touchpad',
2605 depending on what is present on the device.
Katherine Threlkeldab83d392015-06-18 16:45:57 -07002606
Katherine Threlkeld7b97a9f2014-06-24 13:47:14 -07002607 """
2608 labels = []
Katherine Threlkeldab83d392015-06-18 16:45:57 -07002609 looking_for = ['touchpad', 'touchscreen']
2610 player = input_playback.InputPlayback()
2611 input_events = self.run('ls /dev/input/event*').stdout.strip().split()
2612 filename = '/tmp/touch_labels'
2613 for event in input_events:
2614 self.run('evtest %s > %s' % (event, filename), timeout=1,
2615 ignore_timeout=True)
2616 properties = self.run('cat %s' % filename).stdout
2617 input_type = player._determine_input_type(properties)
2618 if input_type in looking_for:
2619 labels.append(input_type)
2620 looking_for.remove(input_type)
2621 if len(looking_for) == 0:
2622 break
2623 self.run('rm %s' % filename)
2624
Katherine Threlkeld7b97a9f2014-06-24 13:47:14 -07002625 return labels
2626
Hung-ying Tyana39b0542015-06-30 10:36:42 +08002627
2628 @label_decorator('internal_display')
2629 def has_internal_display(self):
2630 """Determine if the device under test is equipped with an internal
2631 display.
2632
2633 @return: 'internal_display' if one is present; None otherwise.
2634 """
2635 from autotest_lib.client.cros.graphics import graphics_utils
2636 from autotest_lib.client.common_lib import utils as common_utils
2637
2638 def __system_output(cmd):
2639 return self.run(cmd).stdout
2640
2641 def __read_file(remote_path):
2642 return self.run('cat %s' % remote_path).stdout
2643
2644 # Hijack the necessary client functions so that we can take advantage
2645 # of the client lib here.
2646 # FIXME: find a less hacky way than this
2647 original_system_output = utils.system_output
2648 original_read_file = common_utils.read_file
2649 utils.system_output = __system_output
2650 common_utils.read_file = __read_file
2651 try:
2652 return ('internal_display' if graphics_utils.has_internal_display()
2653 else None)
2654 finally:
2655 utils.system_output = original_system_output
2656 common_utils.read_file = original_read_file
2657
2658
Eric Carusoee673ac2015-08-05 17:03:04 -07002659 @label_decorator('lucidsleep')
2660 def has_lucid_sleep_support(self):
2661 """Determine if the device under test has support for lucid sleep.
2662
2663 @return 'lucidsleep' if this board supports lucid sleep; None otherwise
2664 """
2665 board = self.get_board().replace(ds_constants.BOARD_PREFIX, '')
2666 return 'lucidsleep' if board in LUCID_SLEEP_BOARDS else None
2667
2668
Dan Shi85276d42014-04-08 22:11:45 -07002669 def is_boot_from_usb(self):
2670 """Check if DUT is boot from USB.
2671
2672 @return: True if DUT is boot from usb.
2673 """
2674 device = self.run('rootdev -s -d').stdout.strip()
2675 removable = int(self.run('cat /sys/block/%s/removable' %
2676 os.path.basename(device)).stdout.strip())
2677 return removable == 1
Helen Zhang17dae2b2014-11-11 09:25:52 -08002678
2679
2680 def read_from_meminfo(self, key):
Dan Shi49ca0932014-11-14 11:22:27 -08002681 """Return the memory info from /proc/meminfo
Helen Zhang17dae2b2014-11-11 09:25:52 -08002682
2683 @param key: meminfo requested
2684
2685 @return the memory value as a string
2686
2687 """
Helen Zhang17dae2b2014-11-11 09:25:52 -08002688 meminfo = self.run('grep %s /proc/meminfo' % key).stdout.strip()
2689 logging.debug('%s', meminfo)
2690 return int(re.search(r'\d+', meminfo).group(0))
Rohit Makasana8a4923c2015-08-13 17:04:26 -07002691
2692
2693 def get_board_type(self):
2694 """
2695 Get the DUT's device type from /etc/lsb-release.
Danny Chan471a8d12015-08-18 14:57:41 -07002696 DEVICETYPE can be one of CHROMEBOX, CHROMEBASE, CHROMEBOOK or more.
2697
2698 @return value of DEVICETYPE param from lsb-release.
Rohit Makasana8a4923c2015-08-13 17:04:26 -07002699 """
Danny Chan471a8d12015-08-18 14:57:41 -07002700 device_type = self.run('grep DEVICETYPE /etc/lsb-release',
2701 ignore_status=True).stdout
2702 if device_type:
Kalin Stoyanov524310b2015-08-21 16:24:04 -07002703 return device_type.split('=')[-1].strip()
Danny Chan471a8d12015-08-18 14:57:41 -07002704 return ''
Gilad Arnolda76bef02015-09-29 13:55:15 -07002705
2706
2707 def get_os_type(self):
2708 return 'cros'
Simran Basia5522a32015-10-06 11:01:24 -07002709
2710
2711 def enable_adb_testing(self):
2712 """Mark this host as an adb tester."""
Dan Shia2872172015-10-31 01:16:51 -07002713 self.run('touch %s' % constants.ANDROID_TESTER_FILEFLAG)