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