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 |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 9 | import deduping_scheduler |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 10 | import driver |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 11 | from distutils import version |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 12 | from constants import Labels |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 13 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 14 | import common |
| 15 | from autotest_lib.server.cros.dynamic_suite import constants |
| 16 | from autotest_lib.scheduler import scheduler_lib |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 17 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 18 | |
| 19 | class MalformedConfigEntry(Exception): |
| 20 | """Raised to indicate a failure to parse a Task out of a config.""" |
| 21 | pass |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 22 | |
| 23 | |
Alex Miller | 0d00357 | 2013-03-18 11:51:30 -0700 | [diff] [blame] | 24 | BARE_BRANCHES = ['factory', 'firmware'] |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def PickBranchName(type, milestone): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 28 | """Pick branch name. If type is among BARE_BRANCHES, return type, |
| 29 | otherwise, return milestone. |
| 30 | |
| 31 | @param type: type of the branch, e.g., 'release', 'factory', or 'firmware' |
| 32 | @param milestone: CrOS milestone number |
| 33 | """ |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 34 | if type in BARE_BRANCHES: |
| 35 | return type |
| 36 | return milestone |
| 37 | |
| 38 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 39 | class TotMilestoneManager(object): |
| 40 | """A class capable of converting tot string to milestone numbers. |
| 41 | |
| 42 | This class is used as a cache for the tot milestone, so we don't |
| 43 | repeatedly hit google storage for all O(100) tasks in suite |
| 44 | scheduler's ini file. |
| 45 | """ |
| 46 | |
| 47 | __metaclass__ = scheduler_lib.Singleton |
| 48 | |
Dan Shi | 2324514 | 2015-01-22 13:22:28 -0800 | [diff] [blame^] | 49 | # True if suite_scheduler is running for sanity check. When it's set to |
| 50 | # True, the code won't make gsutil call to get the actual tot milestone to |
| 51 | # avoid dependency on the installation of gsutil to run sanity check. |
| 52 | is_sanity = False |
| 53 | |
| 54 | |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 55 | @staticmethod |
| 56 | def _tot_milestone(): |
| 57 | """Get the tot milestone, eg: R40 |
| 58 | |
| 59 | @returns: A string representing the Tot milestone as declared by |
| 60 | the LATEST_BUILD_URL, or an empty string if LATEST_BUILD_URL |
| 61 | doesn't exist. |
| 62 | """ |
Dan Shi | 2324514 | 2015-01-22 13:22:28 -0800 | [diff] [blame^] | 63 | if TotMilestoneManager.is_sanity: |
| 64 | logging.info('suite_scheduler is running for sanity purpose, no ' |
| 65 | 'need to get the actual tot milestone string.') |
| 66 | return 'R40' |
| 67 | |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 68 | cmd = ['gsutil', 'cat', constants.LATEST_BUILD_URL] |
| 69 | proc = subprocess.Popen( |
| 70 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 71 | stdout, stderr = proc.communicate() |
| 72 | if proc.poll(): |
| 73 | logging.warning('Failed to get latest build: %s', stderr) |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 74 | return '' |
Prashanth Balasubramanian | 1b85962 | 2014-10-28 16:02:15 -0700 | [diff] [blame] | 75 | return stdout.split('-')[0] |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 76 | |
| 77 | |
| 78 | def refresh(self): |
| 79 | """Refresh the tot milestone string managed by this class.""" |
| 80 | self.tot = self._tot_milestone() |
| 81 | |
| 82 | |
| 83 | def __init__(self): |
| 84 | """Initialize a TotMilestoneManager.""" |
| 85 | self.refresh() |
| 86 | |
| 87 | |
| 88 | def ConvertTotSpec(self, tot_spec): |
| 89 | """Converts a tot spec to the appropriate milestone. |
| 90 | |
| 91 | Assume tot is R40: |
| 92 | tot -> R40 |
| 93 | tot-1 -> R39 |
| 94 | tot-2 -> R38 |
| 95 | tot-(any other numbers) -> R40 |
| 96 | |
| 97 | With the last option one assumes that a malformed configuration that has |
| 98 | 'tot' in it, wants at least tot. |
| 99 | |
| 100 | @param tot_spec: A string representing the tot spec. |
| 101 | @raises MalformedConfigEntry: If the tot_spec doesn't match the |
| 102 | expected format. |
| 103 | """ |
| 104 | tot_spec = tot_spec.lower() |
| 105 | match = re.match('(tot)[-]?(1$|2$)?', tot_spec) |
| 106 | if not match: |
| 107 | raise MalformedConfigEntry( |
| 108 | "%s isn't a valid branch spec." % tot_spec) |
| 109 | tot_mstone = self.tot |
| 110 | num_back = match.groups()[1] |
| 111 | if num_back: |
| 112 | tot_mstone_num = tot_mstone.lstrip('R') |
| 113 | tot_mstone = tot_mstone.replace( |
| 114 | tot_mstone_num, str(int(tot_mstone_num)-int(num_back))) |
| 115 | return tot_mstone |
| 116 | |
| 117 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 118 | class Task(object): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 119 | """Represents an entry from the scheduler config. Can schedule itself. |
| 120 | |
| 121 | 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] | 122 | Task. Each instance has enough info to schedule itself |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 123 | on-demand with the AFE. |
| 124 | |
| 125 | This class also overrides __hash__() and all comparitor methods to enable |
| 126 | correct use in dicts, sets, etc. |
| 127 | """ |
| 128 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 129 | |
| 130 | @staticmethod |
| 131 | def CreateFromConfigSection(config, section): |
| 132 | """Create a Task from a section of a config file. |
| 133 | |
| 134 | The section to parse should look like this: |
| 135 | [TaskName] |
| 136 | suite: suite_to_run # Required |
| 137 | run_on: event_on which to run # Required |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 138 | branch_specs: factory,firmware,>=R12 or ==R12 # Optional |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 139 | pool: pool_of_devices # Optional |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 140 | num: sharding_factor # int, Optional |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 141 | boards: board1, board2 # comma seperated string, Optional |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 142 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 143 | By default, Tasks run on all release branches, not factory or firmware. |
| 144 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 145 | @param config: a ForgivingConfigParser. |
| 146 | @param section: the section to parse into a Task. |
| 147 | @return keyword, Task object pair. One or both will be None on error. |
| 148 | @raise MalformedConfigEntry if there's a problem parsing |section|. |
| 149 | """ |
Alex Miller | 0669502 | 2012-07-18 09:31:36 -0700 | [diff] [blame] | 150 | if not config.has_section(section): |
| 151 | raise MalformedConfigEntry('unknown section %s' % section) |
| 152 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 153 | allowed = set(['suite', 'run_on', 'branch_specs', 'pool', 'num', |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 154 | 'boards', 'file_bugs']) |
Alex Miller | bb535e2 | 2012-07-11 20:11:33 -0700 | [diff] [blame] | 155 | # The parameter of union() is the keys under the section in the config |
| 156 | # The union merges this with the allowed set, so if any optional keys |
| 157 | # are omitted, then they're filled in. If any extra keys are present, |
| 158 | # then they will expand unioned set, causing it to fail the following |
| 159 | # comparison against the allowed set. |
| 160 | section_headers = allowed.union(dict(config.items(section)).keys()) |
| 161 | if allowed != section_headers: |
| 162 | raise MalformedConfigEntry('unknown entries: %s' % |
| 163 | ", ".join(map(str, section_headers.difference(allowed)))) |
| 164 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 165 | keyword = config.getstring(section, 'run_on') |
| 166 | suite = config.getstring(section, 'suite') |
| 167 | branches = config.getstring(section, 'branch_specs') |
| 168 | pool = config.getstring(section, 'pool') |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 169 | boards = config.getstring(section, 'boards') |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 170 | file_bugs = config.getboolean(section, 'file_bugs') |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 171 | for klass in driver.Driver.EVENT_CLASSES: |
| 172 | if klass.KEYWORD == keyword: |
| 173 | priority = klass.PRIORITY |
| 174 | timeout = klass.TIMEOUT |
| 175 | break |
| 176 | else: |
| 177 | priority = None |
| 178 | timeout = None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 179 | try: |
| 180 | num = config.getint(section, 'num') |
| 181 | except ValueError as e: |
| 182 | raise MalformedConfigEntry("Ill-specified 'num': %r" %e) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 183 | if not keyword: |
| 184 | raise MalformedConfigEntry('No event to |run_on|.') |
| 185 | if not suite: |
| 186 | raise MalformedConfigEntry('No |suite|') |
| 187 | specs = [] |
| 188 | if branches: |
| 189 | specs = re.split('\s*,\s*', branches) |
| 190 | Task.CheckBranchSpecs(specs) |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 191 | return keyword, Task(section, suite, specs, pool, num, boards, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 192 | priority, timeout, |
| 193 | file_bugs=file_bugs if file_bugs else False) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 194 | |
| 195 | |
| 196 | @staticmethod |
| 197 | def CheckBranchSpecs(branch_specs): |
| 198 | """Make sure entries in the list branch_specs are correctly formed. |
| 199 | |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 200 | We accept any of BARE_BRANCHES in |branch_specs|, as |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 201 | 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] | 202 | CrOS milestone number. |
| 203 | |
| 204 | @param branch_specs: an iterable of branch specifiers. |
| 205 | @raise MalformedConfigEntry if there's a problem parsing |branch_specs|. |
| 206 | """ |
| 207 | have_seen_numeric_constraint = False |
| 208 | for branch in branch_specs: |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 209 | if branch in BARE_BRANCHES: |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 210 | continue |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 211 | if not have_seen_numeric_constraint: |
| 212 | #TODO(beeps): Why was <= dropped on the floor? |
| 213 | if branch.startswith('>=R') or branch.startswith('==R'): |
| 214 | have_seen_numeric_constraint = True |
| 215 | elif 'tot' in branch: |
| 216 | TotMilestoneManager().ConvertTotSpec( |
| 217 | branch[branch.index('tot'):]) |
| 218 | have_seen_numeric_constraint = True |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 219 | continue |
Chris Masone | 97cf0a7 | 2012-05-16 09:55:52 -0700 | [diff] [blame] | 220 | raise MalformedConfigEntry("%s isn't a valid branch spec." % branch) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 221 | |
| 222 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 223 | def __init__(self, name, suite, branch_specs, pool=None, num=None, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 224 | boards=None, priority=None, timeout=None, file_bugs=False): |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 225 | """Constructor |
| 226 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 227 | Given an iterable in |branch_specs|, pre-vetted using CheckBranchSpecs, |
| 228 | we'll store them such that _FitsSpec() can be used to check whether a |
| 229 | given branch 'fits' with the specifications passed in here. |
| 230 | For example, given branch_specs = ['factory', '>=R18'], we'd set things |
| 231 | up so that _FitsSpec() would return True for 'factory', or 'RXX' |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 232 | where XX is a number >= 18. Same check is done for branch_specs = [ |
| 233 | 'factory', '==R18'], which limit the test to only one specific branch. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 234 | |
| 235 | Given branch_specs = ['factory', 'firmware'], _FitsSpec() |
| 236 | would pass only those two specific strings. |
| 237 | |
| 238 | Example usage: |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 239 | t = Task('Name', 'suite', ['factory', '>=R18']) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 240 | t._FitsSpec('factory') # True |
| 241 | t._FitsSpec('R19') # True |
| 242 | t._FitsSpec('R17') # False |
| 243 | t._FitsSpec('firmware') # False |
| 244 | t._FitsSpec('goober') # False |
| 245 | |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 246 | t = Task('Name', 'suite', ['factory', '==R18']) |
| 247 | t._FitsSpec('R19') # False, branch does not equal to 18 |
| 248 | t._FitsSpec('R18') # True |
| 249 | t._FitsSpec('R17') # False |
| 250 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 251 | @param name: name of this task, e.g. 'NightlyPower' |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 252 | @param suite: the name of the suite to run, e.g. 'bvt' |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 253 | @param branch_specs: a pre-vetted iterable of branch specifiers, |
| 254 | e.g. ['>=R18', 'factory'] |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 255 | @param pool: the pool of machines to use for scheduling purposes. |
| 256 | Default: None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 257 | @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] | 258 | Type: integer or None |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 259 | Default: None |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 260 | @param boards: A comma seperated list of boards to run this task on. |
| 261 | Default: Run on all boards. |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 262 | @param priority: The string name of a priority from |
| 263 | client.common_lib.priorities.Priority. |
| 264 | @param timeout: The max lifetime of the suite in hours. |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 265 | @param file_bugs: True if bug filing is desired for the suite created |
| 266 | for this task. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 267 | """ |
Chris Masone | cc4631d | 2012-04-20 12:06:39 -0700 | [diff] [blame] | 268 | self._name = name |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 269 | self._suite = suite |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 270 | self._branch_specs = branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 271 | self._pool = pool |
Aviv Keshet | d83ef44 | 2013-01-16 16:19:35 -0800 | [diff] [blame] | 272 | self._num = num |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 273 | self._priority = priority |
| 274 | self._timeout = timeout |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 275 | self._file_bugs = file_bugs |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 276 | |
| 277 | self._bare_branches = [] |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 278 | self._version_equal_constraint = False |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 279 | if not branch_specs: |
| 280 | # Any milestone is OK. |
| 281 | self._numeric_constraint = version.LooseVersion('0') |
| 282 | else: |
| 283 | self._numeric_constraint = None |
| 284 | for spec in branch_specs: |
Prashanth Balasubramanian | f571aa6 | 2014-10-13 18:09:44 -0700 | [diff] [blame] | 285 | if 'tot' in spec.lower(): |
| 286 | tot_str = spec[spec.index('tot'):] |
| 287 | spec = spec.replace( |
| 288 | tot_str, TotMilestoneManager().ConvertTotSpec( |
| 289 | tot_str)) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 290 | if spec.startswith('>='): |
| 291 | self._numeric_constraint = version.LooseVersion( |
| 292 | spec.lstrip('>=R')) |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 293 | elif spec.startswith('=='): |
| 294 | self._version_equal_constraint = True |
| 295 | self._numeric_constraint = version.LooseVersion( |
| 296 | spec.lstrip('==R')) |
Chris Masone | 67f06d6 | 2012-04-12 15:16:56 -0700 | [diff] [blame] | 297 | else: |
| 298 | self._bare_branches.append(spec) |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 299 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 300 | # Since we expect __hash__() and other comparitor methods to be used |
| 301 | # frequently by set operations, and they use str() a lot, pre-compute |
| 302 | # the string representation of this object. |
Aviv Keshet | 8ce3c98 | 2013-01-24 09:23:13 -0800 | [diff] [blame] | 303 | if num is None: |
| 304 | numStr = '[Default num]' |
| 305 | else: |
| 306 | numStr = '%d' % num |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 307 | |
| 308 | if boards is None: |
| 309 | self._boards = set() |
| 310 | boardsStr = '[All boards]' |
| 311 | else: |
| 312 | self._boards = set([x.strip() for x in boards.split(',')]) |
| 313 | boardsStr = boards |
| 314 | |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 315 | self._str = ('%s: %s on %s with pool %s, boards [%s], file_bugs = %s ' |
| 316 | 'across %s machines.' % (self.__class__.__name__, |
| 317 | suite, branch_specs, pool, boardsStr, self._file_bugs, |
| 318 | numStr)) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 319 | |
| 320 | |
| 321 | def _FitsSpec(self, branch): |
| 322 | """Checks if a branch is deemed OK by this instance's branch specs. |
| 323 | |
| 324 | When called on a branch name, will return whether that branch |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 325 | 'fits' the specifications stored in self._bare_branches, |
| 326 | self._numeric_constraint and self._version_equal_constraint. |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 327 | |
| 328 | @param branch: the branch to check. |
| 329 | @return True if b 'fits' with stored specs, False otherwise. |
| 330 | """ |
Chris Masone | 657e155 | 2012-05-30 17:06:20 -0700 | [diff] [blame] | 331 | if branch in BARE_BRANCHES: |
| 332 | return branch in self._bare_branches |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 333 | if self._numeric_constraint: |
| 334 | if self._version_equal_constraint: |
| 335 | return version.LooseVersion(branch) == self._numeric_constraint |
| 336 | else: |
| 337 | return version.LooseVersion(branch) >= self._numeric_constraint |
| 338 | else: |
| 339 | return False |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 340 | |
| 341 | |
| 342 | @property |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 343 | def name(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 344 | """Name of this task, e.g. 'NightlyPower'.""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 345 | return self._name |
| 346 | |
| 347 | |
| 348 | @property |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 349 | def suite(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 350 | """Name of the suite to run, e.g. 'bvt'.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 351 | return self._suite |
| 352 | |
| 353 | |
| 354 | @property |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 355 | def branch_specs(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 356 | """a pre-vetted iterable of branch specifiers, |
| 357 | e.g. ['>=R18', 'factory'].""" |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 358 | return self._branch_specs |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 359 | |
| 360 | |
| 361 | @property |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 362 | def pool(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 363 | """The pool of machines to use for scheduling purposes.""" |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 364 | return self._pool |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 365 | |
| 366 | |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 367 | @property |
| 368 | def num(self): |
Dan Shi | aceb91d | 2013-02-20 12:41:28 -0800 | [diff] [blame] | 369 | """The number of devices across which to shard the test suite. |
| 370 | Type: integer or None""" |
Alex Miller | 9979b5a | 2012-11-01 17:36:12 -0700 | [diff] [blame] | 371 | return self._num |
| 372 | |
| 373 | |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 374 | @property |
| 375 | def boards(self): |
| 376 | """The boards on which to run this suite. |
| 377 | Type: Iterable of strings""" |
| 378 | return self._boards |
| 379 | |
| 380 | |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 381 | @property |
| 382 | def priority(self): |
| 383 | """The priority of the suite""" |
| 384 | return self._priority |
| 385 | |
| 386 | |
| 387 | @property |
| 388 | def timeout(self): |
| 389 | """The maximum lifetime of the suite in hours.""" |
| 390 | return self._timeout |
| 391 | |
| 392 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 393 | def __str__(self): |
| 394 | return self._str |
| 395 | |
| 396 | |
Chris Masone | 3eeaf0a | 2012-08-09 14:07:27 -0700 | [diff] [blame] | 397 | def __repr__(self): |
| 398 | return self._str |
| 399 | |
| 400 | |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 401 | def __lt__(self, other): |
| 402 | return str(self) < str(other) |
| 403 | |
| 404 | |
| 405 | def __le__(self, other): |
| 406 | return str(self) <= str(other) |
| 407 | |
| 408 | |
| 409 | def __eq__(self, other): |
| 410 | return str(self) == str(other) |
| 411 | |
| 412 | |
| 413 | def __ne__(self, other): |
| 414 | return str(self) != str(other) |
| 415 | |
| 416 | |
| 417 | def __gt__(self, other): |
| 418 | return str(self) > str(other) |
| 419 | |
| 420 | |
| 421 | def __ge__(self, other): |
| 422 | return str(self) >= str(other) |
| 423 | |
| 424 | |
| 425 | def __hash__(self): |
| 426 | """Allows instances to be correctly deduped when used in a set.""" |
| 427 | return hash(str(self)) |
| 428 | |
| 429 | |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 430 | def AvailableHosts(self, scheduler, board): |
| 431 | """Query what hosts are able to run a test on a board and pool |
| 432 | combination. |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 433 | |
| 434 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 435 | deduping_scheduler.py |
| 436 | @param board: the board against which one wants to run the test. |
Alex Miller | 7ce1b36 | 2012-07-10 09:24:10 -0700 | [diff] [blame] | 437 | @return The list of hosts meeting the board and pool requirements, |
| 438 | or None if no hosts were found.""" |
Alex Miller | f2b5744 | 2013-09-07 18:40:02 -0700 | [diff] [blame] | 439 | if self._boards and board not in self._boards: |
| 440 | return [] |
| 441 | |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 442 | labels = [Labels.BOARD_PREFIX + board] |
| 443 | if self._pool: |
Chris Masone | cd214e0 | 2012-07-10 16:22:10 -0700 | [diff] [blame] | 444 | labels.append(Labels.POOL_PREFIX + self._pool) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 445 | |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 446 | return scheduler.CheckHostsExist(multiple_labels=labels) |
Alex Miller | 511a9e3 | 2012-07-03 09:16:47 -0700 | [diff] [blame] | 447 | |
| 448 | |
Alex Miller | d621cf2 | 2012-07-11 13:57:10 -0700 | [diff] [blame] | 449 | def ShouldHaveAvailableHosts(self): |
| 450 | """As a sanity check, return true if we know for certain that |
| 451 | we should be able to schedule this test. If we claim this test |
| 452 | should be able to run, and it ends up not being scheduled, then |
| 453 | a warning will be reported. |
| 454 | |
| 455 | @return True if this test should be able to run, False otherwise. |
| 456 | """ |
| 457 | return self._pool == 'bvt' |
| 458 | |
| 459 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 460 | def Run(self, scheduler, branch_builds, board, force=False): |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 461 | """Run this task. Returns False if it should be destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 462 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 463 | Execute this task. Attempt to schedule the associated suite. |
| 464 | Return True if this task should be kept around, False if it |
| 465 | should be destroyed. This allows for one-shot Tasks. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 466 | |
| 467 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 468 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 469 | @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] | 470 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 471 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 472 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 473 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 474 | @param force: Always schedule the suite. |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 475 | @return True if the task should be kept, False if not |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 476 | """ |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 477 | logging.info('Running %s on %s', self._name, board) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 478 | builds = [] |
Chris Masone | fe5a509 | 2012-04-11 18:29:07 -0700 | [diff] [blame] | 479 | for branch, build in branch_builds.iteritems(): |
Chris Masone | a3a3817 | 2012-05-14 15:19:56 -0700 | [diff] [blame] | 480 | logging.info('Checking if %s fits spec %r', |
| 481 | branch, self.branch_specs) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 482 | if self._FitsSpec(branch): |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 483 | builds.extend(build) |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 484 | for build in builds: |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 485 | try: |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 486 | if not scheduler.ScheduleSuite(self._suite, board, build, |
Alex Miller | c7bcf8b | 2013-09-07 20:13:20 -0700 | [diff] [blame] | 487 | self._pool, self._num, |
| 488 | self._priority, self._timeout, |
Prashanth B | 6de2bde | 2014-03-25 18:45:02 -0700 | [diff] [blame] | 489 | force, |
| 490 | file_bugs=self._file_bugs): |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 491 | logging.info('Skipping scheduling %s on %s for %s', |
| 492 | self._suite, build, board) |
Chris Masone | 3fba86f | 2012-04-03 10:06:56 -0700 | [diff] [blame] | 493 | except deduping_scheduler.DedupingSchedulerException as e: |
| 494 | logging.error(e) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 495 | return True |
| 496 | |
| 497 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 498 | class OneShotTask(Task): |
| 499 | """A Task that can be run only once. Can schedule itself.""" |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 500 | |
| 501 | |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 502 | def Run(self, scheduler, branch_builds, board, force=False): |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 503 | """Run this task. Returns False, indicating it should be destroyed. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 504 | |
Chris Masone | 013859b | 2012-04-01 13:45:26 -0700 | [diff] [blame] | 505 | Run this task. Attempt to schedule the associated suite. |
| 506 | Return False, indicating to the caller that it should discard this task. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 507 | |
| 508 | @param scheduler: an instance of DedupingScheduler, as defined in |
| 509 | deduping_scheduler.py |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 510 | @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] | 511 | install for that branch, e.g. |
Chris Masone | 05b1944 | 2012-04-17 13:37:55 -0700 | [diff] [blame] | 512 | {'R18': ['x86-alex-release/R18-1655.0.0'], |
| 513 | 'R19': ['x86-alex-release/R19-2077.0.0']} |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 514 | @param board: the board against which to run self._suite. |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 515 | @param force: Always schedule the suite. |
| 516 | @return False |
| 517 | """ |
Chris Masone | 96f1663 | 2012-04-04 18:36:03 -0700 | [diff] [blame] | 518 | super(OneShotTask, self).Run(scheduler, branch_builds, board, force) |
Chris Masone | fad911a | 2012-03-29 12:30:26 -0700 | [diff] [blame] | 519 | return False |