Chris Sosa | 5e4246b | 2012-05-22 18:05:22 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Don Garrett | 56b1cc8 | 2013-12-06 17:49:20 -0800 | [diff] [blame] | 5 | import glob |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 6 | import logging |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 7 | import os |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 8 | import re |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 9 | import time |
Prashanth B | 32baa9b | 2014-03-13 13:23:01 -0700 | [diff] [blame] | 10 | import urllib2 |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 11 | import urlparse |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 12 | |
Chris Sosa | 6542508 | 2013-10-16 13:26:22 -0700 | [diff] [blame] | 13 | from autotest_lib.client.bin import utils |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 14 | from autotest_lib.client.common_lib import error, global_config |
Prashanth B | 32baa9b | 2014-03-13 13:23:01 -0700 | [diff] [blame] | 15 | from autotest_lib.client.common_lib.cros import dev_server |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 16 | from autotest_lib.server import autotest |
Shelley Chen | 61d2898 | 2016-10-28 09:40:20 -0700 | [diff] [blame] | 17 | from autotest_lib.server import utils as server_utils |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 18 | from autotest_lib.server.cros.dynamic_suite import constants as ds_constants |
| 19 | from autotest_lib.server.cros.dynamic_suite import tools |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 20 | from chromite.lib import retry_util |
Dan Shi | f3a35f7 | 2016-01-25 11:18:14 -0800 | [diff] [blame] | 21 | |
Shelley Chen | 16b8df3 | 2016-10-27 16:24:21 -0700 | [diff] [blame] | 22 | try: |
| 23 | from chromite.lib import metrics |
Dan Shi | 5e2efb7 | 2017-02-07 11:40:23 -0800 | [diff] [blame] | 24 | except ImportError: |
| 25 | metrics = utils.metrics_mock |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 26 | |
Gwendal Grignou | 3e96cc2 | 2017-06-07 16:22:51 -0700 | [diff] [blame] | 27 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 28 | def _metric_name(base_name): |
| 29 | return 'chromeos/autotest/provision/' + base_name |
| 30 | |
| 31 | |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 32 | # Local stateful update path is relative to the CrOS source directory. |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 33 | UPDATER_IDLE = 'UPDATE_STATUS_IDLE' |
Sean O | c053dfe | 2010-08-23 18:22:26 +0200 | [diff] [blame] | 34 | UPDATER_NEED_REBOOT = 'UPDATE_STATUS_UPDATED_NEED_REBOOT' |
beeps | 5e8c45a | 2013-12-17 22:05:11 -0800 | [diff] [blame] | 35 | # A list of update engine client states that occur after an update is triggered. |
| 36 | UPDATER_PROCESSING_UPDATE = ['UPDATE_STATUS_CHECKING_FORUPDATE', |
| 37 | 'UPDATE_STATUS_UPDATE_AVAILABLE', |
| 38 | 'UPDATE_STATUS_DOWNLOADING', |
| 39 | 'UPDATE_STATUS_FINALIZING'] |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 40 | |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 41 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 42 | _STATEFUL_UPDATE_SCRIPT = 'stateful_update' |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 43 | _QUICK_PROVISION_SCRIPT = 'quick-provision' |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 44 | |
| 45 | _UPDATER_BIN = '/usr/bin/update_engine_client' |
| 46 | _UPDATER_LOGS = ['/var/log/messages', '/var/log/update_engine'] |
| 47 | |
| 48 | _KERNEL_A = {'name': 'KERN-A', 'kernel': 2, 'root': 3} |
| 49 | _KERNEL_B = {'name': 'KERN-B', 'kernel': 4, 'root': 5} |
| 50 | |
| 51 | # Time to wait for new kernel to be marked successful after |
| 52 | # auto update. |
| 53 | _KERNEL_UPDATE_TIMEOUT = 120 |
| 54 | |
| 55 | |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 56 | # PROVISION_FAILED - A flag file to indicate provision failures. The |
| 57 | # file is created at the start of any AU procedure (see |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 58 | # `ChromiumOSUpdater._prepare_host()`). The file's location in |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 59 | # stateful means that on successul update it will be removed. Thus, if |
| 60 | # this file exists, it indicates that we've tried and failed in a |
| 61 | # previous attempt to update. |
| 62 | PROVISION_FAILED = '/var/tmp/provision_failed' |
| 63 | |
| 64 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 65 | # A flag file used to enable special handling in lab DUTs. Some |
| 66 | # parts of the system in Chromium OS test images will behave in ways |
| 67 | # convenient to the test lab when this file is present. Generally, |
| 68 | # we create this immediately after any update completes. |
| 69 | _LAB_MACHINE_FILE = '/mnt/stateful_partition/.labmachine' |
| 70 | |
| 71 | |
Richard Barnette | 3ef29a8 | 2018-06-28 13:52:54 -0700 | [diff] [blame^] | 72 | # _TARGET_VERSION - A file containing the new version to which we plan |
| 73 | # to update. This file is used by the CrOS shutdown code to detect and |
| 74 | # handle certain version downgrade cases. Specifically: Downgrading |
| 75 | # may trigger an unwanted powerwash in the target build when the |
| 76 | # following conditions are met: |
| 77 | # * Source build is a v4.4 kernel with R69-10756.0.0 or later. |
| 78 | # * Target build predates the R69-10756.0.0 cutoff. |
| 79 | # When this file is present and indicates a downgrade, the OS shutdown |
| 80 | # code on the DUT knows how to prevent the powerwash. |
| 81 | _TARGET_VERSION = '/run/update_target_version' |
| 82 | |
| 83 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 84 | class RootFSUpdateError(error.TestFail): |
Chris Sosa | 77556d8 | 2012-04-05 15:23:14 -0700 | [diff] [blame] | 85 | """Raised when the RootFS fails to update.""" |
Chris Sosa | 77556d8 | 2012-04-05 15:23:14 -0700 | [diff] [blame] | 86 | |
| 87 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 88 | class StatefulUpdateError(error.TestFail): |
Chris Sosa | 77556d8 | 2012-04-05 15:23:14 -0700 | [diff] [blame] | 89 | """Raised when the stateful partition fails to update.""" |
Chris Sosa | 77556d8 | 2012-04-05 15:23:14 -0700 | [diff] [blame] | 90 | |
| 91 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 92 | class _AttributedUpdateError(error.TestFail): |
| 93 | """Update failure with an attributed cause.""" |
| 94 | |
| 95 | def __init__(self, attribution, msg): |
| 96 | super(_AttributedUpdateError, self).__init__( |
| 97 | '%s: %s' % (attribution, msg)) |
| 98 | |
| 99 | |
| 100 | class HostUpdateError(_AttributedUpdateError): |
| 101 | """Failure updating a DUT attributable to the DUT. |
| 102 | |
| 103 | This class of exception should be raised when the most likely cause |
| 104 | of failure was a condition existing on the DUT prior to the update, |
| 105 | such as a hardware problem, or a bug in the software on the DUT. |
| 106 | """ |
| 107 | |
| 108 | def __init__(self, hostname, msg): |
| 109 | super(HostUpdateError, self).__init__( |
| 110 | 'Error on %s prior to update' % hostname, msg) |
| 111 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 112 | @property |
| 113 | def failure_summary(self): |
| 114 | #pylint: disable=missing-docstring |
| 115 | return 'DUT failed prior to update' |
| 116 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 117 | |
| 118 | class DevServerError(_AttributedUpdateError): |
| 119 | """Failure updating a DUT attributable to the devserver. |
| 120 | |
| 121 | This class of exception should be raised when the most likely cause |
| 122 | of failure was the devserver serving the target image for update. |
| 123 | """ |
| 124 | |
| 125 | def __init__(self, devserver, msg): |
| 126 | super(DevServerError, self).__init__( |
| 127 | 'Devserver error on %s' % devserver, msg) |
| 128 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 129 | @property |
| 130 | def failure_summary(self): |
| 131 | #pylint: disable=missing-docstring |
| 132 | return 'Devserver failed prior to update' |
| 133 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 134 | |
| 135 | class ImageInstallError(_AttributedUpdateError): |
| 136 | """Failure updating a DUT when installing from the devserver. |
| 137 | |
| 138 | This class of exception should be raised when the target DUT fails |
| 139 | to download and install the target image from the devserver, and |
| 140 | either the devserver or the DUT might be at fault. |
| 141 | """ |
| 142 | |
| 143 | def __init__(self, hostname, devserver, msg): |
| 144 | super(ImageInstallError, self).__init__( |
| 145 | 'Download and install failed from %s onto %s' |
| 146 | % (devserver, hostname), msg) |
| 147 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 148 | @property |
| 149 | def failure_summary(self): |
| 150 | #pylint: disable=missing-docstring |
| 151 | return 'Image failed to download and install' |
| 152 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 153 | |
| 154 | class NewBuildUpdateError(_AttributedUpdateError): |
| 155 | """Failure updating a DUT attributable to the target build. |
| 156 | |
| 157 | This class of exception should be raised when updating to a new |
| 158 | build fails, and the most likely cause of the failure is a bug in |
| 159 | the newly installed target build. |
| 160 | """ |
| 161 | |
| 162 | def __init__(self, update_version, msg): |
| 163 | super(NewBuildUpdateError, self).__init__( |
| 164 | 'Failure in build %s' % update_version, msg) |
| 165 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 166 | @property |
| 167 | def failure_summary(self): |
| 168 | #pylint: disable=missing-docstring |
| 169 | return 'Build failed to work after installing' |
| 170 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 171 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 172 | def _url_to_version(update_url): |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 173 | """Return the version based on update_url. |
| 174 | |
| 175 | @param update_url: url to the image to update to. |
| 176 | |
| 177 | """ |
Dale Curtis | ddfdb94 | 2011-07-14 13:59:24 -0700 | [diff] [blame] | 178 | # The Chrome OS version is generally the last element in the URL. The only |
| 179 | # exception is delta update URLs, which are rooted under the version; e.g., |
| 180 | # http://.../update/.../0.14.755.0/au/0.14.754.0. In this case we want to |
| 181 | # strip off the au section of the path before reading the version. |
Dan Shi | 5002cfc | 2013-04-29 10:45:05 -0700 | [diff] [blame] | 182 | return re.sub('/au/.*', '', |
| 183 | urlparse.urlparse(update_url).path).split('/')[-1].strip() |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 184 | |
| 185 | |
Scott Zawalski | eadbf70 | 2013-03-14 09:23:06 -0400 | [diff] [blame] | 186 | def url_to_image_name(update_url): |
| 187 | """Return the image name based on update_url. |
| 188 | |
| 189 | From a URL like: |
| 190 | http://172.22.50.205:8082/update/lumpy-release/R27-3837.0.0 |
| 191 | return lumpy-release/R27-3837.0.0 |
| 192 | |
| 193 | @param update_url: url to the image to update to. |
| 194 | @returns a string representing the image name in the update_url. |
| 195 | |
| 196 | """ |
| 197 | return '/'.join(urlparse.urlparse(update_url).path.split('/')[-2:]) |
| 198 | |
| 199 | |
Prashanth B | 32baa9b | 2014-03-13 13:23:01 -0700 | [diff] [blame] | 200 | def _get_devserver_build_from_update_url(update_url): |
| 201 | """Get the devserver and build from the update url. |
| 202 | |
| 203 | @param update_url: The url for update. |
| 204 | Eg: http://devserver:port/update/build. |
| 205 | |
| 206 | @return: A tuple of (devserver url, build) or None if the update_url |
| 207 | doesn't match the expected pattern. |
| 208 | |
| 209 | @raises ValueError: If the update_url doesn't match the expected pattern. |
| 210 | @raises ValueError: If no global_config was found, or it doesn't contain an |
| 211 | image_url_pattern. |
| 212 | """ |
| 213 | pattern = global_config.global_config.get_config_value( |
| 214 | 'CROS', 'image_url_pattern', type=str, default='') |
| 215 | if not pattern: |
| 216 | raise ValueError('Cannot parse update_url, the global config needs ' |
| 217 | 'an image_url_pattern.') |
| 218 | re_pattern = pattern.replace('%s', '(\S+)') |
| 219 | parts = re.search(re_pattern, update_url) |
| 220 | if not parts or len(parts.groups()) < 2: |
| 221 | raise ValueError('%s is not an update url' % update_url) |
| 222 | return parts.groups() |
| 223 | |
| 224 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 225 | def _list_image_dir_contents(update_url): |
Prashanth B | 32baa9b | 2014-03-13 13:23:01 -0700 | [diff] [blame] | 226 | """Lists the contents of the devserver for a given build/update_url. |
| 227 | |
| 228 | @param update_url: An update url. Eg: http://devserver:port/update/build. |
| 229 | """ |
| 230 | if not update_url: |
| 231 | logging.warning('Need update_url to list contents of the devserver.') |
| 232 | return |
| 233 | error_msg = 'Cannot check contents of devserver, update url %s' % update_url |
| 234 | try: |
| 235 | devserver_url, build = _get_devserver_build_from_update_url(update_url) |
| 236 | except ValueError as e: |
| 237 | logging.warning('%s: %s', error_msg, e) |
| 238 | return |
| 239 | devserver = dev_server.ImageServer(devserver_url) |
| 240 | try: |
| 241 | devserver.list_image_dir(build) |
| 242 | # The devserver will retry on URLError to avoid flaky connections, but will |
| 243 | # eventually raise the URLError if it persists. All HTTPErrors get |
| 244 | # converted to DevServerExceptions. |
| 245 | except (dev_server.DevServerException, urllib2.URLError) as e: |
| 246 | logging.warning('%s: %s', error_msg, e) |
| 247 | |
| 248 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 249 | def _get_metric_fields(update_url): |
| 250 | """Return a dict of metric fields. |
| 251 | |
| 252 | This is used for sending autoupdate metrics for the given update URL. |
| 253 | |
| 254 | @param update_url Metrics fields will be calculated from this URL. |
| 255 | """ |
| 256 | build_name = url_to_image_name(update_url) |
| 257 | try: |
| 258 | board, build_type, milestone, _ = server_utils.ParseBuildName( |
| 259 | build_name) |
| 260 | except server_utils.ParseBuildNameException: |
| 261 | logging.warning('Unable to parse build name %s for metrics. ' |
| 262 | 'Continuing anyway.', build_name) |
| 263 | board, build_type, milestone = ('', '', '') |
| 264 | return { |
| 265 | 'dev_server': dev_server.get_resolved_hostname(update_url), |
| 266 | 'board': board, |
| 267 | 'build_type': build_type, |
| 268 | 'milestone': milestone, |
| 269 | } |
| 270 | |
| 271 | |
| 272 | def _emit_provision_metrics(update_url, dut_host_name, |
| 273 | failure_reason, duration): |
| 274 | """Send metrics for provision request.""" |
| 275 | # The following is high cardinality, but sparse. |
| 276 | # Each DUT is of a single board type, and likely build type. |
| 277 | # The affinity also results in each DUT being attached to the same |
| 278 | # dev_server as well. |
| 279 | image_fields = _get_metric_fields(update_url) |
| 280 | fields = { |
| 281 | 'board': image_fields['board'], |
| 282 | 'build_type': image_fields['build_type'], |
| 283 | 'dut_host_name': dut_host_name, |
| 284 | 'dev_server': image_fields['dev_server'], |
| 285 | 'success': not failure_reason, |
| 286 | } |
| 287 | build_name = url_to_image_name(update_url) |
| 288 | |
| 289 | # reset_after=True is required for String gauges events to ensure that |
| 290 | # the metrics are not repeatedly emitted until the server restarts. |
| 291 | |
| 292 | metrics.String(_metric_name('provision_build_by_devserver_dut'), |
| 293 | reset_after=True).set(build_name, fields=fields) |
| 294 | if failure_reason: |
| 295 | metrics.String( |
| 296 | _metric_name('provision_failure_reason_by_devserver_dut'), |
| 297 | reset_after=True).set(failure_reason, fields=fields) |
| 298 | metrics.SecondsDistribution( |
| 299 | _metric_name('provision_duration_by_devserver_dut')).add( |
| 300 | duration, fields=fields) |
| 301 | |
| 302 | |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 303 | # TODO(garnold) This implements shared updater functionality needed for |
| 304 | # supporting the autoupdate_EndToEnd server-side test. We should probably |
| 305 | # migrate more of the existing ChromiumOSUpdater functionality to it as we |
| 306 | # expand non-CrOS support in other tests. |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 307 | class ChromiumOSUpdater(object): |
| 308 | """Chromium OS specific DUT update functionality.""" |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 309 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 310 | def __init__(self, update_url, host=None, interactive=True): |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 311 | """Initializes the object. |
| 312 | |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 313 | @param update_url: The URL we want the update to use. |
| 314 | @param host: A client.common_lib.hosts.Host implementation. |
David Haddock | 76a4c88 | 2017-12-13 18:50:09 -0800 | [diff] [blame] | 315 | @param interactive: Bool whether we are doing an interactive update. |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 316 | """ |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 317 | self.update_url = update_url |
| 318 | self.host = host |
David Haddock | 76a4c88 | 2017-12-13 18:50:09 -0800 | [diff] [blame] | 319 | self.interactive = interactive |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 320 | self.update_version = _url_to_version(update_url) |
| 321 | |
| 322 | |
| 323 | def _run(self, cmd, *args, **kwargs): |
| 324 | """Abbreviated form of self.host.run(...)""" |
| 325 | return self.host.run(cmd, *args, **kwargs) |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 326 | |
| 327 | |
| 328 | def check_update_status(self): |
| 329 | """Returns the current update engine state. |
| 330 | |
| 331 | We use the `update_engine_client -status' command and parse the line |
| 332 | indicating the update state, e.g. "CURRENT_OP=UPDATE_STATUS_IDLE". |
| 333 | """ |
Luigi Semenzato | f15c8fc | 2017-03-03 14:12:40 -0800 | [diff] [blame] | 334 | update_status = self.host.run(command='%s -status | grep CURRENT_OP' % |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 335 | _UPDATER_BIN) |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 336 | return update_status.stdout.strip().split('=')[-1] |
| 337 | |
| 338 | |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 339 | def _rootdev(self, options=''): |
| 340 | """Returns the stripped output of rootdev <options>. |
| 341 | |
| 342 | @param options: options to run rootdev. |
| 343 | |
| 344 | """ |
| 345 | return self._run('rootdev %s' % options).stdout.strip() |
| 346 | |
| 347 | |
| 348 | def get_kernel_state(self): |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 349 | """Returns the (<active>, <inactive>) kernel state as a pair. |
| 350 | |
| 351 | @raise RootFSUpdateError if the DUT reports a root partition |
| 352 | number that isn't one of the known valid values. |
| 353 | """ |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 354 | active_root = int(re.findall('\d+\Z', self._rootdev('-s'))[0]) |
| 355 | if active_root == _KERNEL_A['root']: |
| 356 | return _KERNEL_A, _KERNEL_B |
| 357 | elif active_root == _KERNEL_B['root']: |
| 358 | return _KERNEL_B, _KERNEL_A |
| 359 | else: |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 360 | raise RootFSUpdateError( |
| 361 | 'Encountered unknown root partition: %s' % active_root) |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 362 | |
| 363 | |
Richard Barnette | 18fd584 | 2018-05-25 18:21:14 +0000 | [diff] [blame] | 364 | def _cgpt(self, flag, kernel): |
| 365 | """Return numeric cgpt value for the specified flag, kernel, device.""" |
| 366 | return int(self._run('cgpt show -n -i %d %s $(rootdev -s -d)' % ( |
| 367 | kernel['kernel'], flag)).stdout.strip()) |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 368 | |
| 369 | |
| 370 | def _get_next_kernel(self): |
| 371 | """Return the kernel that has priority for the next boot.""" |
| 372 | priority_a = self._cgpt('-P', _KERNEL_A) |
| 373 | priority_b = self._cgpt('-P', _KERNEL_B) |
| 374 | if priority_a > priority_b: |
| 375 | return _KERNEL_A |
| 376 | else: |
| 377 | return _KERNEL_B |
| 378 | |
| 379 | |
| 380 | def _get_kernel_success(self, kernel): |
| 381 | """Return boolean success flag for the specified kernel. |
| 382 | |
| 383 | @param kernel: information of the given kernel, either _KERNEL_A |
| 384 | or _KERNEL_B. |
| 385 | """ |
| 386 | return self._cgpt('-S', kernel) != 0 |
| 387 | |
| 388 | |
| 389 | def _get_kernel_tries(self, kernel): |
| 390 | """Return tries count for the specified kernel. |
| 391 | |
| 392 | @param kernel: information of the given kernel, either _KERNEL_A |
| 393 | or _KERNEL_B. |
| 394 | """ |
| 395 | return self._cgpt('-T', kernel) |
| 396 | |
| 397 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 398 | def _get_last_update_error(self): |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 399 | """Get the last autoupdate error code.""" |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 400 | command_result = self._run( |
| 401 | '%s --last_attempt_error' % _UPDATER_BIN) |
| 402 | return command_result.stdout.strip().replace('\n', ', ') |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 403 | |
| 404 | |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 405 | def _base_update_handler_no_retry(self, run_args): |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 406 | """Base function to handle a remote update ssh call. |
| 407 | |
| 408 | @param run_args: Dictionary of args passed to ssh_host.run function. |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 409 | |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 410 | @throws: intercepts and re-throws all exceptions |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 411 | """ |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 412 | try: |
| 413 | self.host.run(**run_args) |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 414 | except Exception as e: |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 415 | logging.debug('exception in update handler: %s', e) |
| 416 | raise e |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 417 | |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 418 | |
| 419 | def _base_update_handler(self, run_args, err_msg_prefix=None): |
| 420 | """Handle a remote update ssh call, possibly with retries. |
| 421 | |
| 422 | @param run_args: Dictionary of args passed to ssh_host.run function. |
| 423 | @param err_msg_prefix: Prefix of the exception error message. |
| 424 | """ |
| 425 | def exception_handler(e): |
| 426 | """Examines exceptions and returns True if the update handler |
| 427 | should be retried. |
| 428 | |
| 429 | @param e: the exception intercepted by the retry util. |
| 430 | """ |
| 431 | return (isinstance(e, error.AutoservSSHTimeout) or |
| 432 | (isinstance(e, error.GenericHostRunError) and |
| 433 | hasattr(e, 'description') and |
| 434 | (re.search('ERROR_CODE=37', e.description) or |
| 435 | re.search('generic error .255.', e.description)))) |
| 436 | |
| 437 | try: |
| 438 | # Try the update twice (arg 2 is max_retry, not including the first |
| 439 | # call). Some exceptions may be caught by the retry handler. |
| 440 | retry_util.GenericRetry(exception_handler, 1, |
| 441 | self._base_update_handler_no_retry, |
| 442 | run_args) |
| 443 | except Exception as e: |
| 444 | message = err_msg_prefix + ': ' + str(e) |
| 445 | raise RootFSUpdateError(message) |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 446 | |
| 447 | |
Luigi Semenzato | f15c8fc | 2017-03-03 14:12:40 -0800 | [diff] [blame] | 448 | def _wait_for_update_service(self): |
| 449 | """Ensure that the update engine daemon is running, possibly |
| 450 | by waiting for it a bit in case the DUT just rebooted and the |
| 451 | service hasn't started yet. |
| 452 | """ |
| 453 | def handler(e): |
| 454 | """Retry exception handler. |
| 455 | |
| 456 | Assumes that the error is due to the update service not having |
| 457 | started yet. |
| 458 | |
| 459 | @param e: the exception intercepted by the retry util. |
| 460 | """ |
| 461 | if isinstance(e, error.AutoservRunError): |
| 462 | logging.debug('update service check exception: %s\n' |
| 463 | 'retrying...', e) |
| 464 | return True |
| 465 | else: |
| 466 | return False |
| 467 | |
| 468 | # Retry at most three times, every 5s. |
| 469 | status = retry_util.GenericRetry(handler, 3, |
| 470 | self.check_update_status, |
| 471 | sleep=5) |
| 472 | |
| 473 | # Expect the update engine to be idle. |
| 474 | if status != UPDATER_IDLE: |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 475 | raise RootFSUpdateError( |
| 476 | 'Update engine status is %s (%s was expected).' |
| 477 | % (status, UPDATER_IDLE)) |
Luigi Semenzato | f15c8fc | 2017-03-03 14:12:40 -0800 | [diff] [blame] | 478 | |
| 479 | |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 480 | def _reset_update_engine(self): |
| 481 | """Resets the host to prepare for a clean update regardless of state.""" |
| 482 | self._run('stop ui || true') |
| 483 | self._run('stop update-engine || true') |
| 484 | self._run('start update-engine') |
Luigi Semenzato | f15c8fc | 2017-03-03 14:12:40 -0800 | [diff] [blame] | 485 | self._wait_for_update_service() |
| 486 | |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 487 | |
| 488 | def _reset_stateful_partition(self): |
| 489 | """Clear any pending stateful update request.""" |
Richard Barnette | 18fd584 | 2018-05-25 18:21:14 +0000 | [diff] [blame] | 490 | self._run('%s --stateful_change=reset 2>&1' |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 491 | % self._get_stateful_update_script()) |
Richard Barnette | 3ef29a8 | 2018-06-28 13:52:54 -0700 | [diff] [blame^] | 492 | self._run('rm -f %s' % _TARGET_VERSION) |
| 493 | |
| 494 | |
| 495 | def _set_target_version(self): |
| 496 | """Set the "target version" for the update.""" |
| 497 | version_number = self.update_version.split('-')[1] |
| 498 | self._run('echo %s > %s' % (version_number, _TARGET_VERSION)) |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 499 | |
| 500 | |
| 501 | def _revert_boot_partition(self): |
| 502 | """Revert the boot partition.""" |
| 503 | part = self._rootdev('-s') |
| 504 | logging.warning('Reverting update; Boot partition will be %s', part) |
| 505 | return self._run('/postinst %s 2>&1' % part) |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 506 | |
| 507 | |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 508 | def _verify_kernel_state(self): |
| 509 | """Verify that the next kernel to boot is correct for update. |
| 510 | |
| 511 | This tests that the kernel state is correct for a successfully |
| 512 | downloaded and installed update. That is, the next kernel to |
| 513 | boot must be the currently inactive kernel. |
| 514 | |
| 515 | @raise RootFSUpdateError if the DUT next kernel isn't the |
| 516 | expected next kernel. |
| 517 | """ |
| 518 | inactive_kernel = self.get_kernel_state()[1] |
| 519 | next_kernel = self._get_next_kernel() |
| 520 | if next_kernel != inactive_kernel: |
| 521 | raise RootFSUpdateError( |
| 522 | 'Update failed. The kernel for next boot is %s, ' |
| 523 | 'but %s was expected.' |
| 524 | % (next_kernel['name'], inactive_kernel['name'])) |
| 525 | return inactive_kernel |
| 526 | |
| 527 | |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 528 | def _verify_update_completed(self): |
| 529 | """Verifies that an update has completed. |
| 530 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 531 | @raise RootFSUpdateError if the DUT doesn't indicate that |
| 532 | download is complete and the DUT is ready for reboot. |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 533 | """ |
| 534 | status = self.check_update_status() |
| 535 | if status != UPDATER_NEED_REBOOT: |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 536 | error_msg = '' |
| 537 | if status == UPDATER_IDLE: |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 538 | error_msg = 'Update error: %s' % self._get_last_update_error() |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 539 | raise RootFSUpdateError( |
| 540 | 'Update engine status is %s (%s was expected). %s' |
| 541 | % (status, UPDATER_NEED_REBOOT, error_msg)) |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 542 | return self._verify_kernel_state() |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 543 | |
| 544 | |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 545 | def trigger_update(self): |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 546 | """Triggers a background update.""" |
| 547 | # If this function is called immediately after reboot (which it |
| 548 | # can be), there is no guarantee that the update engine is up |
| 549 | # and running yet, so wait for it. |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 550 | self._wait_for_update_service() |
| 551 | |
| 552 | autoupdate_cmd = ('%s --check_for_update --omaha_url=%s' % |
| 553 | (_UPDATER_BIN, self.update_url)) |
| 554 | run_args = {'command': autoupdate_cmd} |
| 555 | err_prefix = 'Failed to trigger an update on %s. ' % self.host.hostname |
| 556 | logging.info('Triggering update via: %s', autoupdate_cmd) |
| 557 | metric_fields = {'success': False} |
| 558 | try: |
| 559 | self._base_update_handler(run_args, err_prefix) |
| 560 | metric_fields['success'] = True |
| 561 | finally: |
| 562 | c = metrics.Counter('chromeos/autotest/autoupdater/trigger') |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 563 | metric_fields.update(_get_metric_fields(self.update_url)) |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 564 | c.increment(fields=metric_fields) |
| 565 | |
| 566 | |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 567 | def update_image(self): |
Richard Barnette | 18fd584 | 2018-05-25 18:21:14 +0000 | [diff] [blame] | 568 | """Updates the device root FS and kernel and verifies success.""" |
Shuqian Zhao | fe4d62e | 2016-06-23 14:46:45 -0700 | [diff] [blame] | 569 | autoupdate_cmd = ('%s --update --omaha_url=%s' % |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 570 | (_UPDATER_BIN, self.update_url)) |
David Haddock | 76a4c88 | 2017-12-13 18:50:09 -0800 | [diff] [blame] | 571 | if not self.interactive: |
| 572 | autoupdate_cmd = '%s --interactive=false' % autoupdate_cmd |
Shuqian Zhao | d999272 | 2016-02-29 12:26:38 -0800 | [diff] [blame] | 573 | run_args = {'command': autoupdate_cmd, 'timeout': 3600} |
| 574 | err_prefix = ('Failed to install device image using payload at %s ' |
| 575 | 'on %s. ' % (self.update_url, self.host.hostname)) |
| 576 | logging.info('Updating image via: %s', autoupdate_cmd) |
Allen Li | 1a5cc0a | 2017-06-20 14:08:59 -0700 | [diff] [blame] | 577 | metric_fields = {'success': False} |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 578 | try: |
Luigi Semenzato | e76d9f8 | 2016-11-21 11:15:10 -0800 | [diff] [blame] | 579 | self._base_update_handler(run_args, err_prefix) |
Allen Li | 1a5cc0a | 2017-06-20 14:08:59 -0700 | [diff] [blame] | 580 | metric_fields['success'] = True |
| 581 | finally: |
Allen Li | 1a5cc0a | 2017-06-20 14:08:59 -0700 | [diff] [blame] | 582 | c = metrics.Counter('chromeos/autotest/autoupdater/update') |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 583 | metric_fields.update(_get_metric_fields(self.update_url)) |
Allen Li | 1a5cc0a | 2017-06-20 14:08:59 -0700 | [diff] [blame] | 584 | c.increment(fields=metric_fields) |
Richard Barnette | 4d211c9 | 2018-05-24 18:56:08 +0000 | [diff] [blame] | 585 | return self._verify_update_completed() |
Gilad Arnold | d6adeb8 | 2015-09-21 07:10:03 -0700 | [diff] [blame] | 586 | |
| 587 | |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 588 | def _get_remote_script(self, script_name): |
| 589 | """Ensure that `script_name` is present on the DUT. |
Chris Sosa | 5e4246b | 2012-05-22 18:05:22 -0700 | [diff] [blame] | 590 | |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 591 | The given script (e.g. `stateful_update`) may be present in the |
| 592 | stateful partition under /usr/local/bin, or we may have to |
| 593 | download it from the devserver. |
Chris Sosa | a3ac215 | 2012-05-23 22:23:13 -0700 | [diff] [blame] | 594 | |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 595 | Determine whether the script is present or must be downloaded |
| 596 | and download if necessary. Then, return a command fragment |
| 597 | sufficient to run the script from whereever it now lives on the |
| 598 | DUT. |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 599 | |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 600 | @param script_name The name of the script as expected in |
| 601 | /usr/local/bin and on the devserver. |
| 602 | @return A string with the command (minus arguments) that will |
| 603 | run the target script. |
Gwendal Grignou | 3e96cc2 | 2017-06-07 16:22:51 -0700 | [diff] [blame] | 604 | """ |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 605 | remote_script = '/usr/local/bin/%s' % script_name |
| 606 | if self.host.path_exists(remote_script): |
| 607 | return remote_script |
| 608 | remote_tmp_script = '/tmp/%s' % script_name |
| 609 | server_name = urlparse.urlparse(self.update_url)[1] |
| 610 | script_url = 'http://%s/static/%s' % (server_name, script_name) |
| 611 | fetch_script = ( |
| 612 | 'curl -o %s %s && head -1 %s | grep "^#!" | sed "s/#!//"') % ( |
| 613 | remote_tmp_script, script_url, remote_tmp_script) |
| 614 | script_interpreter = self._run(fetch_script, |
| 615 | ignore_status=True).stdout.strip() |
| 616 | if not script_interpreter: |
| 617 | return None |
| 618 | return '%s %s' % (script_interpreter, remote_tmp_script) |
Chris Sosa | 5e4246b | 2012-05-22 18:05:22 -0700 | [diff] [blame] | 619 | |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 620 | |
| 621 | def _get_stateful_update_script(self): |
| 622 | """Returns a command to run the stateful update script. |
| 623 | |
| 624 | Find `stateful_update` on the target or install it, as |
| 625 | necessary. If installation fails, raise an exception. |
| 626 | |
| 627 | @raise StatefulUpdateError if the script can't be found or |
| 628 | installed. |
| 629 | @return A string that can be joined with arguments to run the |
| 630 | `stateful_update` command on the DUT. |
| 631 | """ |
| 632 | script_command = self._get_remote_script(_STATEFUL_UPDATE_SCRIPT) |
| 633 | if not script_command: |
| 634 | raise StatefulUpdateError('Could not install %s on DUT' |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 635 | % _STATEFUL_UPDATE_SCRIPT) |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 636 | return script_command |
Chris Sosa | 5e4246b | 2012-05-22 18:05:22 -0700 | [diff] [blame] | 637 | |
| 638 | |
Chris Sosa | c193217 | 2013-10-16 13:28:53 -0700 | [diff] [blame] | 639 | def rollback_rootfs(self, powerwash): |
| 640 | """Triggers rollback and waits for it to complete. |
| 641 | |
| 642 | @param powerwash: If true, powerwash as part of rollback. |
| 643 | |
| 644 | @raise RootFSUpdateError if anything went wrong. |
Chris Sosa | c193217 | 2013-10-16 13:28:53 -0700 | [diff] [blame] | 645 | """ |
Dan Shi | 549fb82 | 2015-03-24 18:01:11 -0700 | [diff] [blame] | 646 | version = self.host.get_release_version() |
Chris Sosa | c861752 | 2014-06-09 23:22:26 +0000 | [diff] [blame] | 647 | # Introduced can_rollback in M36 (build 5772). # etc/lsb-release matches |
| 648 | # X.Y.Z. This version split just pulls the first part out. |
| 649 | try: |
| 650 | build_number = int(version.split('.')[0]) |
| 651 | except ValueError: |
| 652 | logging.error('Could not parse build number.') |
| 653 | build_number = 0 |
| 654 | |
| 655 | if build_number >= 5772: |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 656 | can_rollback_cmd = '%s --can_rollback' % _UPDATER_BIN |
Chris Sosa | c861752 | 2014-06-09 23:22:26 +0000 | [diff] [blame] | 657 | logging.info('Checking for rollback.') |
| 658 | try: |
| 659 | self._run(can_rollback_cmd) |
| 660 | except error.AutoservRunError as e: |
| 661 | raise RootFSUpdateError("Rollback isn't possible on %s: %s" % |
| 662 | (self.host.hostname, str(e))) |
| 663 | |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 664 | rollback_cmd = '%s --rollback --follow' % _UPDATER_BIN |
Chris Sosa | c193217 | 2013-10-16 13:28:53 -0700 | [diff] [blame] | 665 | if not powerwash: |
Dan Shi | f3a35f7 | 2016-01-25 11:18:14 -0800 | [diff] [blame] | 666 | rollback_cmd += ' --nopowerwash' |
Chris Sosa | c193217 | 2013-10-16 13:28:53 -0700 | [diff] [blame] | 667 | |
Chris Sosa | c861752 | 2014-06-09 23:22:26 +0000 | [diff] [blame] | 668 | logging.info('Performing rollback.') |
Chris Sosa | c193217 | 2013-10-16 13:28:53 -0700 | [diff] [blame] | 669 | try: |
| 670 | self._run(rollback_cmd) |
Chris Sosa | c193217 | 2013-10-16 13:28:53 -0700 | [diff] [blame] | 671 | except error.AutoservRunError as e: |
| 672 | raise RootFSUpdateError('Rollback failed on %s: %s' % |
| 673 | (self.host.hostname, str(e))) |
| 674 | |
| 675 | self._verify_update_completed() |
| 676 | |
Gilad Arnold | 0ed760c | 2012-11-05 23:42:53 -0800 | [diff] [blame] | 677 | |
Chris Sosa | 7231260 | 2013-04-16 15:01:56 -0700 | [diff] [blame] | 678 | def update_stateful(self, clobber=True): |
| 679 | """Updates the stateful partition. |
| 680 | |
| 681 | @param clobber: If True, a clean stateful installation. |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 682 | |
| 683 | @raise StatefulUpdateError if the update script fails to |
| 684 | complete successfully. |
Chris Sosa | 7231260 | 2013-04-16 15:01:56 -0700 | [diff] [blame] | 685 | """ |
Chris Sosa | 77556d8 | 2012-04-05 15:23:14 -0700 | [diff] [blame] | 686 | logging.info('Updating stateful partition...') |
Richard Barnette | 18fd584 | 2018-05-25 18:21:14 +0000 | [diff] [blame] | 687 | statefuldev_url = self.update_url.replace('update', 'static') |
Chris Sosa | a3ac215 | 2012-05-23 22:23:13 -0700 | [diff] [blame] | 688 | |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 689 | # Attempt stateful partition update; this must succeed so that the newly |
| 690 | # installed host is testable after update. |
Richard Barnette | f00a2ee | 2018-06-08 11:51:38 -0700 | [diff] [blame] | 691 | statefuldev_cmd = [self._get_stateful_update_script(), statefuldev_url] |
Chris Sosa | 7231260 | 2013-04-16 15:01:56 -0700 | [diff] [blame] | 692 | if clobber: |
| 693 | statefuldev_cmd.append('--stateful_change=clean') |
| 694 | |
| 695 | statefuldev_cmd.append('2>&1') |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 696 | try: |
Dan Shi | 205b873 | 2016-01-25 10:56:22 -0800 | [diff] [blame] | 697 | self._run(' '.join(statefuldev_cmd), timeout=1200) |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 698 | except error.AutoservRunError: |
Richard Barnette | 18fd584 | 2018-05-25 18:21:14 +0000 | [diff] [blame] | 699 | raise StatefulUpdateError( |
Gilad Arnold | 62cf3a4 | 2015-10-01 09:15:25 -0700 | [diff] [blame] | 700 | 'Failed to perform stateful update on %s' % |
| 701 | self.host.hostname) |
Dale Curtis | 5c32c72 | 2011-05-04 19:24:23 -0700 | [diff] [blame] | 702 | |
Chris Sosa | a3ac215 | 2012-05-23 22:23:13 -0700 | [diff] [blame] | 703 | |
Richard Barnette | 54d14f5 | 2018-05-18 16:39:49 +0000 | [diff] [blame] | 704 | def verify_boot_expectations(self, expected_kernel, rollback_message): |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 705 | """Verifies that we fully booted given expected kernel state. |
| 706 | |
| 707 | This method both verifies that we booted using the correct kernel |
| 708 | state and that the OS has marked the kernel as good. |
| 709 | |
Richard Barnette | 54d14f5 | 2018-05-18 16:39:49 +0000 | [diff] [blame] | 710 | @param expected_kernel: kernel that we are verifying with, |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 711 | i.e. I expect to be booted onto partition 4 etc. See output of |
| 712 | get_kernel_state. |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 713 | @param rollback_message: string include in except message text |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 714 | if we booted with the wrong partition. |
| 715 | |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 716 | @raise NewBuildUpdateError if any of the various checks fail. |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 717 | """ |
| 718 | # Figure out the newly active kernel. |
Richard Barnette | 54d14f5 | 2018-05-18 16:39:49 +0000 | [diff] [blame] | 719 | active_kernel = self.get_kernel_state()[0] |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 720 | |
| 721 | # Check for rollback due to a bad build. |
Richard Barnette | 54d14f5 | 2018-05-18 16:39:49 +0000 | [diff] [blame] | 722 | if active_kernel != expected_kernel: |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 723 | |
| 724 | # Kernel crash reports should be wiped between test runs, but |
| 725 | # may persist from earlier parts of the test, or from problems |
| 726 | # with provisioning. |
| 727 | # |
| 728 | # Kernel crash reports will NOT be present if the crash happened |
| 729 | # before encrypted stateful is mounted. |
| 730 | # |
| 731 | # TODO(dgarrett): Integrate with server/crashcollect.py at some |
| 732 | # point. |
| 733 | kernel_crashes = glob.glob('/var/spool/crash/kernel.*.kcrash') |
| 734 | if kernel_crashes: |
| 735 | rollback_message += ': kernel_crash' |
| 736 | logging.debug('Found %d kernel crash reports:', |
| 737 | len(kernel_crashes)) |
| 738 | # The crash names contain timestamps that may be useful: |
| 739 | # kernel.20131207.005945.0.kcrash |
| 740 | for crash in kernel_crashes: |
| 741 | logging.debug(' %s', os.path.basename(crash)) |
| 742 | |
| 743 | # Print out some information to make it easier to debug |
| 744 | # the rollback. |
| 745 | logging.debug('Dumping partition table.') |
| 746 | self._run('cgpt show $(rootdev -s -d)') |
| 747 | logging.debug('Dumping crossystem for firmware debugging.') |
| 748 | self._run('crossystem --all') |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 749 | raise NewBuildUpdateError(self.update_version, rollback_message) |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 750 | |
| 751 | # Make sure chromeos-setgoodkernel runs. |
| 752 | try: |
| 753 | utils.poll_for_condition( |
Richard Barnette | 54d14f5 | 2018-05-18 16:39:49 +0000 | [diff] [blame] | 754 | lambda: (self._get_kernel_tries(active_kernel) == 0 |
| 755 | and self._get_kernel_success(active_kernel)), |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 756 | exception=RootFSUpdateError(), |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 757 | timeout=_KERNEL_UPDATE_TIMEOUT, sleep_interval=5) |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 758 | except RootFSUpdateError: |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 759 | services_status = self._run('status system-services').stdout |
| 760 | if services_status != 'system-services start/running\n': |
| 761 | event = ('Chrome failed to reach login screen') |
| 762 | else: |
| 763 | event = ('update-engine failed to call ' |
| 764 | 'chromeos-setgoodkernel') |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 765 | raise NewBuildUpdateError(self.update_version, event) |
Richard Barnette | 55d1af8 | 2018-05-22 23:40:14 +0000 | [diff] [blame] | 766 | |
| 767 | |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 768 | def _prepare_host(self): |
| 769 | """Make sure the target DUT is working and ready for update. |
| 770 | |
| 771 | Initially, the target DUT's state is unknown. The DUT is |
| 772 | expected to be online, but we strive to be forgiving if Chrome |
| 773 | and/or the update engine aren't fully functional. |
| 774 | """ |
| 775 | # Summary of work, and the rationale: |
| 776 | # 1. Reboot, because it's a good way to clear out problems. |
| 777 | # 2. Touch the PROVISION_FAILED file, to allow repair to detect |
| 778 | # failure later. |
| 779 | # 3. Run the hook for host class specific preparation. |
| 780 | # 4. Stop Chrome, because the system is designed to eventually |
| 781 | # reboot if Chrome is stuck in a crash loop. |
| 782 | # 5. Force `update-engine` to start, because if Chrome failed |
| 783 | # to start properly, the status of the `update-engine` job |
| 784 | # will be uncertain. |
| 785 | self._reset_stateful_partition() |
| 786 | self.host.reboot(timeout=self.host.REBOOT_TIMEOUT) |
| 787 | self._run('touch %s' % PROVISION_FAILED) |
| 788 | self.host.prepare_for_update() |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 789 | self._reset_update_engine() |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 790 | logging.info('Updating from version %s to %s.', |
| 791 | self.host.get_release_version(), |
| 792 | self.update_version) |
| 793 | |
| 794 | |
| 795 | def _verify_devserver(self): |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 796 | """Check that our chosen devserver is still working. |
| 797 | |
| 798 | @raise DevServerError if the devserver fails any sanity check. |
| 799 | """ |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 800 | server = 'http://%s' % urlparse.urlparse(self.update_url)[1] |
| 801 | try: |
| 802 | if not dev_server.ImageServer.devserver_healthy(server): |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 803 | raise DevServerError( |
| 804 | server, 'Devserver is not healthy') |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 805 | except Exception as e: |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 806 | raise DevServerError( |
| 807 | server, 'Devserver is not up and available') |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 808 | |
| 809 | |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 810 | def _install_via_update_engine(self): |
| 811 | """Install an updating using the production AU flow. |
| 812 | |
| 813 | This uses the standard AU flow and the `stateful_update` script |
| 814 | to download and install a root FS, kernel and stateful |
| 815 | filesystem content. |
| 816 | |
| 817 | @return The kernel expected to be booted next. |
| 818 | """ |
| 819 | logging.info('Installing image using update_engine.') |
| 820 | expected_kernel = self.update_image() |
| 821 | self.update_stateful() |
Richard Barnette | 3ef29a8 | 2018-06-28 13:52:54 -0700 | [diff] [blame^] | 822 | self._set_target_version() |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 823 | return expected_kernel |
| 824 | |
| 825 | |
| 826 | def _install_via_quick_provision(self): |
| 827 | """Install an updating using the `quick-provision` script. |
| 828 | |
| 829 | This uses the `quick-provision` script to download and install |
| 830 | a root FS, kernel and stateful filesystem content. |
| 831 | |
| 832 | @return The kernel expected to be booted next. |
| 833 | """ |
| 834 | build_re = global_config.global_config.get_config_value( |
| 835 | 'CROS', 'quick_provision_build_regex', type=str, default='') |
| 836 | image_name = url_to_image_name(self.update_url) |
| 837 | if not build_re or re.match(build_re, image_name) is None: |
| 838 | logging.info('Not eligible for quick-provision.') |
| 839 | return None |
| 840 | logging.info('Installing image using quick-provision.') |
| 841 | provision_command = self._get_remote_script(_QUICK_PROVISION_SCRIPT) |
| 842 | server_name = urlparse.urlparse(self.update_url)[1] |
| 843 | static_url = 'http://%s/static' % server_name |
| 844 | command = '%s --noreboot %s %s' % ( |
| 845 | provision_command, image_name, static_url) |
| 846 | try: |
| 847 | self._run(command) |
Richard Barnette | 3ef29a8 | 2018-06-28 13:52:54 -0700 | [diff] [blame^] | 848 | self._set_target_version() |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 849 | return self._verify_kernel_state() |
| 850 | except Exception: |
| 851 | # N.B. We handle only `Exception` here. Non-Exception |
| 852 | # classes (such as KeyboardInterrupt) are handled by our |
| 853 | # caller. |
| 854 | logging.exception('quick-provision script failed; ' |
| 855 | 'will fall back to update_engine.') |
| 856 | self._revert_boot_partition() |
| 857 | self._reset_stateful_partition() |
| 858 | self._reset_update_engine() |
| 859 | return None |
| 860 | |
| 861 | |
Richard Barnette | 54d14f5 | 2018-05-18 16:39:49 +0000 | [diff] [blame] | 862 | def _install_update(self): |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 863 | """Install the requested image on the DUT, but don't start it. |
| 864 | |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 865 | This downloads and installs a root FS, kernel and stateful |
| 866 | filesystem content. This does not reboot the DUT, so the update |
| 867 | is merely pending when the method returns. |
| 868 | |
| 869 | @return The kernel expected to be booted next. |
Dan Shi | 0f466e8 | 2013-02-22 15:44:58 -0800 | [diff] [blame] | 870 | """ |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 871 | logging.info('Installing image at %s onto %s', |
| 872 | self.update_url, self.host.hostname) |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 873 | try: |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 874 | return (self._install_via_quick_provision() |
| 875 | or self._install_via_update_engine()) |
Dale Curtis | 1e97318 | 2011-07-12 18:21:36 -0700 | [diff] [blame] | 876 | except: |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 877 | # N.B. This handling code includes non-Exception classes such |
| 878 | # as KeyboardInterrupt. We need to clean up, but we also must |
| 879 | # re-raise. |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 880 | self._revert_boot_partition() |
| 881 | self._reset_stateful_partition() |
Richard Barnette | e86b1ce | 2018-06-07 10:37:23 -0700 | [diff] [blame] | 882 | self._reset_update_engine() |
Dale Curtis | 1e97318 | 2011-07-12 18:21:36 -0700 | [diff] [blame] | 883 | # Collect update engine logs in the event of failure. |
| 884 | if self.host.job: |
Aviv Keshet | 2610d3e | 2016-06-01 16:37:01 -0700 | [diff] [blame] | 885 | logging.info('Collecting update engine logs due to failure...') |
Dale Curtis | 1e97318 | 2011-07-12 18:21:36 -0700 | [diff] [blame] | 886 | self.host.get_file( |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 887 | _UPDATER_LOGS, self.host.job.sysinfo.sysinfodir, |
Gilad Arnold | 0c0df73 | 2015-09-21 06:37:59 -0700 | [diff] [blame] | 888 | preserve_perm=False) |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 889 | _list_image_dir_contents(self.update_url) |
Dale Curtis | 1e97318 | 2011-07-12 18:21:36 -0700 | [diff] [blame] | 890 | raise |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 891 | |
| 892 | |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 893 | def _complete_update(self, expected_kernel): |
| 894 | """Finish the update, and confirm that it succeeded. |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 895 | |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 896 | Initial condition is that the target build has been downloaded |
| 897 | and installed on the DUT, but has not yet been booted. This |
| 898 | function is responsible for rebooting the DUT, and checking that |
| 899 | the new build is running successfully. |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 900 | |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 901 | @param expected_kernel: kernel expected to be active after reboot. |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 902 | """ |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 903 | # Regarding the 'crossystem' command below: In some cases, |
| 904 | # the update flow puts the TPM into a state such that it |
| 905 | # fails verification. We don't know why. However, this |
| 906 | # call papers over the problem by clearing the TPM during |
| 907 | # the reboot. |
| 908 | # |
| 909 | # We ignore failures from 'crossystem'. Although failure |
| 910 | # here is unexpected, and could signal a bug, the point of |
| 911 | # the exercise is to paper over problems; allowing this to |
| 912 | # fail would defeat the purpose. |
| 913 | self._run('crossystem clear_tpm_owner_request=1', |
| 914 | ignore_status=True) |
| 915 | self.host.reboot(timeout=self.host.REBOOT_TIMEOUT) |
| 916 | |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 917 | # Touch the lab machine file to leave a marker that |
| 918 | # distinguishes this image from other test images. |
| 919 | # Afterwards, we must re-run the autoreboot script because |
| 920 | # it depends on the _LAB_MACHINE_FILE. |
| 921 | autoreboot_cmd = ('FILE="%s" ; [ -f "$FILE" ] || ' |
| 922 | '( touch "$FILE" ; start autoreboot )') |
Richard Barnette | 3e8b228 | 2018-05-15 20:42:20 +0000 | [diff] [blame] | 923 | self._run(autoreboot_cmd % _LAB_MACHINE_FILE) |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 924 | self.verify_boot_expectations( |
| 925 | expected_kernel, rollback_message= |
| 926 | 'Build %s failed to boot on %s; system rolled back to previous ' |
| 927 | 'build' % (self.update_version, self.host.hostname)) |
| 928 | |
| 929 | logging.debug('Cleaning up old autotest directories.') |
| 930 | try: |
| 931 | installed_autodir = autotest.Autotest.get_installed_autodir( |
| 932 | self.host) |
| 933 | self._run('rm -rf ' + installed_autodir) |
| 934 | except autotest.AutodirNotFoundError: |
| 935 | logging.debug('No autotest installed directory found.') |
| 936 | |
| 937 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 938 | def _run_update_steps(self): |
| 939 | """Perform a full update of a DUT, with diagnosis for failures. |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 940 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 941 | Run the individual steps of the update. If a step fails, make |
| 942 | sure that the exception raised describes the failure with a |
| 943 | diagnosis based on the step that failed. |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 944 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 945 | @raise HostUpdateError if a failure is caused by a problem on |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 946 | the DUT prior to the update. |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 947 | @raise ImageInstallError if a failure occurs during download |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 948 | and install of the update and cannot be definitively |
| 949 | blamed on either the DUT or the devserver. |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 950 | @raise NewBuildUpdateError if a failure occurs because the |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 951 | new build fails to function correctly. |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 952 | """ |
Richard Barnette | 14ee84c | 2018-05-18 20:23:42 +0000 | [diff] [blame] | 953 | self._verify_devserver() |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 954 | |
| 955 | try: |
| 956 | self._prepare_host() |
| 957 | except _AttributedUpdateError: |
| 958 | raise |
| 959 | except Exception as e: |
| 960 | logging.exception('Failure preparing host prior to update.') |
| 961 | raise HostUpdateError(self.host.hostname, str(e)) |
| 962 | |
| 963 | try: |
| 964 | expected_kernel = self._install_update() |
| 965 | except _AttributedUpdateError: |
| 966 | raise |
| 967 | except Exception as e: |
| 968 | logging.exception('Failure during download and install.') |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 969 | server_name = dev_server.get_resolved_hostname(self.update_url) |
Richard Barnette | 9d43e56 | 2018-06-05 17:20:10 +0000 | [diff] [blame] | 970 | raise ImageInstallError(self.host.hostname, server_name, str(e)) |
| 971 | |
| 972 | try: |
| 973 | self._complete_update(expected_kernel) |
| 974 | except _AttributedUpdateError: |
| 975 | raise |
| 976 | except Exception as e: |
| 977 | logging.exception('Failure from build after update.') |
| 978 | raise NewBuildUpdateError(self.update_version, str(e)) |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 979 | |
Richard Barnette | 621a8e4 | 2018-06-25 17:34:11 -0700 | [diff] [blame] | 980 | |
| 981 | def run_update(self): |
| 982 | """Perform a full update of a DUT in the test lab. |
| 983 | |
| 984 | This downloads and installs the root FS and stateful partition |
| 985 | content needed for the update specified in `self.host` and |
| 986 | `self.update_url`. The update is performed according to the |
| 987 | requirements for provisioning a DUT for testing the requested |
| 988 | build. |
| 989 | |
| 990 | At the end of the procedure, metrics are reported describing the |
| 991 | outcome of the operation. |
| 992 | |
| 993 | @returns A tuple of the form `(image_name, attributes)`, where |
| 994 | `image_name` is the name of the image installed, and |
| 995 | `attributes` is new attributes to be applied to the DUT. |
| 996 | """ |
| 997 | start_time = time.time() |
| 998 | failure_reason = None |
| 999 | server_name = dev_server.get_resolved_hostname(self.update_url) |
| 1000 | metrics.Counter(_metric_name('install')).increment( |
| 1001 | fields={'devserver': server_name}) |
| 1002 | try: |
| 1003 | self._run_update_steps() |
| 1004 | except _AttributedUpdateError as e: |
| 1005 | failure_reason = e.failure_summary |
| 1006 | raise |
| 1007 | except Exception as e: |
| 1008 | failure_reason = 'Unknown failure' |
| 1009 | raise |
| 1010 | finally: |
| 1011 | end_time = time.time() |
| 1012 | _emit_provision_metrics( |
| 1013 | self.update_url, self.host.hostname, |
| 1014 | failure_reason, end_time - start_time) |
| 1015 | |
Richard Barnette | 0beb14b | 2018-05-15 18:07:52 +0000 | [diff] [blame] | 1016 | image_name = url_to_image_name(self.update_url) |
| 1017 | # update_url is different from devserver url needed to stage autotest |
| 1018 | # packages, therefore, resolve a new devserver url here. |
| 1019 | devserver_url = dev_server.ImageServer.resolve( |
| 1020 | image_name, self.host.hostname).url() |
| 1021 | repo_url = tools.get_package_url(devserver_url, image_name) |
| 1022 | return image_name, {ds_constants.JOB_REPO_URL: repo_url} |