Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 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 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 5 | |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 6 | import logging |
| 7 | import re |
| 8 | import subprocess |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 9 | |
| 10 | import base_event |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 11 | import deduping_scheduler |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 12 | import driver |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 13 | import manifest_versions |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 14 | from distutils import version |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 15 | from constants import Labels |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 16 | from constants import Builds |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 17 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 18 | import common |
Fang Deng | f08814a | 2015-08-03 18:12:18 +0000 | [diff] [blame] | 19 | from autotest_lib.server import utils as server_utils |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 20 | from autotest_lib.server.cros.dynamic_suite import constants |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 21 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 22 | OS_TYPE_CROS = 'cros' |
| 23 | OS_TYPE_BRILLO = 'brillo' |
| 24 | OS_TYPE_ANDROID = 'android' |
| 25 | OS_TYPES = {OS_TYPE_CROS, OS_TYPE_BRILLO, OS_TYPE_ANDROID} |
| 26 | OS_TYPES_LAUNCH_CONTROL = {OS_TYPE_BRILLO, OS_TYPE_ANDROID} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 27 | |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame^] | 28 | _WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', |
| 29 | 'Sunday'] |
| 30 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 31 | class MalformedConfigEntry(Exception): |
| 32 | """Raised to indicate a failure to parse a Task out of a config.""" |
| 33 | pass |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 34 | |
| 35 | |
Alex Miller | 0d00357 | 2013-03-18 11:51:30 -0700 | [diff] [blame] | 36 | BARE_BRANCHES = ['factory', 'firmware'] |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def PickBranchName(type, milestone): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 40 | """Pick branch name. If type is among BARE_BRANCHES, return type, |
| 41 | otherwise, return milestone. |
| 42 | |
| 43 | @param type: type of the branch, e.g., 'release', 'factory', or 'firmware' |
| 44 | @param milestone: CrOS milestone number |
| 45 | """ |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 46 | if type in BARE_BRANCHES: |
| 47 | return type |
| 48 | return milestone |
| 49 | |
| 50 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 51 | class TotMilestoneManager(object): |
| 52 | """A class capable of converting tot string to milestone numbers. |
| 53 | |
| 54 | This class is used as a cache for the tot milestone, so we don't |
| 55 | repeatedly hit google storage for all O(100) tasks in suite |
| 56 | scheduler's ini file. |
| 57 | """ |
| 58 | |
Fang Deng | f08814a | 2015-08-03 18:12:18 +0000 | [diff] [blame] | 59 | __metaclass__ = server_utils.Singleton |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 60 | |
Dan Shi | 2324514 | 2015-01-22 13:22:28 -0800 | [diff] [blame] | 61 | # True if suite_scheduler is running for sanity check. When it's set to |
| 62 | # True, the code won't make gsutil call to get the actual tot milestone to |
| 63 | # avoid dependency on the installation of gsutil to run sanity check. |
| 64 | is_sanity = False |
| 65 | |
| 66 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 67 | @staticmethod |
| 68 | def _tot_milestone(): |
| 69 | """Get the tot milestone, eg: R40 |
| 70 | |
| 71 | @returns: A string representing the Tot milestone as declared by |
| 72 | the LATEST_BUILD_URL, or an empty string if LATEST_BUILD_URL |
| 73 | doesn't exist. |
| 74 | """ |
Dan Shi | 2324514 | 2015-01-22 13:22:28 -0800 | [diff] [blame] | 75 | if TotMilestoneManager.is_sanity: |
| 76 | logging.info('suite_scheduler is running for sanity purpose, no ' |
| 77 | 'need to get the actual tot milestone string.') |
| 78 | return 'R40' |
| 79 | |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 80 | cmd = ['gsutil', 'cat', constants.LATEST_BUILD_URL] |
| 81 | proc = subprocess.Popen( |
| 82 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 83 | stdout, stderr = proc.communicate() |
| 84 | if proc.poll(): |
| 85 | logging.warning('Failed to get latest build: %s', stderr) |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 86 | return '' |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 87 | return stdout.split('-')[0] |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 88 | |
| 89 | |
| 90 | def refresh(self): |
| 91 | """Refresh the tot milestone string managed by this class.""" |
| 92 | self.tot = self._tot_milestone() |
| 93 | |
| 94 | |
| 95 | def __init__(self): |
| 96 | """Initialize a TotMilestoneManager.""" |
| 97 | self.refresh() |
| 98 | |
| 99 | |
| 100 | def ConvertTotSpec(self, tot_spec): |
| 101 | """Converts a tot spec to the appropriate milestone. |
| 102 | |
| 103 | Assume tot is R40: |
| 104 | tot -> R40 |
| 105 | tot-1 -> R39 |
| 106 | tot-2 -> R38 |
| 107 | tot-(any other numbers) -> R40 |
| 108 | |
| 109 | With the last option one assumes that a malformed configuration that has |
| 110 | 'tot' in it, wants at least tot. |
| 111 | |
| 112 | @param tot_spec: A string representing the tot spec. |
| 113 | @raises MalformedConfigEntry: If the tot_spec doesn't match the |
| 114 | expected format. |
| 115 | """ |
| 116 | tot_spec = tot_spec.lower() |
| 117 | match = re.match('(tot)[-]?(1$|2$)?', tot_spec) |
| 118 | if not match: |
| 119 | raise MalformedConfigEntry( |
| 120 | "%s isn't a valid branch spec." % tot_spec) |
| 121 | tot_mstone = self.tot |
| 122 | num_back = match.groups()[1] |
| 123 | if num_back: |
| 124 | tot_mstone_num = tot_mstone.lstrip('R') |
| 125 | tot_mstone = tot_mstone.replace( |
| 126 | tot_mstone_num, str(int(tot_mstone_num)-int(num_back))) |
| 127 | return tot_mstone |
| 128 | |
| 129 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 130 | class Task(object): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 131 | """Represents an entry from the scheduler config. Can schedule itself. |
| 132 | |
| 133 | Each entry from the scheduler config file maps one-to-one to a |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 134 | Task. Each instance has enough info to schedule itself |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 135 | on-demand with the AFE. |
| 136 | |
Aviv Keshet | 52c7a21 | 2015-12-07 15:27:22 -0800 | [diff] [blame] | 137 | This class also overrides __hash__() and all comparator methods to enable |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 138 | correct use in dicts, sets, etc. |
| 139 | """ |
| 140 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 141 | |
| 142 | @staticmethod |
| 143 | def CreateFromConfigSection(config, section): |
| 144 | """Create a Task from a section of a config file. |
| 145 | |
| 146 | The section to parse should look like this: |
| 147 | [TaskName] |
| 148 | suite: suite_to_run # Required |
| 149 | run_on: event_on which to run # Required |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 150 | hour: integer of the hour to run, only applies to nightly. # Optional |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 151 | branch_specs: factory,firmware,>=R12 or ==R12 # Optional |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 152 | pool: pool_of_devices # Optional |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 153 | num: sharding_factor # int, Optional |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 154 | boards: board1, board2 # comma seperated string, Optional |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 155 | # Settings for Launch Control builds only: |
| 156 | os_type: brillo # Type of OS, e.g., cros, brillo, android. Default is |
| 157 | cros. Required for android/brillo builds. |
| 158 | branches: git_mnc_release # comma separated string of Launch Control |
| 159 | branches. Required and only applicable for android/brillo |
| 160 | builds. |
| 161 | targets: dragonboard-eng # comma separated string of build targets. |
| 162 | Required and only applicable for android/brillo builds. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 163 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 164 | By default, Tasks run on all release branches, not factory or firmware. |
| 165 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 166 | @param config: a ForgivingConfigParser. |
| 167 | @param section: the section to parse into a Task. |
| 168 | @return keyword, Task object pair. One or both will be None on error. |
| 169 | @raise MalformedConfigEntry if there's a problem parsing |section|. |
| 170 | """ |
Alex Miller | 0669502 | 2012-07-18 09:31:36 -0700 | [diff] [blame] | 171 | if not config.has_section(section): |
| 172 | raise MalformedConfigEntry('unknown section %s' % section) |
| 173 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 174 | allowed = set(['suite', 'run_on', 'branch_specs', 'pool', 'num', |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 175 | 'boards', 'file_bugs', 'cros_build_spec', |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 176 | 'firmware_rw_build_spec', 'firmware_ro_build_spec', |
| 177 | 'test_source', 'job_retry', 'hour', 'day', 'branches', |
| 178 | 'targets', 'os_type']) |
Alex Miller | bb535e2 | 2012-07-11 20:11:33 -0700 | [diff] [blame] | 179 | # The parameter of union() is the keys under the section in the config |
| 180 | # The union merges this with the allowed set, so if any optional keys |
| 181 | # are omitted, then they're filled in. If any extra keys are present, |
| 182 | # then they will expand unioned set, causing it to fail the following |
| 183 | # comparison against the allowed set. |
| 184 | section_headers = allowed.union(dict(config.items(section)).keys()) |
| 185 | if allowed != section_headers: |
| 186 | raise MalformedConfigEntry('unknown entries: %s' % |
| 187 | ", ".join(map(str, section_headers.difference(allowed)))) |
| 188 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 189 | keyword = config.getstring(section, 'run_on') |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 190 | hour = config.getstring(section, 'hour') |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 191 | suite = config.getstring(section, 'suite') |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 192 | branch_specs = config.getstring(section, 'branch_specs') |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 193 | pool = config.getstring(section, 'pool') |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 194 | boards = config.getstring(section, 'boards') |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 195 | file_bugs = config.getboolean(section, 'file_bugs') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 196 | cros_build_spec = config.getstring(section, 'cros_build_spec') |
| 197 | firmware_rw_build_spec = config.getstring( |
| 198 | section, 'firmware_rw_build_spec') |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 199 | firmware_ro_build_spec = config.getstring( |
| 200 | section, 'firmware_ro_build_spec') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 201 | test_source = config.getstring(section, 'test_source') |
Dan Shi | 29a1699 | 2015-09-22 11:29:58 -0700 | [diff] [blame] | 202 | job_retry = config.getboolean(section, 'job_retry') |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 203 | for klass in driver.Driver.EVENT_CLASSES: |
| 204 | if klass.KEYWORD == keyword: |
| 205 | priority = klass.PRIORITY |
| 206 | timeout = klass.TIMEOUT |
| 207 | break |
| 208 | else: |
| 209 | priority = None |
| 210 | timeout = None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 211 | try: |
| 212 | num = config.getint(section, 'num') |
| 213 | except ValueError as e: |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 214 | raise MalformedConfigEntry("Ill-specified 'num': %r" % e) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 215 | if not keyword: |
| 216 | raise MalformedConfigEntry('No event to |run_on|.') |
| 217 | if not suite: |
| 218 | raise MalformedConfigEntry('No |suite|') |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 219 | try: |
| 220 | hour = config.getint(section, 'hour') |
| 221 | except ValueError as e: |
| 222 | raise MalformedConfigEntry("Ill-specified 'hour': %r" % e) |
| 223 | if hour is not None and (hour < 0 or hour > 23): |
| 224 | raise MalformedConfigEntry( |
| 225 | '`hour` must be an integer between 0 and 23.') |
| 226 | if hour is not None and keyword != 'nightly': |
| 227 | raise MalformedConfigEntry( |
| 228 | '`hour` is the trigger time that can only apply to nightly ' |
| 229 | 'event.') |
Dan Shi | ce1f20a | 2016-01-25 17:27:40 -0800 | [diff] [blame] | 230 | |
| 231 | try: |
| 232 | day = config.getint(section, 'day') |
| 233 | except ValueError as e: |
| 234 | raise MalformedConfigEntry("Ill-specified 'day': %r" % e) |
| 235 | if day is not None and (day < 0 or day > 6): |
| 236 | raise MalformedConfigEntry( |
| 237 | '`day` must be an integer between 0 and 6, where 0 is for ' |
| 238 | 'Monday and 6 is for Sunday.') |
| 239 | if day is not None and keyword != 'weekly': |
| 240 | raise MalformedConfigEntry( |
| 241 | '`day` is the trigger of the day of a week, that can only ' |
| 242 | 'apply to weekly events.') |
| 243 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 244 | specs = [] |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 245 | if branch_specs: |
| 246 | specs = re.split('\s*,\s*', branch_specs) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 247 | Task.CheckBranchSpecs(specs) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 248 | |
| 249 | os_type = config.getstring(section, 'os_type') or OS_TYPE_CROS |
| 250 | if os_type not in OS_TYPES: |
| 251 | raise MalformedConfigEntry('`os_type` must be one of %s' % OS_TYPES) |
| 252 | |
| 253 | lc_branches = config.getstring(section, 'branches') |
| 254 | lc_targets = config.getstring(section, 'targets') |
| 255 | if os_type == OS_TYPE_CROS and (lc_branches or lc_targets): |
| 256 | raise MalformedConfigEntry( |
| 257 | '`branches` and `targets` are only supported for Launch ' |
| 258 | 'Control builds, not ChromeOS builds.') |
| 259 | if (os_type in OS_TYPES_LAUNCH_CONTROL and |
| 260 | (not lc_branches or not lc_targets)): |
| 261 | raise MalformedConfigEntry( |
| 262 | '`branches` and `targets` must be specified for Launch ' |
| 263 | 'Control builds.') |
| 264 | if os_type in OS_TYPES_LAUNCH_CONTROL and boards: |
| 265 | raise MalformedConfigEntry( |
| 266 | '`boards` for Launch Control builds are retrieved from ' |
| 267 | '`targets` setting, it should not be set for Launch ' |
| 268 | 'Control builds.') |
| 269 | |
| 270 | # Extract boards from targets list. |
| 271 | if os_type in OS_TYPES_LAUNCH_CONTROL: |
| 272 | boards = '' |
| 273 | for target in lc_targets.split(','): |
| 274 | board_name, _ = server_utils.parse_launch_control_target( |
| 275 | target.strip()) |
| 276 | boards += '%s-%s,' % (os_type, board_name) |
| 277 | boards = boards.strip(',') |
| 278 | |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 279 | return keyword, Task(section, suite, specs, pool, num, boards, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 280 | priority, timeout, |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 281 | file_bugs=file_bugs if file_bugs else False, |
| 282 | cros_build_spec=cros_build_spec, |
| 283 | firmware_rw_build_spec=firmware_rw_build_spec, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 284 | firmware_ro_build_spec=firmware_ro_build_spec, |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 285 | test_source=test_source, job_retry=job_retry, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 286 | hour=hour, day=day, os_type=os_type, |
| 287 | launch_control_branches=lc_branches, |
| 288 | launch_control_targets=lc_targets) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 289 | |
| 290 | |
| 291 | @staticmethod |
| 292 | def CheckBranchSpecs(branch_specs): |
| 293 | """Make sure entries in the list branch_specs are correctly formed. |
| 294 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 295 | We accept any of BARE_BRANCHES in |branch_specs|, as |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 296 | well as _one_ string of the form '>=RXX' or '==RXX', where 'RXX' is a |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 297 | CrOS milestone number. |
| 298 | |
| 299 | @param branch_specs: an iterable of branch specifiers. |
| 300 | @raise MalformedConfigEntry if there's a problem parsing |branch_specs|. |
| 301 | """ |
| 302 | have_seen_numeric_constraint = False |
| 303 | for branch in branch_specs: |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 304 | if branch in BARE_BRANCHES: |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 305 | continue |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 306 | if not have_seen_numeric_constraint: |
| 307 | #TODO(beeps): Why was <= dropped on the floor? |
| 308 | if branch.startswith('>=R') or branch.startswith('==R'): |
| 309 | have_seen_numeric_constraint = True |
| 310 | elif 'tot' in branch: |
| 311 | TotMilestoneManager().ConvertTotSpec( |
| 312 | branch[branch.index('tot'):]) |
| 313 | have_seen_numeric_constraint = True |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 314 | continue |
Chris Masone | 97cf0a7 | 2012-05-16 09:55:52 -0700 | [diff] [blame] | 315 | raise MalformedConfigEntry("%s isn't a valid branch spec." % branch) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 316 | |
| 317 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 318 | def __init__(self, name, suite, branch_specs, pool=None, num=None, |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 319 | boards=None, priority=None, timeout=None, file_bugs=False, |
| 320 | cros_build_spec=None, firmware_rw_build_spec=None, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 321 | firmware_ro_build_spec=None, test_source=None, job_retry=False, |
| 322 | hour=None, day=None, os_type=OS_TYPE_CROS, |
| 323 | launch_control_branches=None, launch_control_targets=None): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 324 | """Constructor |
| 325 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 326 | Given an iterable in |branch_specs|, pre-vetted using CheckBranchSpecs, |
| 327 | we'll store them such that _FitsSpec() can be used to check whether a |
| 328 | given branch 'fits' with the specifications passed in here. |
| 329 | For example, given branch_specs = ['factory', '>=R18'], we'd set things |
| 330 | up so that _FitsSpec() would return True for 'factory', or 'RXX' |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 331 | where XX is a number >= 18. Same check is done for branch_specs = [ |
| 332 | 'factory', '==R18'], which limit the test to only one specific branch. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 333 | |
| 334 | Given branch_specs = ['factory', 'firmware'], _FitsSpec() |
| 335 | would pass only those two specific strings. |
| 336 | |
| 337 | Example usage: |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 338 | t = Task('Name', 'suite', ['factory', '>=R18']) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 339 | t._FitsSpec('factory') # True |
| 340 | t._FitsSpec('R19') # True |
| 341 | t._FitsSpec('R17') # False |
| 342 | t._FitsSpec('firmware') # False |
| 343 | t._FitsSpec('goober') # False |
| 344 | |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 345 | t = Task('Name', 'suite', ['factory', '==R18']) |
| 346 | t._FitsSpec('R19') # False, branch does not equal to 18 |
| 347 | t._FitsSpec('R18') # True |
| 348 | t._FitsSpec('R17') # False |
| 349 | |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 350 | cros_build_spec and firmware_rw_build_spec are set for tests require |
| 351 | firmware update on the dut. Only one of them can be set. |
| 352 | For example: |
| 353 | branch_specs: ==tot |
| 354 | firmware_rw_build_spec: firmware |
| 355 | test_source: cros |
| 356 | This will run test using latest build on firmware branch, and the latest |
| 357 | ChromeOS build on ToT. The test source build is ChromeOS build. |
| 358 | |
| 359 | branch_specs: firmware |
| 360 | cros_build_spec: ==tot-1 |
| 361 | test_source: firmware_rw |
| 362 | This will run test using latest build on firmware branch, and the latest |
| 363 | ChromeOS build on dev channel (ToT-1). The test source build is the |
| 364 | firmware RW build. |
| 365 | |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 366 | branch_specs: ==tot |
| 367 | firmware_rw_build_spec: cros |
| 368 | test_source: cros |
| 369 | This will run test using latest ChromeOS and firmware RW build on ToT. |
| 370 | ChromeOS build on ToT. The test source build is ChromeOS build. |
| 371 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 372 | @param name: name of this task, e.g. 'NightlyPower' |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 373 | @param suite: the name of the suite to run, e.g. 'bvt' |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 374 | @param branch_specs: a pre-vetted iterable of branch specifiers, |
| 375 | e.g. ['>=R18', 'factory'] |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 376 | @param pool: the pool of machines to use for scheduling purposes. |
| 377 | Default: None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 378 | @param num: the number of devices across which to shard the test suite. |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 379 | Type: integer or None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 380 | Default: None |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 381 | @param boards: A comma separated list of boards to run this task on. |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 382 | Default: Run on all boards. |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 383 | @param priority: The string name of a priority from |
| 384 | client.common_lib.priorities.Priority. |
| 385 | @param timeout: The max lifetime of the suite in hours. |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 386 | @param file_bugs: True if bug filing is desired for the suite created |
| 387 | for this task. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 388 | @param cros_build_spec: Spec used to determine the ChromeOS build to |
| 389 | test with a firmware build, e.g., tot, R41 etc. |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 390 | @param firmware_rw_build_spec: Spec used to determine the firmware RW |
| 391 | build test with a ChromeOS build. |
| 392 | @param firmware_ro_build_spec: Spec used to determine the firmware RO |
| 393 | build test with a ChromeOS build. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 394 | @param test_source: The source of test code when firmware will be |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 395 | updated in the test. The value can be `firmware_rw`, |
| 396 | `firmware_ro` or `cros`. |
Dan Shi | 29a1699 | 2015-09-22 11:29:58 -0700 | [diff] [blame] | 397 | @param job_retry: Set to True to enable job-level retry. Default is |
| 398 | False. |
Dan Shi | 9f256d9 | 2016-01-22 00:09:25 -0800 | [diff] [blame] | 399 | @param hour: An integer specifying the hour that a nightly run should |
| 400 | be triggered, default is set to 21. |
Dan Shi | ce1f20a | 2016-01-25 17:27:40 -0800 | [diff] [blame] | 401 | @param day: An integer specifying the day of a week that a weekly run |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 402 | should be triggered, default is set to 5, which is Saturday. |
| 403 | @param os_type: Type of OS, e.g., cros, brillo, android. Default is |
| 404 | cros. The argument is required for android/brillo builds. |
| 405 | @param launch_control_branches: Comma separated string of Launch Control |
| 406 | branches. The argument is required and only applicable for |
| 407 | android/brillo builds. |
| 408 | @param launch_control_targets: Comma separated string of build targets |
| 409 | for Launch Control builds. The argument is required and only |
| 410 | applicable for android/brillo builds. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 411 | """ |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 412 | self._name = name |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 413 | self._suite = suite |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 414 | self._branch_specs = branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 415 | self._pool = pool |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 416 | self._num = num |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 417 | self._priority = priority |
| 418 | self._timeout = timeout |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 419 | self._file_bugs = file_bugs |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 420 | self._cros_build_spec = cros_build_spec |
| 421 | self._firmware_rw_build_spec = firmware_rw_build_spec |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 422 | self._firmware_ro_build_spec = firmware_ro_build_spec |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 423 | self._test_source = test_source |
Dan Shi | 29a1699 | 2015-09-22 11:29:58 -0700 | [diff] [blame] | 424 | self._job_retry = job_retry |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 425 | self._hour = hour |
| 426 | self._day = day |
| 427 | self._os_type = os_type |
| 428 | self._launch_control_branches = ( |
| 429 | [b.strip() for b in launch_control_branches.split(',')] |
| 430 | if launch_control_branches else []) |
| 431 | self._launch_control_targets = ( |
| 432 | [t.strip() for t in launch_control_targets.split(',')] |
| 433 | if launch_control_targets else []) |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 434 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 435 | if ((self._firmware_rw_build_spec or self._firmware_ro_build_spec or |
| 436 | cros_build_spec) and |
| 437 | not self.test_source in [Builds.FIRMWARE_RW, Builds.FIRMWARE_RO, |
| 438 | Builds.CROS]): |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 439 | raise MalformedConfigEntry( |
| 440 | 'You must specify the build for test source. It can only ' |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 441 | 'be `firmware_rw`, `firmware_ro` or `cros`.') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 442 | if self._firmware_rw_build_spec and cros_build_spec: |
| 443 | raise MalformedConfigEntry( |
| 444 | 'You cannot specify both firmware_rw_build_spec and ' |
| 445 | 'cros_build_spec. firmware_rw_build_spec is used to specify' |
| 446 | ' a firmware build when the suite requires firmware to be ' |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 447 | 'updated in the dut, its value can only be `firmware` or ' |
| 448 | '`cros`. cros_build_spec is used to specify a ChromeOS ' |
| 449 | 'build when build_specs is set to firmware.') |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 450 | if (self._firmware_rw_build_spec and |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 451 | self._firmware_rw_build_spec not in ['firmware', 'cros']): |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 452 | raise MalformedConfigEntry( |
Dan Shi | 59562a8 | 2016-01-06 16:05:31 -0800 | [diff] [blame] | 453 | 'firmware_rw_build_spec can only be empty, firmware or ' |
| 454 | 'cros. It does not support other build type yet.') |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 455 | |
| 456 | self._bare_branches = [] |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 457 | self._version_equal_constraint = False |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 458 | self._version_gte_constraint = False |
| 459 | self._version_lte_constraint = False |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 460 | if not branch_specs: |
| 461 | # Any milestone is OK. |
| 462 | self._numeric_constraint = version.LooseVersion('0') |
| 463 | else: |
| 464 | self._numeric_constraint = None |
| 465 | for spec in branch_specs: |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 466 | if 'tot' in spec.lower(): |
| 467 | tot_str = spec[spec.index('tot'):] |
| 468 | spec = spec.replace( |
| 469 | tot_str, TotMilestoneManager().ConvertTotSpec( |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 470 | tot_str)) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 471 | if spec.startswith('>='): |
| 472 | self._numeric_constraint = version.LooseVersion( |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 473 | spec.lstrip('>=R')) |
| 474 | self._version_gte_constraint = True |
| 475 | elif spec.startswith('<='): |
| 476 | self._numeric_constraint = version.LooseVersion( |
| 477 | spec.lstrip('<=R')) |
| 478 | self._version_lte_constraint = True |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 479 | elif spec.startswith('=='): |
| 480 | self._version_equal_constraint = True |
| 481 | self._numeric_constraint = version.LooseVersion( |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 482 | spec.lstrip('==R')) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 483 | else: |
| 484 | self._bare_branches.append(spec) |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 485 | |
Aviv Keshet | 52c7a21 | 2015-12-07 15:27:22 -0800 | [diff] [blame] | 486 | # Since we expect __hash__() and other comparator methods to be used |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 487 | # frequently by set operations, and they use str() a lot, pre-compute |
| 488 | # the string representation of this object. |
Aviv Keshet | 8ce3c98 | 2013-01-24 09:23:13 -0800 | [diff] [blame] | 489 | if num is None: |
| 490 | numStr = '[Default num]' |
| 491 | else: |
| 492 | numStr = '%d' % num |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 493 | |
| 494 | if boards is None: |
| 495 | self._boards = set() |
| 496 | boardsStr = '[All boards]' |
| 497 | else: |
| 498 | self._boards = set([x.strip() for x in boards.split(',')]) |
| 499 | boardsStr = boards |
| 500 | |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame^] | 501 | time_str = '' |
| 502 | if self._hour: |
| 503 | time_str = ' Run at %d:00.' % self._hour |
| 504 | elif self._day: |
| 505 | time_str = ' Run on %s.' % _WEEKDAYS[self._day] |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 506 | if os_type == OS_TYPE_CROS: |
| 507 | self._str = ('%s: %s on %s with pool %s, boards [%s], file_bugs = ' |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame^] | 508 | '%s across %s machines.%s' % |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 509 | (self.__class__.__name__, suite, branch_specs, pool, |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame^] | 510 | boardsStr, self._file_bugs, numStr, time_str)) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 511 | else: |
| 512 | self._str = ('%s: %s on branches %s and targets %s with pool %s, ' |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame^] | 513 | 'boards [%s], file_bugs = %s across %s machines.%s' % |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 514 | (self.__class__.__name__, suite, |
| 515 | launch_control_branches, launch_control_targets, |
Dan Shi | 481b8b6 | 2016-03-08 13:03:08 -0800 | [diff] [blame^] | 516 | pool, boardsStr, self._file_bugs, numStr, time_str)) |
| 517 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 518 | |
| 519 | |
| 520 | def _FitsSpec(self, branch): |
| 521 | """Checks if a branch is deemed OK by this instance's branch specs. |
| 522 | |
| 523 | When called on a branch name, will return whether that branch |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 524 | 'fits' the specifications stored in self._bare_branches, |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 525 | self._numeric_constraint, self._version_equal_constraint, |
| 526 | self._version_gte_constraint and self._version_lte_constraint. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 527 | |
| 528 | @param branch: the branch to check. |
| 529 | @return True if b 'fits' with stored specs, False otherwise. |
| 530 | """ |
Chris Masone | 657e155 | 2012-05-30 17:06:20 -0700 | [diff] [blame] | 531 | if branch in BARE_BRANCHES: |
| 532 | return branch in self._bare_branches |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 533 | if self._numeric_constraint: |
| 534 | if self._version_equal_constraint: |
| 535 | return version.LooseVersion(branch) == self._numeric_constraint |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 536 | elif self._version_gte_constraint: |
| 537 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 538 | elif self._version_lte_constraint: |
| 539 | return version.LooseVersion(branch) <= self._numeric_constraint |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 540 | else: |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 541 | # Default to great or equal constraint. |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 542 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 543 | else: |
| 544 | return False |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 545 | |
| 546 | |
| 547 | @property |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 548 | def name(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 549 | """Name of this task, e.g. 'NightlyPower'.""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 550 | return self._name |
| 551 | |
| 552 | |
| 553 | @property |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 554 | def suite(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 555 | """Name of the suite to run, e.g. 'bvt'.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 556 | return self._suite |
| 557 | |
| 558 | |
| 559 | @property |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 560 | def branch_specs(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 561 | """a pre-vetted iterable of branch specifiers, |
| 562 | e.g. ['>=R18', 'factory'].""" |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 563 | return self._branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 564 | |
| 565 | |
| 566 | @property |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 567 | def pool(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 568 | """The pool of machines to use for scheduling purposes.""" |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 569 | return self._pool |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 570 | |
| 571 | |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 572 | @property |
| 573 | def num(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 574 | """The number of devices across which to shard the test suite. |
| 575 | Type: integer or None""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 576 | return self._num |
| 577 | |
| 578 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 579 | @property |
| 580 | def boards(self): |
| 581 | """The boards on which to run this suite. |
| 582 | Type: Iterable of strings""" |
| 583 | return self._boards |
| 584 | |
| 585 | |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 586 | @property |
| 587 | def priority(self): |
| 588 | """The priority of the suite""" |
| 589 | return self._priority |
| 590 | |
| 591 | |
| 592 | @property |
| 593 | def timeout(self): |
| 594 | """The maximum lifetime of the suite in hours.""" |
| 595 | return self._timeout |
| 596 | |
| 597 | |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 598 | @property |
| 599 | def cros_build_spec(self): |
| 600 | """The build spec of ChromeOS to test with a firmware build.""" |
| 601 | return self._cros_build_spec |
| 602 | |
| 603 | |
| 604 | @property |
| 605 | def firmware_rw_build_spec(self): |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 606 | """The build spec of RW firmware to test with a ChromeOS build. |
| 607 | |
| 608 | The value can be firmware or cros. |
| 609 | """ |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 610 | return self._firmware_rw_build_spec |
| 611 | |
| 612 | |
| 613 | @property |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 614 | def firmware_ro_build_spec(self): |
| 615 | """The build spec of RO firmware to test with a ChromeOS build. |
| 616 | |
| 617 | The value can be stable, firmware or cros, where stable is the stable |
| 618 | firmware build retrieved from stable_version table. |
| 619 | """ |
| 620 | return self._firmware_ro_build_spec |
| 621 | |
| 622 | |
| 623 | @property |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 624 | def test_source(self): |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 625 | """Source of the test code, value can be `firmware_rw`, `firmware_ro` or |
| 626 | `cros`.""" |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 627 | return self._test_source |
| 628 | |
| 629 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 630 | @property |
| 631 | def hour(self): |
| 632 | """An integer specifying the hour that a nightly run should be triggered |
| 633 | """ |
| 634 | return self._hour |
| 635 | |
| 636 | |
| 637 | @property |
| 638 | def day(self): |
| 639 | """An integer specifying the day of a week that a weekly run should be |
| 640 | triggered""" |
| 641 | return self._day |
| 642 | |
| 643 | |
| 644 | @property |
| 645 | def os_type(self): |
| 646 | """Type of OS, e.g., cros, brillo, android.""" |
| 647 | return self._os_type |
| 648 | |
| 649 | |
| 650 | @property |
| 651 | def launch_control_branches(self): |
| 652 | """A list of Launch Control builds.""" |
| 653 | return self._launch_control_branches |
| 654 | |
| 655 | |
| 656 | @property |
| 657 | def launch_control_targets(self): |
| 658 | """A list of Launch Control targets.""" |
| 659 | return self._launch_control_targets |
| 660 | |
| 661 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 662 | def __str__(self): |
| 663 | return self._str |
| 664 | |
| 665 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 666 | def __repr__(self): |
| 667 | return self._str |
| 668 | |
| 669 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 670 | def __lt__(self, other): |
| 671 | return str(self) < str(other) |
| 672 | |
| 673 | |
| 674 | def __le__(self, other): |
| 675 | return str(self) <= str(other) |
| 676 | |
| 677 | |
| 678 | def __eq__(self, other): |
| 679 | return str(self) == str(other) |
| 680 | |
| 681 | |
| 682 | def __ne__(self, other): |
| 683 | return str(self) != str(other) |
| 684 | |
| 685 | |
| 686 | def __gt__(self, other): |
| 687 | return str(self) > str(other) |
| 688 | |
| 689 | |
| 690 | def __ge__(self, other): |
| 691 | return str(self) >= str(other) |
| 692 | |
| 693 | |
| 694 | def __hash__(self): |
| 695 | """Allows instances to be correctly deduped when used in a set.""" |
| 696 | return hash(str(self)) |
| 697 | |
| 698 | |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 699 | def _GetCrOSBuild(self, mv, board): |
| 700 | """Get the ChromeOS build name to test with firmware build. |
| 701 | |
| 702 | The ChromeOS build to be used is determined by `self.cros_build_spec`. |
| 703 | Its value can be: |
| 704 | tot: use the latest ToT build. |
| 705 | tot-x: use the latest build in x milestone before ToT. |
| 706 | Rxx: use the latest build on xx milestone. |
| 707 | |
| 708 | @param board: the board against which to run self._suite. |
| 709 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 710 | |
| 711 | @return: The ChromeOS build name to test with firmware build. |
| 712 | |
| 713 | """ |
| 714 | if not self.cros_build_spec: |
| 715 | return None |
| 716 | if self.cros_build_spec.startswith('tot'): |
| 717 | milestone = TotMilestoneManager().ConvertTotSpec( |
| 718 | self.cros_build_spec)[1:] |
| 719 | elif self.cros_build_spec.startswith('R'): |
| 720 | milestone = self.cros_build_spec[1:] |
| 721 | milestone, latest_manifest = mv.GetLatestManifest( |
| 722 | board, 'release', milestone=milestone) |
| 723 | latest_build = base_event.BuildName(board, 'release', milestone, |
| 724 | latest_manifest) |
| 725 | logging.debug('Found latest build of %s for spec %s: %s', |
| 726 | board, self.cros_build_spec, latest_build) |
| 727 | return latest_build |
| 728 | |
| 729 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 730 | def _GetFirmwareBuild(self, spec, mv, board): |
| 731 | """Get the firmware build name to test with ChromeOS build. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 732 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 733 | @param spec: build spec for RO or RW firmware, e.g., firmware, cros |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 734 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 735 | @param board: the board against which to run self._suite. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 736 | |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 737 | @return: The firmware build name to test with ChromeOS build. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 738 | """ |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 739 | if spec == 'stable': |
| 740 | # TODO(crbug.com/577316): Query stable RO firmware. |
| 741 | raise NotImplementedError('`stable` RO firmware build is not ' |
| 742 | 'supported yet.') |
| 743 | if not spec: |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 744 | return None |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 745 | # build_type is the build type of the firmware build, e.g., factory, |
| 746 | # firmware or release. If spec is set to cros, build type should be |
| 747 | # mapped to release. |
| 748 | build_type = 'release' if spec == 'cros' else spec |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 749 | latest_milestone, latest_manifest = mv.GetLatestManifest( |
| 750 | board, build_type) |
| 751 | latest_build = base_event.BuildName(board, build_type, latest_milestone, |
| 752 | latest_manifest) |
| 753 | logging.debug('Found latest firmware build of %s for spec %s: %s', |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 754 | board, spec, latest_build) |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 755 | return latest_build |
| 756 | |
| 757 | |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 758 | def AvailableHosts(self, scheduler, board): |
| 759 | """Query what hosts are able to run a test on a board and pool |
| 760 | combination. |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 761 | |
| 762 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 763 | deduping_scheduler.py |
| 764 | @param board: the board against which one wants to run the test. |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 765 | @return The list of hosts meeting the board and pool requirements, |
| 766 | or None if no hosts were found.""" |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 767 | if self._boards and board not in self._boards: |
| 768 | return [] |
| 769 | |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 770 | labels = [Labels.BOARD_PREFIX + board] |
| 771 | if self._pool: |
Chris Masone | cd214e0 | 2012-07-10 16:22:10 -0700 | [diff] [blame] | 772 | labels.append(Labels.POOL_PREFIX + self._pool) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 773 | |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 774 | return scheduler.CheckHostsExist(multiple_labels=labels) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 775 | |
| 776 | |
Alex Miller | d621cf2 | 2012-07-11 13:57:10 -0700 | [diff] [blame] | 777 | def ShouldHaveAvailableHosts(self): |
| 778 | """As a sanity check, return true if we know for certain that |
| 779 | we should be able to schedule this test. If we claim this test |
| 780 | should be able to run, and it ends up not being scheduled, then |
| 781 | a warning will be reported. |
| 782 | |
| 783 | @return True if this test should be able to run, False otherwise. |
| 784 | """ |
| 785 | return self._pool == 'bvt' |
| 786 | |
| 787 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 788 | def _ScheduleSuite(self, scheduler, cros_build, firmware_rw_build, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 789 | firmware_ro_build, test_source_build, |
| 790 | launch_control_build, board, force, run_prod_code=False): |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 791 | """Try to schedule a suite with given build and board information. |
| 792 | |
| 793 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 794 | deduping_scheduler.py |
| 795 | @oaran build: Build to run suite for, e.g., 'daisy-release/R18-1655.0.0' |
| 796 | and 'git_mnc_release/shamu-eng/123'. |
| 797 | @param firmware_rw_build: Firmware RW build to run test with. |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 798 | @param firmware_ro_build: Firmware RO build to run test with. |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 799 | @param test_source_build: Test source build, used for server-side |
| 800 | packaging. |
| 801 | @param launch_control_build: Name of a Launch Control build, e.g., |
| 802 | 'git_mnc_release/shamu-eng/123' |
| 803 | @param board: the board against which to run self._suite. |
| 804 | @param force: Always schedule the suite. |
| 805 | @param run_prod_code: If True, the suite will run the test code that |
| 806 | lives in prod aka the test code currently on the |
| 807 | lab servers. If False, the control files and test |
| 808 | code for this suite run will be retrieved from the |
| 809 | build artifacts. Default is False. |
| 810 | """ |
| 811 | test_source_build_msg = ( |
| 812 | ' Test source build is %s.' % test_source_build |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 813 | if test_source_build else '') |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 814 | firmware_rw_build_msg = ( |
| 815 | ' Firmware RW build is %s.' % firmware_rw_build |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 816 | if firmware_rw_build else '') |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 817 | firmware_ro_build_msg = ( |
| 818 | ' Firmware RO build is %s.' % firmware_ro_build |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 819 | if firmware_ro_build else '') |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 820 | build_string = cros_build or launch_control_build |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 821 | logging.debug('Schedule %s for build %s.%s%s%s', |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 822 | self._suite, build_string, test_source_build_msg, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 823 | firmware_rw_build_msg, firmware_ro_build_msg) |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 824 | |
| 825 | if not scheduler.ScheduleSuite( |
| 826 | self._suite, board, cros_build, self._pool, self._num, |
| 827 | self._priority, self._timeout, force, |
| 828 | file_bugs=self._file_bugs, |
| 829 | firmware_rw_build=firmware_rw_build, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 830 | firmware_ro_build=firmware_ro_build, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 831 | test_source_build=test_source_build, |
| 832 | job_retry=self._job_retry, |
| 833 | launch_control_build=launch_control_build, |
| 834 | run_prod_code=run_prod_code): |
| 835 | logging.info('Skipping scheduling %s on %s for %s', |
| 836 | self._suite, build_string, board) |
| 837 | |
| 838 | |
| 839 | def _Run_CrOS_Builds(self, scheduler, branch_builds, board, force=False, |
| 840 | mv=None): |
| 841 | """Run this task for CrOS builds. Returns False if it should be |
| 842 | destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 843 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 844 | Execute this task. Attempt to schedule the associated suite. |
| 845 | Return True if this task should be kept around, False if it |
| 846 | should be destroyed. This allows for one-shot Tasks. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 847 | |
| 848 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 849 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 850 | @param branch_builds: a dict mapping branch name to the build(s) to |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 851 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 852 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 853 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 854 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 855 | @param force: Always schedule the suite. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 856 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 857 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 858 | @return True if the task should be kept, False if not |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 859 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 860 | """ |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 861 | logging.info('Running %s on %s', self._name, board) |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 862 | is_firmware_build = 'firmware' in self.branch_specs |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 863 | |
| 864 | # firmware_xx_build is only needed if firmware_xx_build_spec is given. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 865 | firmware_rw_build = None |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 866 | firmware_ro_build = None |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 867 | try: |
| 868 | if is_firmware_build: |
| 869 | # When build specified in branch_specs is a firmware build, |
| 870 | # we need a ChromeOS build to test with the firmware build. |
| 871 | cros_build = self._GetCrOSBuild(mv, board) |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 872 | elif self.firmware_rw_build_spec or self.firmware_ro_build_spec: |
| 873 | # When firmware_xx_build_spec is specified, the test involves |
| 874 | # updating the RW firmware by firmware build specified in |
| 875 | # firmware_xx_build_spec. |
| 876 | firmware_rw_build = self._GetFirmwareBuild( |
| 877 | self.firmware_rw_build_spec, mv, board) |
| 878 | firmware_ro_build = self._GetFirmwareBuild( |
| 879 | self.firmware_ro_build_spec, mv, board) |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 880 | except manifest_versions.QueryException as e: |
| 881 | logging.error(e) |
| 882 | logging.error('Running %s on %s is failed. Failed to find build ' |
| 883 | 'required to run the suite.', self._name, board) |
| 884 | return False |
| 885 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 886 | builds = [] |
Chris Masone | fe5a509 | 2012-04-11 18:29:07 -0700 | [diff] [blame] | 887 | for branch, build in branch_builds.iteritems(): |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 888 | logging.info('Checking if %s fits spec %r', |
| 889 | branch, self.branch_specs) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 890 | if self._FitsSpec(branch): |
Dan Shi | bde1077 | 2015-08-18 10:15:58 -0700 | [diff] [blame] | 891 | logging.debug('Build %s fits the spec.', build) |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 892 | builds.extend(build) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 893 | for build in builds: |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 894 | try: |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 895 | if is_firmware_build: |
| 896 | firmware_rw_build = build |
| 897 | else: |
| 898 | cros_build = build |
| 899 | if self.test_source == Builds.FIRMWARE_RW: |
| 900 | test_source_build = firmware_rw_build |
| 901 | elif self.test_source == Builds.CROS: |
| 902 | test_source_build = cros_build |
| 903 | else: |
| 904 | test_source_build = None |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 905 | self._ScheduleSuite(scheduler, cros_build, firmware_rw_build, |
Dan Shi | b49bb8b | 2016-03-01 15:29:27 -0800 | [diff] [blame] | 906 | firmware_ro_build, test_source_build, |
| 907 | None, board, force) |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 908 | except deduping_scheduler.DedupingSchedulerException as e: |
| 909 | logging.error(e) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 910 | return True |
| 911 | |
| 912 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 913 | def _Run_LaunchControl_Builds(self, scheduler, launch_control_builds, board, |
| 914 | force=False): |
| 915 | """Run this task. Returns False if it should be destroyed. |
| 916 | |
| 917 | Execute this task. Attempt to schedule the associated suite. |
| 918 | Return True if this task should be kept around, False if it |
| 919 | should be destroyed. This allows for one-shot Tasks. |
| 920 | |
| 921 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 922 | deduping_scheduler.py |
| 923 | @param launch_control_builds: A list of Launch Control builds. |
| 924 | @param board: the board against which to run self._suite. |
| 925 | @param force: Always schedule the suite. |
| 926 | |
| 927 | @return True if the task should be kept, False if not |
| 928 | |
| 929 | """ |
| 930 | logging.info('Running %s on %s', self._name, board) |
| 931 | for build in launch_control_builds: |
| 932 | try: |
Dan Shi | 8446fac | 2016-03-02 22:07:39 -0800 | [diff] [blame] | 933 | self._ScheduleSuite(scheduler, None, None, None, |
| 934 | test_source_build=build, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 935 | launch_control_build=build, board=board, |
| 936 | force=force, run_prod_code=True) |
| 937 | except deduping_scheduler.DedupingSchedulerException as e: |
| 938 | logging.error(e) |
| 939 | return True |
| 940 | |
| 941 | |
| 942 | def Run(self, scheduler, branch_builds, board, force=False, mv=None, |
| 943 | launch_control_builds=None): |
| 944 | """Run this task. Returns False if it should be destroyed. |
| 945 | |
| 946 | Execute this task. Attempt to schedule the associated suite. |
| 947 | Return True if this task should be kept around, False if it |
| 948 | should be destroyed. This allows for one-shot Tasks. |
| 949 | |
| 950 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 951 | deduping_scheduler.py |
| 952 | @param branch_builds: a dict mapping branch name to the build(s) to |
| 953 | install for that branch, e.g. |
| 954 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 955 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
| 956 | @param board: the board against which to run self._suite. |
| 957 | @param force: Always schedule the suite. |
| 958 | @param mv: an instance of manifest_versions.ManifestVersions. |
| 959 | @param launch_control_builds: A list of Launch Control builds. |
| 960 | |
| 961 | @return True if the task should be kept, False if not |
| 962 | |
| 963 | """ |
| 964 | if ((self._os_type == OS_TYPE_CROS and not branch_builds) or |
| 965 | (self._os_type != OS_TYPE_CROS and not launch_control_builds)): |
| 966 | logging.debug('No build to run, skip running %s on %s.', self._name, |
| 967 | board) |
| 968 | # Return True so the task will be kept, as the given build and board |
| 969 | # do not match. |
| 970 | return True |
| 971 | |
| 972 | if self._os_type == OS_TYPE_CROS: |
| 973 | return self._Run_CrOS_Builds( |
| 974 | scheduler, branch_builds, board, force, mv) |
| 975 | else: |
| 976 | return self._Run_LaunchControl_Builds( |
| 977 | scheduler, launch_control_builds, board, force) |
| 978 | |
| 979 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 980 | class OneShotTask(Task): |
| 981 | """A Task that can be run only once. Can schedule itself.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 982 | |
| 983 | |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 984 | def Run(self, scheduler, branch_builds, board, force=False, mv=None, |
| 985 | launch_control_builds=None): |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 986 | """Run this task. Returns False, indicating it should be destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 987 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 988 | Run this task. Attempt to schedule the associated suite. |
| 989 | Return False, indicating to the caller that it should discard this task. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 990 | |
| 991 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 992 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 993 | @param branch_builds: a dict mapping branch name to the build(s) to |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 994 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 995 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 996 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 997 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 998 | @param force: Always schedule the suite. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 999 | @param mv: an instance of manifest_versions.ManifestVersions. |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 1000 | @param launch_control_builds: A list of Launch Control builds. |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1001 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1002 | @return False |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1003 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1004 | """ |
Dan Shi | a25e0d4 | 2015-07-23 15:00:04 -0700 | [diff] [blame] | 1005 | super(OneShotTask, self).Run(scheduler, branch_builds, board, force, |
Dan Shi | 2121a33 | 2016-02-25 14:22:22 -0800 | [diff] [blame] | 1006 | mv, launch_control_builds) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 1007 | return False |