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