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