Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 5 | import collections |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 6 | import re |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 7 | import sys |
Allen Li | aaabda8 | 2017-02-21 18:27:38 -0800 | [diff] [blame] | 8 | import warnings |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 9 | |
| 10 | import common |
Fang Deng | af30e7c | 2014-11-15 13:57:03 -0800 | [diff] [blame] | 11 | from autotest_lib.server.cros import provision_actionables as actionables |
Allen Li | 89711f7 | 2017-02-21 18:21:52 -0800 | [diff] [blame] | 12 | from autotest_lib.utils import labellib |
| 13 | from autotest_lib.utils.labellib import Key |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | ### Constants for label prefixes |
Allen Li | 89711f7 | 2017-02-21 18:21:52 -0800 | [diff] [blame] | 17 | CROS_VERSION_PREFIX = Key.CROS_VERSION |
Rohit Makasana | 37f5cf0 | 2017-06-08 17:21:25 -0700 | [diff] [blame] | 18 | CROS_TH_VERSION_PREFIX = Key.CROS_TH_VERSION |
Allen Li | 89711f7 | 2017-02-21 18:21:52 -0800 | [diff] [blame] | 19 | ANDROID_BUILD_VERSION_PREFIX = Key.ANDROID_BUILD_VERSION |
| 20 | TESTBED_BUILD_VERSION_PREFIX = Key.TESTBED_VERSION |
| 21 | FW_RW_VERSION_PREFIX = Key.FIRMWARE_RW_VERSION |
| 22 | FW_RO_VERSION_PREFIX = Key.FIRMWARE_RO_VERSION |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 23 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 24 | _ANDROID_BUILD_REGEX = r'.+/.+/P?([0-9]+|LATEST)' |
| 25 | _ANDROID_TESTBED_BUILD_REGEX = _ANDROID_BUILD_REGEX + '(,|(#[0-9]+))' |
Rohit Makasana | 37f5cf0 | 2017-06-08 17:21:25 -0700 | [diff] [blame] | 26 | _CROS_TH_BUILD_REGEX = r'.+-release/.+;.+/.+/P?[0-9]+$' |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 27 | |
Dan Shi | e44f9c0 | 2016-02-18 13:25:05 -0800 | [diff] [blame] | 28 | # Special label to skip provision and run reset instead. |
| 29 | SKIP_PROVISION = 'skip_provision' |
| 30 | |
Chris Sosa | e92399e | 2015-04-24 11:32:59 -0700 | [diff] [blame] | 31 | # Default number of provisions attempts to try if we believe the devserver is |
| 32 | # flaky. |
| 33 | FLAKY_DEVSERVER_ATTEMPTS = 2 |
| 34 | |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 35 | |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 36 | _Action = collections.namedtuple('_Action', 'name, value') |
| 37 | |
| 38 | |
| 39 | def _get_label_action(str_label): |
| 40 | """Get action represented by the label. |
| 41 | |
| 42 | This is used for determine actions to perform based on labels, for |
| 43 | example for provisioning or repair. |
| 44 | |
| 45 | @param str_label: label string |
| 46 | @returns: _Action instance |
| 47 | """ |
| 48 | try: |
| 49 | keyval_label = labellib.parse_keyval_label(str_label) |
| 50 | except ValueError: |
| 51 | return _Action(str_label, None) |
| 52 | else: |
| 53 | return _Action(keyval_label.key, keyval_label.value) |
| 54 | |
| 55 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 56 | ### Helpers to convert value to label |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 57 | def get_version_label_prefix(image): |
| 58 | """ |
| 59 | Determine a version label prefix from a given image name. |
| 60 | |
| 61 | Parses `image` to determine what kind of image it refers |
| 62 | to, and returns the corresponding version label prefix. |
| 63 | |
| 64 | Known version label prefixes are: |
| 65 | * `CROS_VERSION_PREFIX` for Chrome OS version strings. |
| 66 | These images have names like `cave-release/R57-9030.0.0`. |
Rohit Makasana | 37f5cf0 | 2017-06-08 17:21:25 -0700 | [diff] [blame] | 67 | * `CROS_TH_VERSION_PREFIX` for Chrome OS ARC TH version strings. |
| 68 | These images have names like |
| 69 | `cyan-release/R60-9517.0.0;git_nyc-arc/cheets_x86-user/3512523`. |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 70 | * `ANDROID_BUILD_VERSION_PREFIX` for Android build versions |
| 71 | These images have names like |
| 72 | `git_mnc-release/shamu-userdebug/2457013`. |
| 73 | * `TESTBED_BUILD_VERSION_PREFIX` for Android testbed version |
| 74 | specifications. These are either comma separated lists of |
| 75 | Android versions, or an Android version with a suffix like |
| 76 | '#2', indicating two devices running the given build. |
| 77 | |
| 78 | @param image: The image name to be parsed. |
| 79 | @returns: A string that is the prefix of version labels for the type |
| 80 | of image identified by `image`. |
| 81 | |
| 82 | """ |
| 83 | if re.match(_ANDROID_TESTBED_BUILD_REGEX, image, re.I): |
| 84 | return TESTBED_BUILD_VERSION_PREFIX |
| 85 | elif re.match(_ANDROID_BUILD_REGEX, image, re.I): |
| 86 | return ANDROID_BUILD_VERSION_PREFIX |
Rohit Makasana | 37f5cf0 | 2017-06-08 17:21:25 -0700 | [diff] [blame] | 87 | elif re.match(_CROS_TH_BUILD_REGEX, image, re.I): |
| 88 | return CROS_TH_VERSION_PREFIX |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 89 | else: |
| 90 | return CROS_VERSION_PREFIX |
| 91 | |
| 92 | |
| 93 | def image_version_to_label(image): |
| 94 | """ |
| 95 | Return a version label appropriate to the given image name. |
| 96 | |
| 97 | The type of version label is as determined described for |
| 98 | `get_version_label_prefix()`, meaning the label will identify a |
| 99 | CrOS, Android, or Testbed version. |
| 100 | |
| 101 | @param image: The image name to be parsed. |
| 102 | @returns: A string that is the appropriate label name. |
| 103 | |
| 104 | """ |
| 105 | return get_version_label_prefix(image) + ':' + image |
| 106 | |
| 107 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 108 | def fwro_version_to_label(image): |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 109 | """ |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 110 | Returns the proper label name for a RO firmware build of |image|. |
Tom Wai-Hong Tam | 2d00cb2 | 2016-01-08 06:40:50 +0800 | [diff] [blame] | 111 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 112 | @param image: A string of the form 'lumpy-release/R28-3993.0.0' |
| 113 | @returns: A string that is the appropriate label name. |
Tom Wai-Hong Tam | 2d00cb2 | 2016-01-08 06:40:50 +0800 | [diff] [blame] | 114 | |
| 115 | """ |
Allen Li | aaabda8 | 2017-02-21 18:27:38 -0800 | [diff] [blame] | 116 | warnings.warn('fwro_version_to_label is deprecated', stacklevel=2) |
| 117 | keyval_label = labellib.KeyvalLabel(Key.FIRMWARE_RO_VERSION, image) |
| 118 | return labellib.format_keyval_label(keyval_label) |
Tom Wai-Hong Tam | 2d00cb2 | 2016-01-08 06:40:50 +0800 | [diff] [blame] | 119 | |
| 120 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 121 | def fwrw_version_to_label(image): |
| 122 | """ |
| 123 | Returns the proper label name for a RW firmware build of |image|. |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 124 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 125 | @param image: A string of the form 'lumpy-release/R28-3993.0.0' |
| 126 | @returns: A string that is the appropriate label name. |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 127 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 128 | """ |
Allen Li | aaabda8 | 2017-02-21 18:27:38 -0800 | [diff] [blame] | 129 | warnings.warn('fwrw_version_to_label is deprecated', stacklevel=2) |
| 130 | keyval_label = labellib.KeyvalLabel(Key.FIRMWARE_RW_VERSION, image) |
| 131 | return labellib.format_keyval_label(keyval_label) |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 132 | |
| 133 | |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 134 | class _SpecialTaskAction(object): |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 135 | """ |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 136 | Base class to give a template for mapping labels to tests. |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 137 | """ |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 138 | |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 139 | # A dictionary mapping labels to test names. |
| 140 | _actions = {} |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 141 | |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 142 | # The name of this special task to be used in output. |
| 143 | name = None; |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 144 | |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 145 | # Some special tasks require to run before others, e.g., ChromeOS image |
| 146 | # needs to be updated before firmware provision. List `_priorities` defines |
| 147 | # the order of each label prefix. An element with a smaller index has higher |
| 148 | # priority. Not listed ones have the lowest priority. |
| 149 | # This property should be overriden in subclass to define its own priorities |
| 150 | # across available label prefixes. |
| 151 | _priorities = [] |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 152 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 153 | |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 154 | @classmethod |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 155 | def acts_on(cls, label): |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 156 | """ |
| 157 | Returns True if the label is a label that we recognize as something we |
| 158 | know how to act on, given our _actions. |
| 159 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 160 | @param label: The label as a string. |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 161 | @returns: True if there exists a test to run for this label. |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 162 | """ |
Allen Li | 95e930a | 2017-02-21 18:31:18 -0800 | [diff] [blame] | 163 | action = _get_label_action(label) |
| 164 | return action.name in cls._actions |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 165 | |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 166 | |
| 167 | @classmethod |
Allen Li | 2115458 | 2017-02-22 18:00:42 -0800 | [diff] [blame] | 168 | def run_task_actions(cls, job, host, labels): |
| 169 | """ |
| 170 | Run task actions on host that correspond to the labels. |
| 171 | |
| 172 | Emits status lines for each run test, and INFO lines for each |
| 173 | skipped label. |
| 174 | |
| 175 | @param job: A job object from a control file. |
| 176 | @param host: The host to run actions on. |
| 177 | @param labels: The list of job labels to work on. |
| 178 | @raises: SpecialTaskActionException if a test fails. |
| 179 | """ |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 180 | unactionable = cls._filter_unactionable_labels(labels) |
Allen Li | 2115458 | 2017-02-22 18:00:42 -0800 | [diff] [blame] | 181 | for label in unactionable: |
| 182 | job.record('INFO', None, cls.name, |
| 183 | "Can't %s label '%s'." % (cls.name, label)) |
| 184 | |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 185 | for action_item, value in cls._actions_and_values_iter(labels): |
Allen Li | 2115458 | 2017-02-22 18:00:42 -0800 | [diff] [blame] | 186 | success = action_item.execute(job=job, host=host, value=value) |
| 187 | if not success: |
| 188 | raise SpecialTaskActionException() |
| 189 | |
| 190 | |
| 191 | @classmethod |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 192 | def _actions_and_values_iter(cls, labels): |
| 193 | """Return sorted action and value pairs to run for labels. |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 194 | |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 195 | @params: An iterable of label strings. |
| 196 | @returns: A generator of Actionable and value pairs. |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 197 | """ |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 198 | actionable = cls._filter_actionable_labels(labels) |
| 199 | keyval_mapping = labellib.LabelsMapping(actionable) |
| 200 | sorted_names = sorted(keyval_mapping, key=cls._get_action_priority) |
| 201 | for name in sorted_names: |
| 202 | action_item = cls._actions[name] |
| 203 | value = keyval_mapping[name] |
| 204 | yield action_item, value |
| 205 | |
| 206 | |
| 207 | @classmethod |
| 208 | def _filter_unactionable_labels(cls, labels): |
| 209 | """ |
| 210 | Return labels that we cannot act on. |
| 211 | |
| 212 | @param labels: A list of strings of labels. |
| 213 | @returns: A set of unactionable labels |
| 214 | """ |
| 215 | return {label for label in labels |
| 216 | if not (label == SKIP_PROVISION or cls.acts_on(label))} |
| 217 | |
| 218 | |
| 219 | @classmethod |
| 220 | def _filter_actionable_labels(cls, labels): |
| 221 | """ |
| 222 | Return labels that we can act on. |
| 223 | |
| 224 | @param labels: A list of strings of labels. |
| 225 | @returns: A set of actionable labels |
| 226 | """ |
| 227 | return {label for label in labels if cls.acts_on(label)} |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 228 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 229 | |
Alex Miller | aa77200 | 2014-04-10 17:51:21 -0700 | [diff] [blame] | 230 | @classmethod |
| 231 | def partition(cls, labels): |
| 232 | """ |
| 233 | Filter a list of labels into two sets: those labels that we know how to |
| 234 | act on and those that we don't know how to act on. |
| 235 | |
| 236 | @param labels: A list of strings of labels. |
| 237 | @returns: A tuple where the first element is a set of unactionable |
| 238 | labels, and the second element is a set of the actionable |
| 239 | labels. |
| 240 | """ |
Allen Li | 5b62312 | 2017-02-22 17:42:02 -0800 | [diff] [blame] | 241 | unactionable = set() |
| 242 | actionable = set() |
Alex Miller | aa77200 | 2014-04-10 17:51:21 -0700 | [diff] [blame] | 243 | |
| 244 | for label in labels: |
Dan Shi | e44f9c0 | 2016-02-18 13:25:05 -0800 | [diff] [blame] | 245 | if label == SKIP_PROVISION: |
| 246 | # skip_provision is neither actionable or a capability label. |
| 247 | # It doesn't need any handling. |
| 248 | continue |
| 249 | elif cls.acts_on(label): |
Allen Li | 5b62312 | 2017-02-22 17:42:02 -0800 | [diff] [blame] | 250 | actionable.add(label) |
Alex Miller | aa77200 | 2014-04-10 17:51:21 -0700 | [diff] [blame] | 251 | else: |
Allen Li | 5b62312 | 2017-02-22 17:42:02 -0800 | [diff] [blame] | 252 | unactionable.add(label) |
Alex Miller | aa77200 | 2014-04-10 17:51:21 -0700 | [diff] [blame] | 253 | |
Allen Li | 5b62312 | 2017-02-22 17:42:02 -0800 | [diff] [blame] | 254 | return unactionable, actionable |
Alex Miller | aa77200 | 2014-04-10 17:51:21 -0700 | [diff] [blame] | 255 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 256 | |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 257 | @classmethod |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 258 | def _get_action_priority(cls, name): |
| 259 | """Return priority for the action with the given name.""" |
| 260 | if name in cls._priorities: |
| 261 | return cls._priorities.index(name) |
| 262 | else: |
| 263 | return sys.maxint |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 264 | |
| 265 | |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 266 | class Verify(_SpecialTaskAction): |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 267 | """ |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 268 | Tests to verify that the DUT is in a sane, known good state that we can run |
| 269 | tests on. Failure to verify leads to running Repair. |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 270 | """ |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 271 | |
| 272 | _actions = { |
Fang Deng | af30e7c | 2014-11-15 13:57:03 -0800 | [diff] [blame] | 273 | 'modem_repair': actionables.TestActionable('cellular_StaleModemReboot'), |
Don Garrett | 6f7e800 | 2015-07-23 22:45:37 +0000 | [diff] [blame] | 274 | # TODO(crbug.com/404421): set rpm action to power_RPMTest after the RPM |
| 275 | # is stable in lab (destiny). The power_RPMTest failure led to reset job |
| 276 | # failure and that left dut in Repair Failed. Since the test will fail |
| 277 | # anyway due to the destiny lab issue, and test retry will retry the |
| 278 | # test in another DUT. |
| 279 | # This change temporarily disable the RPM check in reset job. |
| 280 | # Another way to do this is to remove rpm dependency from tests' control |
| 281 | # file. That will involve changes on multiple control files. This one |
| 282 | # line change here is a simple temporary fix. |
| 283 | 'rpm': actionables.TestActionable('dummy_PassServer'), |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | name = 'verify' |
| 287 | |
| 288 | |
| 289 | class Provision(_SpecialTaskAction): |
| 290 | """ |
| 291 | Provisioning runs to change the configuration of the DUT from one state to |
| 292 | another. It will only be run on verified DUTs. |
| 293 | """ |
| 294 | |
Dan Shi | 7279a5a | 2016-04-07 11:04:28 -0700 | [diff] [blame] | 295 | # ChromeOS update must happen before firmware install, so the dut has the |
| 296 | # correct ChromeOS version label when firmware install occurs. The ChromeOS |
| 297 | # version label is used for firmware update to stage desired ChromeOS image |
| 298 | # on to the servo USB stick. |
| 299 | _priorities = [CROS_VERSION_PREFIX, |
| 300 | FW_RO_VERSION_PREFIX, |
| 301 | FW_RW_VERSION_PREFIX] |
| 302 | |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 303 | # TODO(milleral): http://crbug.com/249555 |
| 304 | # Create some way to discover and register provisioning tests so that we |
| 305 | # don't need to hand-maintain a list of all of them. |
| 306 | _actions = { |
Fang Deng | 9d54874 | 2015-02-03 11:35:02 -0800 | [diff] [blame] | 307 | CROS_VERSION_PREFIX: actionables.TestActionable( |
| 308 | 'provision_AutoUpdate', |
| 309 | extra_kwargs={'disable_sysinfo': False, |
| 310 | 'disable_before_test_sysinfo': False, |
| 311 | 'disable_before_iteration_sysinfo': True, |
| 312 | 'disable_after_test_sysinfo': True, |
| 313 | 'disable_after_iteration_sysinfo': True}), |
Rohit Makasana | 37f5cf0 | 2017-06-08 17:21:25 -0700 | [diff] [blame] | 314 | CROS_TH_VERSION_PREFIX : actionables.TestActionable( |
| 315 | 'provision_CheetsUpdate'), |
Tom Wai-Hong Tam | 9a23761 | 2016-01-08 03:41:46 +0800 | [diff] [blame] | 316 | FW_RO_VERSION_PREFIX: actionables.TestActionable( |
Fang Deng | af30e7c | 2014-11-15 13:57:03 -0800 | [diff] [blame] | 317 | 'provision_FirmwareUpdate'), |
Tom Wai-Hong Tam | 9a23761 | 2016-01-08 03:41:46 +0800 | [diff] [blame] | 318 | FW_RW_VERSION_PREFIX: actionables.TestActionable( |
| 319 | 'provision_FirmwareUpdate', |
Dan Shi | 61e407c | 2016-04-08 14:21:07 -0700 | [diff] [blame] | 320 | extra_kwargs={'rw_only': True, |
| 321 | 'tag': 'rw_only'}), |
Simran Basi | 5ace6f2 | 2016-01-06 17:30:44 -0800 | [diff] [blame] | 322 | ANDROID_BUILD_VERSION_PREFIX : actionables.TestActionable( |
| 323 | 'provision_AndroidUpdate'), |
Simran Basi | adf3131 | 2016-06-28 14:23:05 -0700 | [diff] [blame] | 324 | TESTBED_BUILD_VERSION_PREFIX : actionables.TestActionable( |
| 325 | 'provision_TestbedUpdate'), |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | name = 'provision' |
| 329 | |
| 330 | |
| 331 | class Cleanup(_SpecialTaskAction): |
| 332 | """ |
| 333 | Cleanup runs after a test fails to try and remove artifacts of tests and |
| 334 | ensure the DUT will be in a sane state for the next test run. |
| 335 | """ |
| 336 | |
| 337 | _actions = { |
Fang Deng | af30e7c | 2014-11-15 13:57:03 -0800 | [diff] [blame] | 338 | 'cleanup-reboot': actionables.RebootActionable(), |
Alex Miller | 1968edf | 2014-02-27 18:11:36 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | name = 'cleanup' |
| 342 | |
| 343 | |
| 344 | class Repair(_SpecialTaskAction): |
| 345 | """ |
| 346 | Repair runs when one of the other special tasks fails. It should be able |
| 347 | to take a component of the DUT that's in an unknown state and restore it to |
| 348 | a good state. |
| 349 | """ |
| 350 | |
| 351 | _actions = { |
| 352 | } |
| 353 | |
| 354 | name = 'repair' |
| 355 | |
| 356 | |
Alex Miller | aa77200 | 2014-04-10 17:51:21 -0700 | [diff] [blame] | 357 | # TODO(milleral): crbug.com/364273 |
| 358 | # Label doesn't really mean label in this context. We're putting things into |
| 359 | # DEPENDENCIES that really aren't DEPENDENCIES, and we should probably stop |
| 360 | # doing that. |
| 361 | def is_for_special_action(label): |
| 362 | """ |
| 363 | If any special task handles the label specially, then we're using the label |
| 364 | to communicate that we want an action, and not as an actual dependency that |
| 365 | the test has. |
| 366 | |
| 367 | @param label: A string label name. |
| 368 | @return True if any special task handles this label specially, |
| 369 | False if no special task handles this label. |
| 370 | """ |
| 371 | return (Verify.acts_on(label) or |
| 372 | Provision.acts_on(label) or |
| 373 | Cleanup.acts_on(label) or |
Dan Shi | e44f9c0 | 2016-02-18 13:25:05 -0800 | [diff] [blame] | 374 | Repair.acts_on(label) or |
| 375 | label == SKIP_PROVISION) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 376 | |
| 377 | |
Prathmesh Prabhu | 2c7471d | 2016-11-15 20:19:57 +0000 | [diff] [blame] | 378 | def join(provision_type, provision_value): |
| 379 | """ |
| 380 | Combine the provision type and value into the label name. |
| 381 | |
| 382 | @param provision_type: One of the constants that are the label prefixes. |
| 383 | @param provision_value: A string of the value for this provision type. |
| 384 | @returns: A string that is the label name for this (type, value) pair. |
| 385 | |
| 386 | >>> join(CROS_VERSION_PREFIX, 'lumpy-release/R27-3773.0.0') |
| 387 | 'cros-version:lumpy-release/R27-3773.0.0' |
| 388 | |
| 389 | """ |
| 390 | return '%s:%s' % (provision_type, provision_value) |
| 391 | |
| 392 | |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 393 | class SpecialTaskActionException(Exception): |
| 394 | """ |
| 395 | Exception raised when a special task fails to successfully run a test that |
| 396 | is required. |
| 397 | |
| 398 | This is also a literally meaningless exception. It's always just discarded. |
| 399 | """ |
| 400 | |
| 401 | |
| 402 | def run_special_task_actions(job, host, labels, task): |
| 403 | """ |
| 404 | Iterate through all `label`s and run any tests on `host` that `task` has |
| 405 | corresponding to the passed in labels. |
| 406 | |
| 407 | Emits status lines for each run test, and INFO lines for each skipped label. |
| 408 | |
| 409 | @param job: A job object from a control file. |
| 410 | @param host: The host to run actions on. |
| 411 | @param labels: The list of job labels to work on. |
| 412 | @param task: An instance of _SpecialTaskAction. |
| 413 | @returns: None |
| 414 | @raises: SpecialTaskActionException if a test fails. |
| 415 | |
| 416 | """ |
Allen Li | d575f64 | 2017-05-23 13:07:28 -0700 | [diff] [blame] | 417 | warnings.warn('run_special_task_actions is deprecated', stacklevel=2) |
Allen Li | 2115458 | 2017-02-22 18:00:42 -0800 | [diff] [blame] | 418 | task.run_task_actions(job, host, labels) |