blob: 349adb3dc1cc758643b72bc8f6ff13bc787b4e8b [file] [log] [blame]
Chris Masonefad911a2012-03-29 12:30:26 -07001# 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 Masone67f06d62012-04-12 15:16:56 -07005
Prashanth Balasubramanian1b859622014-10-28 16:02:15 -07006import logging
7import re
8import subprocess
Dan Shia25e0d42015-07-23 15:00:04 -07009
10import base_event
Aviv Keshetd83ef442013-01-16 16:19:35 -080011import deduping_scheduler
Alex Millerc7bcf8b2013-09-07 20:13:20 -070012import driver
Dan Shia25e0d42015-07-23 15:00:04 -070013import manifest_versions
Chris Masone67f06d62012-04-12 15:16:56 -070014from distutils import version
Alex Miller511a9e32012-07-03 09:16:47 -070015from constants import Labels
Dan Shia25e0d42015-07-23 15:00:04 -070016from constants import Builds
Chris Masone96f16632012-04-04 18:36:03 -070017
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070018import common
Dan Shi648ce922016-03-26 00:22:47 -070019from autotest_lib.client.common_lib import global_config
Fang Dengf08814a2015-08-03 18:12:18 +000020from autotest_lib.server import utils as server_utils
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070021from autotest_lib.server.cros.dynamic_suite import constants
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070022
Dan Shi648ce922016-03-26 00:22:47 -070023
24CONFIG = global_config.global_config
25
Dan Shi2121a332016-02-25 14:22:22 -080026OS_TYPE_CROS = 'cros'
27OS_TYPE_BRILLO = 'brillo'
28OS_TYPE_ANDROID = 'android'
29OS_TYPES = {OS_TYPE_CROS, OS_TYPE_BRILLO, OS_TYPE_ANDROID}
30OS_TYPES_LAUNCH_CONTROL = {OS_TYPE_BRILLO, OS_TYPE_ANDROID}
Chris Masone96f16632012-04-04 18:36:03 -070031
Dan Shi481b8b62016-03-08 13:03:08 -080032_WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
33 'Sunday']
34
Dan Shi84585362016-10-03 14:11:43 -070035# regex to parse the dut count from board label. Note that the regex makes sure
36# there is only one board specified in `boards`
37TESTBED_DUT_COUNT_REGEX = '[^,]*-(\d+)'
38
Chris Masone96f16632012-04-04 18:36:03 -070039class MalformedConfigEntry(Exception):
40 """Raised to indicate a failure to parse a Task out of a config."""
41 pass
Chris Masonefad911a2012-03-29 12:30:26 -070042
43
Alex Miller0d003572013-03-18 11:51:30 -070044BARE_BRANCHES = ['factory', 'firmware']
Chris Masone67f06d62012-04-12 15:16:56 -070045
46
47def PickBranchName(type, milestone):
Dan Shiaceb91d2013-02-20 12:41:28 -080048 """Pick branch name. If type is among BARE_BRANCHES, return type,
49 otherwise, return milestone.
50
51 @param type: type of the branch, e.g., 'release', 'factory', or 'firmware'
52 @param milestone: CrOS milestone number
53 """
Chris Masone67f06d62012-04-12 15:16:56 -070054 if type in BARE_BRANCHES:
55 return type
56 return milestone
57
58
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070059class TotMilestoneManager(object):
60 """A class capable of converting tot string to milestone numbers.
61
62 This class is used as a cache for the tot milestone, so we don't
63 repeatedly hit google storage for all O(100) tasks in suite
64 scheduler's ini file.
65 """
66
Fang Dengf08814a2015-08-03 18:12:18 +000067 __metaclass__ = server_utils.Singleton
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070068
Dan Shi23245142015-01-22 13:22:28 -080069 # True if suite_scheduler is running for sanity check. When it's set to
70 # True, the code won't make gsutil call to get the actual tot milestone to
71 # avoid dependency on the installation of gsutil to run sanity check.
72 is_sanity = False
73
74
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070075 @staticmethod
76 def _tot_milestone():
77 """Get the tot milestone, eg: R40
78
79 @returns: A string representing the Tot milestone as declared by
80 the LATEST_BUILD_URL, or an empty string if LATEST_BUILD_URL
81 doesn't exist.
82 """
Dan Shi23245142015-01-22 13:22:28 -080083 if TotMilestoneManager.is_sanity:
84 logging.info('suite_scheduler is running for sanity purpose, no '
85 'need to get the actual tot milestone string.')
86 return 'R40'
87
Prashanth Balasubramanian1b859622014-10-28 16:02:15 -070088 cmd = ['gsutil', 'cat', constants.LATEST_BUILD_URL]
89 proc = subprocess.Popen(
90 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
91 stdout, stderr = proc.communicate()
92 if proc.poll():
93 logging.warning('Failed to get latest build: %s', stderr)
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070094 return ''
Prashanth Balasubramanian1b859622014-10-28 16:02:15 -070095 return stdout.split('-')[0]
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -070096
97
98 def refresh(self):
99 """Refresh the tot milestone string managed by this class."""
100 self.tot = self._tot_milestone()
101
102
103 def __init__(self):
104 """Initialize a TotMilestoneManager."""
105 self.refresh()
106
107
108 def ConvertTotSpec(self, tot_spec):
109 """Converts a tot spec to the appropriate milestone.
110
111 Assume tot is R40:
112 tot -> R40
113 tot-1 -> R39
114 tot-2 -> R38
115 tot-(any other numbers) -> R40
116
117 With the last option one assumes that a malformed configuration that has
118 'tot' in it, wants at least tot.
119
120 @param tot_spec: A string representing the tot spec.
121 @raises MalformedConfigEntry: If the tot_spec doesn't match the
122 expected format.
123 """
124 tot_spec = tot_spec.lower()
125 match = re.match('(tot)[-]?(1$|2$)?', tot_spec)
126 if not match:
127 raise MalformedConfigEntry(
128 "%s isn't a valid branch spec." % tot_spec)
129 tot_mstone = self.tot
130 num_back = match.groups()[1]
131 if num_back:
132 tot_mstone_num = tot_mstone.lstrip('R')
133 tot_mstone = tot_mstone.replace(
134 tot_mstone_num, str(int(tot_mstone_num)-int(num_back)))
135 return tot_mstone
136
137
Chris Masone013859b2012-04-01 13:45:26 -0700138class Task(object):
Chris Masonefad911a2012-03-29 12:30:26 -0700139 """Represents an entry from the scheduler config. Can schedule itself.
140
141 Each entry from the scheduler config file maps one-to-one to a
Chris Masone013859b2012-04-01 13:45:26 -0700142 Task. Each instance has enough info to schedule itself
Chris Masonefad911a2012-03-29 12:30:26 -0700143 on-demand with the AFE.
144
Aviv Keshet52c7a212015-12-07 15:27:22 -0800145 This class also overrides __hash__() and all comparator methods to enable
Chris Masonefad911a2012-03-29 12:30:26 -0700146 correct use in dicts, sets, etc.
147 """
148
Chris Masone96f16632012-04-04 18:36:03 -0700149
150 @staticmethod
151 def CreateFromConfigSection(config, section):
152 """Create a Task from a section of a config file.
153
154 The section to parse should look like this:
155 [TaskName]
156 suite: suite_to_run # Required
157 run_on: event_on which to run # Required
Dan Shi9f256d92016-01-22 00:09:25 -0800158 hour: integer of the hour to run, only applies to nightly. # Optional
Dan Shiaceb91d2013-02-20 12:41:28 -0800159 branch_specs: factory,firmware,>=R12 or ==R12 # Optional
Chris Masone96f16632012-04-04 18:36:03 -0700160 pool: pool_of_devices # Optional
Chris Masone3eeaf0a2012-08-09 14:07:27 -0700161 num: sharding_factor # int, Optional
Alex Millerf2b57442013-09-07 18:40:02 -0700162 boards: board1, board2 # comma seperated string, Optional
Dan Shi2121a332016-02-25 14:22:22 -0800163 # Settings for Launch Control builds only:
164 os_type: brillo # Type of OS, e.g., cros, brillo, android. Default is
165 cros. Required for android/brillo builds.
166 branches: git_mnc_release # comma separated string of Launch Control
167 branches. Required and only applicable for android/brillo
168 builds.
169 targets: dragonboard-eng # comma separated string of build targets.
170 Required and only applicable for android/brillo builds.
Dan Shi84585362016-10-03 14:11:43 -0700171 testbed_dut_count: Number of duts to test when using a testbed.
Chris Masone96f16632012-04-04 18:36:03 -0700172
Chris Masone67f06d62012-04-12 15:16:56 -0700173 By default, Tasks run on all release branches, not factory or firmware.
174
Chris Masone96f16632012-04-04 18:36:03 -0700175 @param config: a ForgivingConfigParser.
176 @param section: the section to parse into a Task.
177 @return keyword, Task object pair. One or both will be None on error.
178 @raise MalformedConfigEntry if there's a problem parsing |section|.
179 """
Alex Miller06695022012-07-18 09:31:36 -0700180 if not config.has_section(section):
181 raise MalformedConfigEntry('unknown section %s' % section)
182
Alex Millerf2b57442013-09-07 18:40:02 -0700183 allowed = set(['suite', 'run_on', 'branch_specs', 'pool', 'num',
Dan Shia25e0d42015-07-23 15:00:04 -0700184 'boards', 'file_bugs', 'cros_build_spec',
Dan Shib49bb8b2016-03-01 15:29:27 -0800185 'firmware_rw_build_spec', 'firmware_ro_build_spec',
186 'test_source', 'job_retry', 'hour', 'day', 'branches',
187 'targets', 'os_type'])
Alex Millerbb535e22012-07-11 20:11:33 -0700188 # The parameter of union() is the keys under the section in the config
189 # The union merges this with the allowed set, so if any optional keys
190 # are omitted, then they're filled in. If any extra keys are present,
191 # then they will expand unioned set, causing it to fail the following
192 # comparison against the allowed set.
193 section_headers = allowed.union(dict(config.items(section)).keys())
194 if allowed != section_headers:
195 raise MalformedConfigEntry('unknown entries: %s' %
196 ", ".join(map(str, section_headers.difference(allowed))))
197
Chris Masone96f16632012-04-04 18:36:03 -0700198 keyword = config.getstring(section, 'run_on')
Dan Shi9f256d92016-01-22 00:09:25 -0800199 hour = config.getstring(section, 'hour')
Chris Masone96f16632012-04-04 18:36:03 -0700200 suite = config.getstring(section, 'suite')
Dan Shi2121a332016-02-25 14:22:22 -0800201 branch_specs = config.getstring(section, 'branch_specs')
Chris Masone96f16632012-04-04 18:36:03 -0700202 pool = config.getstring(section, 'pool')
Alex Millerf2b57442013-09-07 18:40:02 -0700203 boards = config.getstring(section, 'boards')
Prashanth B6de2bde2014-03-25 18:45:02 -0700204 file_bugs = config.getboolean(section, 'file_bugs')
Dan Shia25e0d42015-07-23 15:00:04 -0700205 cros_build_spec = config.getstring(section, 'cros_build_spec')
206 firmware_rw_build_spec = config.getstring(
207 section, 'firmware_rw_build_spec')
Dan Shib49bb8b2016-03-01 15:29:27 -0800208 firmware_ro_build_spec = config.getstring(
209 section, 'firmware_ro_build_spec')
Dan Shia25e0d42015-07-23 15:00:04 -0700210 test_source = config.getstring(section, 'test_source')
Dan Shi29a16992015-09-22 11:29:58 -0700211 job_retry = config.getboolean(section, 'job_retry')
Alex Millerc7bcf8b2013-09-07 20:13:20 -0700212 for klass in driver.Driver.EVENT_CLASSES:
213 if klass.KEYWORD == keyword:
214 priority = klass.PRIORITY
215 timeout = klass.TIMEOUT
216 break
217 else:
218 priority = None
219 timeout = None
Chris Masone3eeaf0a2012-08-09 14:07:27 -0700220 try:
221 num = config.getint(section, 'num')
222 except ValueError as e:
Dan Shi9f256d92016-01-22 00:09:25 -0800223 raise MalformedConfigEntry("Ill-specified 'num': %r" % e)
Chris Masone96f16632012-04-04 18:36:03 -0700224 if not keyword:
225 raise MalformedConfigEntry('No event to |run_on|.')
226 if not suite:
227 raise MalformedConfigEntry('No |suite|')
Dan Shi9f256d92016-01-22 00:09:25 -0800228 try:
229 hour = config.getint(section, 'hour')
230 except ValueError as e:
231 raise MalformedConfigEntry("Ill-specified 'hour': %r" % e)
232 if hour is not None and (hour < 0 or hour > 23):
233 raise MalformedConfigEntry(
234 '`hour` must be an integer between 0 and 23.')
235 if hour is not None and keyword != 'nightly':
236 raise MalformedConfigEntry(
237 '`hour` is the trigger time that can only apply to nightly '
238 'event.')
Dan Shice1f20a2016-01-25 17:27:40 -0800239
Dan Shi84585362016-10-03 14:11:43 -0700240 testbed_dut_count = None
Dan Shieb014bc2016-10-10 10:20:57 -0700241 if boards:
242 match = re.match(TESTBED_DUT_COUNT_REGEX, boards)
243 if match:
244 testbed_dut_count = int(match.group(1))
Dan Shi84585362016-10-03 14:11:43 -0700245
Dan Shice1f20a2016-01-25 17:27:40 -0800246 try:
247 day = config.getint(section, 'day')
248 except ValueError as e:
249 raise MalformedConfigEntry("Ill-specified 'day': %r" % e)
250 if day is not None and (day < 0 or day > 6):
251 raise MalformedConfigEntry(
252 '`day` must be an integer between 0 and 6, where 0 is for '
253 'Monday and 6 is for Sunday.')
254 if day is not None and keyword != 'weekly':
255 raise MalformedConfigEntry(
256 '`day` is the trigger of the day of a week, that can only '
257 'apply to weekly events.')
258
Chris Masone96f16632012-04-04 18:36:03 -0700259 specs = []
Dan Shi2121a332016-02-25 14:22:22 -0800260 if branch_specs:
261 specs = re.split('\s*,\s*', branch_specs)
Chris Masone96f16632012-04-04 18:36:03 -0700262 Task.CheckBranchSpecs(specs)
Dan Shi2121a332016-02-25 14:22:22 -0800263
264 os_type = config.getstring(section, 'os_type') or OS_TYPE_CROS
265 if os_type not in OS_TYPES:
266 raise MalformedConfigEntry('`os_type` must be one of %s' % OS_TYPES)
267
268 lc_branches = config.getstring(section, 'branches')
269 lc_targets = config.getstring(section, 'targets')
270 if os_type == OS_TYPE_CROS and (lc_branches or lc_targets):
271 raise MalformedConfigEntry(
272 '`branches` and `targets` are only supported for Launch '
273 'Control builds, not ChromeOS builds.')
274 if (os_type in OS_TYPES_LAUNCH_CONTROL and
275 (not lc_branches or not lc_targets)):
276 raise MalformedConfigEntry(
277 '`branches` and `targets` must be specified for Launch '
278 'Control builds.')
Dan Shi84585362016-10-03 14:11:43 -0700279 if (os_type in OS_TYPES_LAUNCH_CONTROL and boards and
280 not testbed_dut_count):
Dan Shi2121a332016-02-25 14:22:22 -0800281 raise MalformedConfigEntry(
282 '`boards` for Launch Control builds are retrieved from '
283 '`targets` setting, it should not be set for Launch '
284 'Control builds.')
Dan Shi84585362016-10-03 14:11:43 -0700285 if os_type == OS_TYPE_CROS and testbed_dut_count:
286 raise MalformedConfigEntry(
287 'testbed_dut_count is only supported for Launch Control '
288 'builds testing with testbed.')
Dan Shi2121a332016-02-25 14:22:22 -0800289
290 # Extract boards from targets list.
291 if os_type in OS_TYPES_LAUNCH_CONTROL:
292 boards = ''
293 for target in lc_targets.split(','):
294 board_name, _ = server_utils.parse_launch_control_target(
295 target.strip())
Dan Shi8db7e612016-07-21 12:55:16 -0700296 boards += '%s,' % board_name
Dan Shi2121a332016-02-25 14:22:22 -0800297 boards = boards.strip(',')
298
Alex Millerc7bcf8b2013-09-07 20:13:20 -0700299 return keyword, Task(section, suite, specs, pool, num, boards,
Prashanth B6de2bde2014-03-25 18:45:02 -0700300 priority, timeout,
Dan Shia25e0d42015-07-23 15:00:04 -0700301 file_bugs=file_bugs if file_bugs else False,
302 cros_build_spec=cros_build_spec,
303 firmware_rw_build_spec=firmware_rw_build_spec,
Dan Shib49bb8b2016-03-01 15:29:27 -0800304 firmware_ro_build_spec=firmware_ro_build_spec,
Dan Shi9f256d92016-01-22 00:09:25 -0800305 test_source=test_source, job_retry=job_retry,
Dan Shi2121a332016-02-25 14:22:22 -0800306 hour=hour, day=day, os_type=os_type,
307 launch_control_branches=lc_branches,
Dan Shi84585362016-10-03 14:11:43 -0700308 launch_control_targets=lc_targets,
309 testbed_dut_count=testbed_dut_count)
Chris Masone96f16632012-04-04 18:36:03 -0700310
311
312 @staticmethod
313 def CheckBranchSpecs(branch_specs):
314 """Make sure entries in the list branch_specs are correctly formed.
315
Chris Masone67f06d62012-04-12 15:16:56 -0700316 We accept any of BARE_BRANCHES in |branch_specs|, as
Dan Shiaceb91d2013-02-20 12:41:28 -0800317 well as _one_ string of the form '>=RXX' or '==RXX', where 'RXX' is a
Chris Masone96f16632012-04-04 18:36:03 -0700318 CrOS milestone number.
319
320 @param branch_specs: an iterable of branch specifiers.
321 @raise MalformedConfigEntry if there's a problem parsing |branch_specs|.
322 """
323 have_seen_numeric_constraint = False
324 for branch in branch_specs:
Chris Masone67f06d62012-04-12 15:16:56 -0700325 if branch in BARE_BRANCHES:
Chris Masone96f16632012-04-04 18:36:03 -0700326 continue
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -0700327 if not have_seen_numeric_constraint:
328 #TODO(beeps): Why was <= dropped on the floor?
329 if branch.startswith('>=R') or branch.startswith('==R'):
330 have_seen_numeric_constraint = True
331 elif 'tot' in branch:
332 TotMilestoneManager().ConvertTotSpec(
333 branch[branch.index('tot'):])
334 have_seen_numeric_constraint = True
Chris Masone96f16632012-04-04 18:36:03 -0700335 continue
Chris Masone97cf0a72012-05-16 09:55:52 -0700336 raise MalformedConfigEntry("%s isn't a valid branch spec." % branch)
Chris Masone96f16632012-04-04 18:36:03 -0700337
338
Alex Millerf2b57442013-09-07 18:40:02 -0700339 def __init__(self, name, suite, branch_specs, pool=None, num=None,
Dan Shia25e0d42015-07-23 15:00:04 -0700340 boards=None, priority=None, timeout=None, file_bugs=False,
341 cros_build_spec=None, firmware_rw_build_spec=None,
Dan Shib49bb8b2016-03-01 15:29:27 -0800342 firmware_ro_build_spec=None, test_source=None, job_retry=False,
343 hour=None, day=None, os_type=OS_TYPE_CROS,
Dan Shi84585362016-10-03 14:11:43 -0700344 launch_control_branches=None, launch_control_targets=None,
345 testbed_dut_count=None):
Chris Masonefad911a2012-03-29 12:30:26 -0700346 """Constructor
347
Chris Masone96f16632012-04-04 18:36:03 -0700348 Given an iterable in |branch_specs|, pre-vetted using CheckBranchSpecs,
349 we'll store them such that _FitsSpec() can be used to check whether a
350 given branch 'fits' with the specifications passed in here.
351 For example, given branch_specs = ['factory', '>=R18'], we'd set things
352 up so that _FitsSpec() would return True for 'factory', or 'RXX'
Dan Shiaceb91d2013-02-20 12:41:28 -0800353 where XX is a number >= 18. Same check is done for branch_specs = [
354 'factory', '==R18'], which limit the test to only one specific branch.
Chris Masone96f16632012-04-04 18:36:03 -0700355
356 Given branch_specs = ['factory', 'firmware'], _FitsSpec()
357 would pass only those two specific strings.
358
359 Example usage:
Chris Masonecc4631d2012-04-20 12:06:39 -0700360 t = Task('Name', 'suite', ['factory', '>=R18'])
Chris Masone96f16632012-04-04 18:36:03 -0700361 t._FitsSpec('factory') # True
362 t._FitsSpec('R19') # True
363 t._FitsSpec('R17') # False
364 t._FitsSpec('firmware') # False
365 t._FitsSpec('goober') # False
366
Dan Shiaceb91d2013-02-20 12:41:28 -0800367 t = Task('Name', 'suite', ['factory', '==R18'])
368 t._FitsSpec('R19') # False, branch does not equal to 18
369 t._FitsSpec('R18') # True
370 t._FitsSpec('R17') # False
371
Dan Shia25e0d42015-07-23 15:00:04 -0700372 cros_build_spec and firmware_rw_build_spec are set for tests require
373 firmware update on the dut. Only one of them can be set.
374 For example:
375 branch_specs: ==tot
376 firmware_rw_build_spec: firmware
377 test_source: cros
378 This will run test using latest build on firmware branch, and the latest
379 ChromeOS build on ToT. The test source build is ChromeOS build.
380
381 branch_specs: firmware
382 cros_build_spec: ==tot-1
383 test_source: firmware_rw
384 This will run test using latest build on firmware branch, and the latest
385 ChromeOS build on dev channel (ToT-1). The test source build is the
386 firmware RW build.
387
Dan Shi59562a82016-01-06 16:05:31 -0800388 branch_specs: ==tot
389 firmware_rw_build_spec: cros
390 test_source: cros
391 This will run test using latest ChromeOS and firmware RW build on ToT.
392 ChromeOS build on ToT. The test source build is ChromeOS build.
393
Chris Masone3eeaf0a2012-08-09 14:07:27 -0700394 @param name: name of this task, e.g. 'NightlyPower'
Chris Masonefad911a2012-03-29 12:30:26 -0700395 @param suite: the name of the suite to run, e.g. 'bvt'
Chris Masone96f16632012-04-04 18:36:03 -0700396 @param branch_specs: a pre-vetted iterable of branch specifiers,
397 e.g. ['>=R18', 'factory']
Chris Masonefad911a2012-03-29 12:30:26 -0700398 @param pool: the pool of machines to use for scheduling purposes.
399 Default: None
Chris Masone3eeaf0a2012-08-09 14:07:27 -0700400 @param num: the number of devices across which to shard the test suite.
Aviv Keshetd83ef442013-01-16 16:19:35 -0800401 Type: integer or None
Chris Masone3eeaf0a2012-08-09 14:07:27 -0700402 Default: None
Dan Shi9f256d92016-01-22 00:09:25 -0800403 @param boards: A comma separated list of boards to run this task on.
Alex Millerf2b57442013-09-07 18:40:02 -0700404 Default: Run on all boards.
Alex Millerc7bcf8b2013-09-07 20:13:20 -0700405 @param priority: The string name of a priority from
406 client.common_lib.priorities.Priority.
407 @param timeout: The max lifetime of the suite in hours.
Prashanth B6de2bde2014-03-25 18:45:02 -0700408 @param file_bugs: True if bug filing is desired for the suite created
409 for this task.
Dan Shia25e0d42015-07-23 15:00:04 -0700410 @param cros_build_spec: Spec used to determine the ChromeOS build to
411 test with a firmware build, e.g., tot, R41 etc.
Dan Shib49bb8b2016-03-01 15:29:27 -0800412 @param firmware_rw_build_spec: Spec used to determine the firmware RW
413 build test with a ChromeOS build.
414 @param firmware_ro_build_spec: Spec used to determine the firmware RO
415 build test with a ChromeOS build.
Dan Shia25e0d42015-07-23 15:00:04 -0700416 @param test_source: The source of test code when firmware will be
Dan Shib49bb8b2016-03-01 15:29:27 -0800417 updated in the test. The value can be `firmware_rw`,
418 `firmware_ro` or `cros`.
Dan Shi29a16992015-09-22 11:29:58 -0700419 @param job_retry: Set to True to enable job-level retry. Default is
420 False.
Dan Shi9f256d92016-01-22 00:09:25 -0800421 @param hour: An integer specifying the hour that a nightly run should
422 be triggered, default is set to 21.
Dan Shice1f20a2016-01-25 17:27:40 -0800423 @param day: An integer specifying the day of a week that a weekly run
Dan Shi2121a332016-02-25 14:22:22 -0800424 should be triggered, default is set to 5, which is Saturday.
425 @param os_type: Type of OS, e.g., cros, brillo, android. Default is
426 cros. The argument is required for android/brillo builds.
427 @param launch_control_branches: Comma separated string of Launch Control
428 branches. The argument is required and only applicable for
429 android/brillo builds.
430 @param launch_control_targets: Comma separated string of build targets
431 for Launch Control builds. The argument is required and only
432 applicable for android/brillo builds.
Dan Shi84585362016-10-03 14:11:43 -0700433 @param testbed_dut_count: Number of duts to test when using a testbed.
Chris Masonefad911a2012-03-29 12:30:26 -0700434 """
Chris Masonecc4631d2012-04-20 12:06:39 -0700435 self._name = name
Chris Masonefad911a2012-03-29 12:30:26 -0700436 self._suite = suite
Chris Masone96f16632012-04-04 18:36:03 -0700437 self._branch_specs = branch_specs
Chris Masonefad911a2012-03-29 12:30:26 -0700438 self._pool = pool
Aviv Keshetd83ef442013-01-16 16:19:35 -0800439 self._num = num
Alex Millerc7bcf8b2013-09-07 20:13:20 -0700440 self._priority = priority
441 self._timeout = timeout
Prashanth B6de2bde2014-03-25 18:45:02 -0700442 self._file_bugs = file_bugs
Dan Shia25e0d42015-07-23 15:00:04 -0700443 self._cros_build_spec = cros_build_spec
444 self._firmware_rw_build_spec = firmware_rw_build_spec
Dan Shib49bb8b2016-03-01 15:29:27 -0800445 self._firmware_ro_build_spec = firmware_ro_build_spec
Dan Shia25e0d42015-07-23 15:00:04 -0700446 self._test_source = test_source
Dan Shi29a16992015-09-22 11:29:58 -0700447 self._job_retry = job_retry
Dan Shi2121a332016-02-25 14:22:22 -0800448 self._hour = hour
449 self._day = day
450 self._os_type = os_type
451 self._launch_control_branches = (
452 [b.strip() for b in launch_control_branches.split(',')]
453 if launch_control_branches else [])
454 self._launch_control_targets = (
455 [t.strip() for t in launch_control_targets.split(',')]
456 if launch_control_targets else [])
Dan Shi84585362016-10-03 14:11:43 -0700457 self._testbed_dut_count = testbed_dut_count
Dan Shia25e0d42015-07-23 15:00:04 -0700458
Dan Shib49bb8b2016-03-01 15:29:27 -0800459 if ((self._firmware_rw_build_spec or self._firmware_ro_build_spec or
460 cros_build_spec) and
461 not self.test_source in [Builds.FIRMWARE_RW, Builds.FIRMWARE_RO,
462 Builds.CROS]):
Dan Shia25e0d42015-07-23 15:00:04 -0700463 raise MalformedConfigEntry(
464 'You must specify the build for test source. It can only '
Dan Shib49bb8b2016-03-01 15:29:27 -0800465 'be `firmware_rw`, `firmware_ro` or `cros`.')
Dan Shia25e0d42015-07-23 15:00:04 -0700466 if self._firmware_rw_build_spec and cros_build_spec:
467 raise MalformedConfigEntry(
468 'You cannot specify both firmware_rw_build_spec and '
469 'cros_build_spec. firmware_rw_build_spec is used to specify'
470 ' a firmware build when the suite requires firmware to be '
Dan Shi59562a82016-01-06 16:05:31 -0800471 'updated in the dut, its value can only be `firmware` or '
472 '`cros`. cros_build_spec is used to specify a ChromeOS '
473 'build when build_specs is set to firmware.')
Dan Shia25e0d42015-07-23 15:00:04 -0700474 if (self._firmware_rw_build_spec and
Dan Shi59562a82016-01-06 16:05:31 -0800475 self._firmware_rw_build_spec not in ['firmware', 'cros']):
Dan Shia25e0d42015-07-23 15:00:04 -0700476 raise MalformedConfigEntry(
Dan Shi59562a82016-01-06 16:05:31 -0800477 'firmware_rw_build_spec can only be empty, firmware or '
478 'cros. It does not support other build type yet.')
Chris Masone96f16632012-04-04 18:36:03 -0700479
Dan Shi84585362016-10-03 14:11:43 -0700480 if os_type not in OS_TYPES_LAUNCH_CONTROL and self._testbed_dut_count:
481 raise MalformedConfigEntry(
482 'testbed_dut_count is only applicable to testbed to run '
483 'test with builds from Launch Control.')
484
Chris Masone96f16632012-04-04 18:36:03 -0700485 self._bare_branches = []
Dan Shiaceb91d2013-02-20 12:41:28 -0800486 self._version_equal_constraint = False
Dan Shibde10772015-08-18 10:15:58 -0700487 self._version_gte_constraint = False
488 self._version_lte_constraint = False
Chris Masone67f06d62012-04-12 15:16:56 -0700489 if not branch_specs:
490 # Any milestone is OK.
491 self._numeric_constraint = version.LooseVersion('0')
492 else:
493 self._numeric_constraint = None
494 for spec in branch_specs:
Prashanth Balasubramanianf571aa62014-10-13 18:09:44 -0700495 if 'tot' in spec.lower():
496 tot_str = spec[spec.index('tot'):]
497 spec = spec.replace(
498 tot_str, TotMilestoneManager().ConvertTotSpec(
Dan Shibde10772015-08-18 10:15:58 -0700499 tot_str))
Chris Masone67f06d62012-04-12 15:16:56 -0700500 if spec.startswith('>='):
501 self._numeric_constraint = version.LooseVersion(
Dan Shibde10772015-08-18 10:15:58 -0700502 spec.lstrip('>=R'))
503 self._version_gte_constraint = True
504 elif spec.startswith('<='):
505 self._numeric_constraint = version.LooseVersion(
506 spec.lstrip('<=R'))
507 self._version_lte_constraint = True
Dan Shiaceb91d2013-02-20 12:41:28 -0800508 elif spec.startswith('=='):
509 self._version_equal_constraint = True
510 self._numeric_constraint = version.LooseVersion(
Dan Shibde10772015-08-18 10:15:58 -0700511 spec.lstrip('==R'))
Chris Masone67f06d62012-04-12 15:16:56 -0700512 else:
513 self._bare_branches.append(spec)
Alex Millerf2b57442013-09-07 18:40:02 -0700514
Aviv Keshet52c7a212015-12-07 15:27:22 -0800515 # Since we expect __hash__() and other comparator methods to be used
Chris Masonefad911a2012-03-29 12:30:26 -0700516 # frequently by set operations, and they use str() a lot, pre-compute
517 # the string representation of this object.
Aviv Keshet8ce3c982013-01-24 09:23:13 -0800518 if num is None:
519 numStr = '[Default num]'
520 else:
521 numStr = '%d' % num
Alex Millerf2b57442013-09-07 18:40:02 -0700522
523 if boards is None:
524 self._boards = set()
525 boardsStr = '[All boards]'
526 else:
527 self._boards = set([x.strip() for x in boards.split(',')])
528 boardsStr = boards
529
Dan Shi481b8b62016-03-08 13:03:08 -0800530 time_str = ''
531 if self._hour:
532 time_str = ' Run at %d:00.' % self._hour
533 elif self._day:
534 time_str = ' Run on %s.' % _WEEKDAYS[self._day]
Dan Shi2121a332016-02-25 14:22:22 -0800535 if os_type == OS_TYPE_CROS:
536 self._str = ('%s: %s on %s with pool %s, boards [%s], file_bugs = '
Dan Shi481b8b62016-03-08 13:03:08 -0800537 '%s across %s machines.%s' %
Dan Shi2121a332016-02-25 14:22:22 -0800538 (self.__class__.__name__, suite, branch_specs, pool,
Dan Shi481b8b62016-03-08 13:03:08 -0800539 boardsStr, self._file_bugs, numStr, time_str))
Dan Shi2121a332016-02-25 14:22:22 -0800540 else:
Dan Shi84585362016-10-03 14:11:43 -0700541 testbed_dut_count_str = '.'
542 if self._testbed_dut_count:
543 testbed_dut_count_str = (', each with %d duts.' %
544 self._testbed_dut_count)
Dan Shi2121a332016-02-25 14:22:22 -0800545 self._str = ('%s: %s on branches %s and targets %s with pool %s, '
Dan Shi84585362016-10-03 14:11:43 -0700546 'boards [%s], file_bugs = %s across %s machines%s%s' %
Dan Shi2121a332016-02-25 14:22:22 -0800547 (self.__class__.__name__, suite,
548 launch_control_branches, launch_control_targets,
Dan Shi84585362016-10-03 14:11:43 -0700549 pool, boardsStr, self._file_bugs, numStr,
550 testbed_dut_count_str, time_str))
Chris Masone96f16632012-04-04 18:36:03 -0700551
552
553 def _FitsSpec(self, branch):
554 """Checks if a branch is deemed OK by this instance's branch specs.
555
556 When called on a branch name, will return whether that branch
Dan Shiaceb91d2013-02-20 12:41:28 -0800557 'fits' the specifications stored in self._bare_branches,
Dan Shibde10772015-08-18 10:15:58 -0700558 self._numeric_constraint, self._version_equal_constraint,
559 self._version_gte_constraint and self._version_lte_constraint.
Chris Masone96f16632012-04-04 18:36:03 -0700560
561 @param branch: the branch to check.
562 @return True if b 'fits' with stored specs, False otherwise.
563 """
Chris Masone657e1552012-05-30 17:06:20 -0700564 if branch in BARE_BRANCHES:
565 return branch in self._bare_branches
Dan Shiaceb91d2013-02-20 12:41:28 -0800566 if self._numeric_constraint:
567 if self._version_equal_constraint:
568 return version.LooseVersion(branch) == self._numeric_constraint
Dan Shibde10772015-08-18 10:15:58 -0700569 elif self._version_gte_constraint:
570 return version.LooseVersion(branch) >= self._numeric_constraint
571 elif self._version_lte_constraint:
572 return version.LooseVersion(branch) <= self._numeric_constraint
Dan Shiaceb91d2013-02-20 12:41:28 -0800573 else:
Dan Shibde10772015-08-18 10:15:58 -0700574 # Default to great or equal constraint.
Dan Shiaceb91d2013-02-20 12:41:28 -0800575 return version.LooseVersion(branch) >= self._numeric_constraint
576 else:
577 return False
Chris Masonefad911a2012-03-29 12:30:26 -0700578
579
580 @property
Alex Miller9979b5a2012-11-01 17:36:12 -0700581 def name(self):
Dan Shiaceb91d2013-02-20 12:41:28 -0800582 """Name of this task, e.g. 'NightlyPower'."""
Alex Miller9979b5a2012-11-01 17:36:12 -0700583 return self._name
584
585
586 @property
Chris Masonefad911a2012-03-29 12:30:26 -0700587 def suite(self):
Dan Shiaceb91d2013-02-20 12:41:28 -0800588 """Name of the suite to run, e.g. 'bvt'."""
Chris Masonefad911a2012-03-29 12:30:26 -0700589 return self._suite
590
591
592 @property
Chris Masone96f16632012-04-04 18:36:03 -0700593 def branch_specs(self):
Dan Shiaceb91d2013-02-20 12:41:28 -0800594 """a pre-vetted iterable of branch specifiers,
595 e.g. ['>=R18', 'factory']."""
Chris Masone96f16632012-04-04 18:36:03 -0700596 return self._branch_specs
Chris Masonefad911a2012-03-29 12:30:26 -0700597
598
599 @property
Chris Masone3fba86f2012-04-03 10:06:56 -0700600 def pool(self):
Dan Shiaceb91d2013-02-20 12:41:28 -0800601 """The pool of machines to use for scheduling purposes."""
Chris Masone3fba86f2012-04-03 10:06:56 -0700602 return self._pool
Chris Masonefad911a2012-03-29 12:30:26 -0700603
604
Alex Miller9979b5a2012-11-01 17:36:12 -0700605 @property
606 def num(self):
Dan Shiaceb91d2013-02-20 12:41:28 -0800607 """The number of devices across which to shard the test suite.
608 Type: integer or None"""
Alex Miller9979b5a2012-11-01 17:36:12 -0700609 return self._num
610
611
Alex Millerf2b57442013-09-07 18:40:02 -0700612 @property
613 def boards(self):
614 """The boards on which to run this suite.
615 Type: Iterable of strings"""
616 return self._boards
617
618
Alex Millerc7bcf8b2013-09-07 20:13:20 -0700619 @property
620 def priority(self):
621 """The priority of the suite"""
622 return self._priority
623
624
625 @property
626 def timeout(self):
627 """The maximum lifetime of the suite in hours."""
628 return self._timeout
629
630
Dan Shia25e0d42015-07-23 15:00:04 -0700631 @property
632 def cros_build_spec(self):
633 """The build spec of ChromeOS to test with a firmware build."""
634 return self._cros_build_spec
635
636
637 @property
638 def firmware_rw_build_spec(self):
Dan Shib49bb8b2016-03-01 15:29:27 -0800639 """The build spec of RW firmware to test with a ChromeOS build.
640
641 The value can be firmware or cros.
642 """
Dan Shia25e0d42015-07-23 15:00:04 -0700643 return self._firmware_rw_build_spec
644
645
646 @property
Dan Shib49bb8b2016-03-01 15:29:27 -0800647 def firmware_ro_build_spec(self):
648 """The build spec of RO firmware to test with a ChromeOS build.
649
650 The value can be stable, firmware or cros, where stable is the stable
651 firmware build retrieved from stable_version table.
652 """
653 return self._firmware_ro_build_spec
654
655
656 @property
Dan Shia25e0d42015-07-23 15:00:04 -0700657 def test_source(self):
Dan Shib49bb8b2016-03-01 15:29:27 -0800658 """Source of the test code, value can be `firmware_rw`, `firmware_ro` or
659 `cros`."""
Dan Shia25e0d42015-07-23 15:00:04 -0700660 return self._test_source
661
662
Dan Shi2121a332016-02-25 14:22:22 -0800663 @property
664 def hour(self):
665 """An integer specifying the hour that a nightly run should be triggered
666 """
667 return self._hour
668
669
670 @property
671 def day(self):
672 """An integer specifying the day of a week that a weekly run should be
673 triggered"""
674 return self._day
675
676
677 @property
678 def os_type(self):
679 """Type of OS, e.g., cros, brillo, android."""
680 return self._os_type
681
682
683 @property
684 def launch_control_branches(self):
685 """A list of Launch Control builds."""
686 return self._launch_control_branches
687
688
689 @property
690 def launch_control_targets(self):
691 """A list of Launch Control targets."""
692 return self._launch_control_targets
693
694
Chris Masonefad911a2012-03-29 12:30:26 -0700695 def __str__(self):
696 return self._str
697
698
Chris Masone3eeaf0a2012-08-09 14:07:27 -0700699 def __repr__(self):
700 return self._str
701
702
Chris Masonefad911a2012-03-29 12:30:26 -0700703 def __lt__(self, other):
704 return str(self) < str(other)
705
706
707 def __le__(self, other):
708 return str(self) <= str(other)
709
710
711 def __eq__(self, other):
712 return str(self) == str(other)
713
714
715 def __ne__(self, other):
716 return str(self) != str(other)
717
718
719 def __gt__(self, other):
720 return str(self) > str(other)
721
722
723 def __ge__(self, other):
724 return str(self) >= str(other)
725
726
727 def __hash__(self):
728 """Allows instances to be correctly deduped when used in a set."""
729 return hash(str(self))
730
731
Dan Shia25e0d42015-07-23 15:00:04 -0700732 def _GetCrOSBuild(self, mv, board):
733 """Get the ChromeOS build name to test with firmware build.
734
735 The ChromeOS build to be used is determined by `self.cros_build_spec`.
736 Its value can be:
737 tot: use the latest ToT build.
738 tot-x: use the latest build in x milestone before ToT.
739 Rxx: use the latest build on xx milestone.
740
741 @param board: the board against which to run self._suite.
742 @param mv: an instance of manifest_versions.ManifestVersions.
743
744 @return: The ChromeOS build name to test with firmware build.
745
746 """
747 if not self.cros_build_spec:
748 return None
749 if self.cros_build_spec.startswith('tot'):
750 milestone = TotMilestoneManager().ConvertTotSpec(
751 self.cros_build_spec)[1:]
752 elif self.cros_build_spec.startswith('R'):
753 milestone = self.cros_build_spec[1:]
754 milestone, latest_manifest = mv.GetLatestManifest(
755 board, 'release', milestone=milestone)
756 latest_build = base_event.BuildName(board, 'release', milestone,
757 latest_manifest)
758 logging.debug('Found latest build of %s for spec %s: %s',
759 board, self.cros_build_spec, latest_build)
760 return latest_build
761
762
Dan Shib49bb8b2016-03-01 15:29:27 -0800763 def _GetFirmwareBuild(self, spec, mv, board):
764 """Get the firmware build name to test with ChromeOS build.
Dan Shia25e0d42015-07-23 15:00:04 -0700765
Dan Shi648ce922016-03-26 00:22:47 -0700766 @param spec: build spec for RO or RW firmware, e.g., firmware, cros.
767 For RO firmware, the value can also be in the format of
768 released_ro_X, where X is the index of the list or RO builds
769 defined in global config RELEASED_RO_BUILDS_[board].
770 For example, for spec `released_ro_2`, and global config
771 CROS/RELEASED_RO_BUILDS_veyron_jerry: build1,build2
772 the return firmare RO build should be build2.
Dan Shia25e0d42015-07-23 15:00:04 -0700773 @param mv: an instance of manifest_versions.ManifestVersions.
774 @param board: the board against which to run self._suite.
Dan Shia25e0d42015-07-23 15:00:04 -0700775
Dan Shib49bb8b2016-03-01 15:29:27 -0800776 @return: The firmware build name to test with ChromeOS build.
Dan Shia25e0d42015-07-23 15:00:04 -0700777 """
Dan Shib49bb8b2016-03-01 15:29:27 -0800778 if spec == 'stable':
779 # TODO(crbug.com/577316): Query stable RO firmware.
780 raise NotImplementedError('`stable` RO firmware build is not '
781 'supported yet.')
782 if not spec:
Dan Shia25e0d42015-07-23 15:00:04 -0700783 return None
Dan Shi648ce922016-03-26 00:22:47 -0700784
785 if spec.startswith('released_ro_'):
786 index = int(spec[12:])
787 released_ro_builds = CONFIG.get_config_value(
788 'CROS', 'RELEASED_RO_BUILDS_%s' % board, type=str,
789 default='').split(',')
790 if not released_ro_builds or len(released_ro_builds) < index:
791 return None
792 else:
793 return released_ro_builds[index-1]
794
Dan Shib49bb8b2016-03-01 15:29:27 -0800795 # build_type is the build type of the firmware build, e.g., factory,
796 # firmware or release. If spec is set to cros, build type should be
797 # mapped to release.
798 build_type = 'release' if spec == 'cros' else spec
Dan Shia25e0d42015-07-23 15:00:04 -0700799 latest_milestone, latest_manifest = mv.GetLatestManifest(
800 board, build_type)
801 latest_build = base_event.BuildName(board, build_type, latest_milestone,
802 latest_manifest)
803 logging.debug('Found latest firmware build of %s for spec %s: %s',
Dan Shib49bb8b2016-03-01 15:29:27 -0800804 board, spec, latest_build)
Dan Shia25e0d42015-07-23 15:00:04 -0700805 return latest_build
806
807
Alex Miller7ce1b362012-07-10 09:24:10 -0700808 def AvailableHosts(self, scheduler, board):
809 """Query what hosts are able to run a test on a board and pool
810 combination.
Alex Miller511a9e32012-07-03 09:16:47 -0700811
812 @param scheduler: an instance of DedupingScheduler, as defined in
813 deduping_scheduler.py
814 @param board: the board against which one wants to run the test.
Alex Miller7ce1b362012-07-10 09:24:10 -0700815 @return The list of hosts meeting the board and pool requirements,
816 or None if no hosts were found."""
Alex Millerf2b57442013-09-07 18:40:02 -0700817 if self._boards and board not in self._boards:
818 return []
819
Dan Shi8a1fbac2016-10-13 12:36:18 -0700820 board_label = Labels.BOARD_PREFIX + board
821 if self._testbed_dut_count:
822 board_label += '-%d' % self._testbed_dut_count
823 labels = [board_label]
Alex Miller511a9e32012-07-03 09:16:47 -0700824 if self._pool:
Chris Masonecd214e02012-07-10 16:22:10 -0700825 labels.append(Labels.POOL_PREFIX + self._pool)
Alex Miller511a9e32012-07-03 09:16:47 -0700826
Prashanth B6de2bde2014-03-25 18:45:02 -0700827 return scheduler.CheckHostsExist(multiple_labels=labels)
Alex Miller511a9e32012-07-03 09:16:47 -0700828
829
Alex Millerd621cf22012-07-11 13:57:10 -0700830 def ShouldHaveAvailableHosts(self):
831 """As a sanity check, return true if we know for certain that
832 we should be able to schedule this test. If we claim this test
833 should be able to run, and it ends up not being scheduled, then
834 a warning will be reported.
835
836 @return True if this test should be able to run, False otherwise.
837 """
838 return self._pool == 'bvt'
839
840
Dan Shi2121a332016-02-25 14:22:22 -0800841 def _ScheduleSuite(self, scheduler, cros_build, firmware_rw_build,
Dan Shib49bb8b2016-03-01 15:29:27 -0800842 firmware_ro_build, test_source_build,
843 launch_control_build, board, force, run_prod_code=False):
Dan Shi2121a332016-02-25 14:22:22 -0800844 """Try to schedule a suite with given build and board information.
845
846 @param scheduler: an instance of DedupingScheduler, as defined in
847 deduping_scheduler.py
848 @oaran build: Build to run suite for, e.g., 'daisy-release/R18-1655.0.0'
849 and 'git_mnc_release/shamu-eng/123'.
850 @param firmware_rw_build: Firmware RW build to run test with.
Dan Shib49bb8b2016-03-01 15:29:27 -0800851 @param firmware_ro_build: Firmware RO build to run test with.
Dan Shi2121a332016-02-25 14:22:22 -0800852 @param test_source_build: Test source build, used for server-side
853 packaging.
854 @param launch_control_build: Name of a Launch Control build, e.g.,
855 'git_mnc_release/shamu-eng/123'
856 @param board: the board against which to run self._suite.
857 @param force: Always schedule the suite.
858 @param run_prod_code: If True, the suite will run the test code that
859 lives in prod aka the test code currently on the
860 lab servers. If False, the control files and test
861 code for this suite run will be retrieved from the
862 build artifacts. Default is False.
863 """
864 test_source_build_msg = (
865 ' Test source build is %s.' % test_source_build
Dan Shi8446fac2016-03-02 22:07:39 -0800866 if test_source_build else '')
Dan Shi2121a332016-02-25 14:22:22 -0800867 firmware_rw_build_msg = (
868 ' Firmware RW build is %s.' % firmware_rw_build
Dan Shi8446fac2016-03-02 22:07:39 -0800869 if firmware_rw_build else '')
Dan Shib49bb8b2016-03-01 15:29:27 -0800870 firmware_ro_build_msg = (
871 ' Firmware RO build is %s.' % firmware_ro_build
Dan Shi8446fac2016-03-02 22:07:39 -0800872 if firmware_ro_build else '')
Dan Shi84585362016-10-03 14:11:43 -0700873 # If testbed_dut_count is set, the suite is for testbed. Update build
874 # and board with the dut count.
875 if self._testbed_dut_count:
876 launch_control_build = '%s#%d' % (launch_control_build,
877 self._testbed_dut_count)
878 test_source_build = launch_control_build
879 board = '%s-%d' % (board, self._testbed_dut_count)
Dan Shi2121a332016-02-25 14:22:22 -0800880 build_string = cros_build or launch_control_build
Dan Shib49bb8b2016-03-01 15:29:27 -0800881 logging.debug('Schedule %s for build %s.%s%s%s',
Dan Shi2121a332016-02-25 14:22:22 -0800882 self._suite, build_string, test_source_build_msg,
Dan Shib49bb8b2016-03-01 15:29:27 -0800883 firmware_rw_build_msg, firmware_ro_build_msg)
Dan Shi2121a332016-02-25 14:22:22 -0800884
885 if not scheduler.ScheduleSuite(
886 self._suite, board, cros_build, self._pool, self._num,
887 self._priority, self._timeout, force,
888 file_bugs=self._file_bugs,
889 firmware_rw_build=firmware_rw_build,
Dan Shib49bb8b2016-03-01 15:29:27 -0800890 firmware_ro_build=firmware_ro_build,
Dan Shi2121a332016-02-25 14:22:22 -0800891 test_source_build=test_source_build,
892 job_retry=self._job_retry,
893 launch_control_build=launch_control_build,
Dan Shi84585362016-10-03 14:11:43 -0700894 run_prod_code=run_prod_code,
895 testbed_dut_count=self._testbed_dut_count):
Dan Shi2121a332016-02-25 14:22:22 -0800896 logging.info('Skipping scheduling %s on %s for %s',
897 self._suite, build_string, board)
898
899
900 def _Run_CrOS_Builds(self, scheduler, branch_builds, board, force=False,
901 mv=None):
902 """Run this task for CrOS builds. Returns False if it should be
903 destroyed.
Chris Masonefad911a2012-03-29 12:30:26 -0700904
Chris Masone013859b2012-04-01 13:45:26 -0700905 Execute this task. Attempt to schedule the associated suite.
906 Return True if this task should be kept around, False if it
907 should be destroyed. This allows for one-shot Tasks.
Chris Masonefad911a2012-03-29 12:30:26 -0700908
909 @param scheduler: an instance of DedupingScheduler, as defined in
910 deduping_scheduler.py
Chris Masone05b19442012-04-17 13:37:55 -0700911 @param branch_builds: a dict mapping branch name to the build(s) to
Chris Masone96f16632012-04-04 18:36:03 -0700912 install for that branch, e.g.
Chris Masone05b19442012-04-17 13:37:55 -0700913 {'R18': ['x86-alex-release/R18-1655.0.0'],
914 'R19': ['x86-alex-release/R19-2077.0.0']}
Chris Masone96f16632012-04-04 18:36:03 -0700915 @param board: the board against which to run self._suite.
Chris Masonefad911a2012-03-29 12:30:26 -0700916 @param force: Always schedule the suite.
Dan Shia25e0d42015-07-23 15:00:04 -0700917 @param mv: an instance of manifest_versions.ManifestVersions.
918
Chris Masone013859b2012-04-01 13:45:26 -0700919 @return True if the task should be kept, False if not
Dan Shia25e0d42015-07-23 15:00:04 -0700920
Chris Masonefad911a2012-03-29 12:30:26 -0700921 """
Chris Masonea3a38172012-05-14 15:19:56 -0700922 logging.info('Running %s on %s', self._name, board)
Dan Shia25e0d42015-07-23 15:00:04 -0700923 is_firmware_build = 'firmware' in self.branch_specs
Dan Shib49bb8b2016-03-01 15:29:27 -0800924
925 # firmware_xx_build is only needed if firmware_xx_build_spec is given.
Dan Shia25e0d42015-07-23 15:00:04 -0700926 firmware_rw_build = None
Dan Shib49bb8b2016-03-01 15:29:27 -0800927 firmware_ro_build = None
Dan Shia25e0d42015-07-23 15:00:04 -0700928 try:
929 if is_firmware_build:
930 # When build specified in branch_specs is a firmware build,
931 # we need a ChromeOS build to test with the firmware build.
932 cros_build = self._GetCrOSBuild(mv, board)
Dan Shib49bb8b2016-03-01 15:29:27 -0800933 elif self.firmware_rw_build_spec or self.firmware_ro_build_spec:
934 # When firmware_xx_build_spec is specified, the test involves
935 # updating the RW firmware by firmware build specified in
936 # firmware_xx_build_spec.
937 firmware_rw_build = self._GetFirmwareBuild(
938 self.firmware_rw_build_spec, mv, board)
939 firmware_ro_build = self._GetFirmwareBuild(
940 self.firmware_ro_build_spec, mv, board)
Dan Shi648ce922016-03-26 00:22:47 -0700941 # If RO firmware is specified, force to create suite, because
942 # dedupe based on test source build does not reflect the change
943 # of RO firmware.
944 if firmware_ro_build:
945 force = True
Dan Shia25e0d42015-07-23 15:00:04 -0700946 except manifest_versions.QueryException as e:
947 logging.error(e)
948 logging.error('Running %s on %s is failed. Failed to find build '
949 'required to run the suite.', self._name, board)
950 return False
951
Dan Shi648ce922016-03-26 00:22:47 -0700952 # Return if there is no firmware RO build found for given spec.
953 if not firmware_ro_build and self.firmware_ro_build_spec:
954 return True
955
Chris Masone96f16632012-04-04 18:36:03 -0700956 builds = []
Chris Masonefe5a5092012-04-11 18:29:07 -0700957 for branch, build in branch_builds.iteritems():
Chris Masonea3a38172012-05-14 15:19:56 -0700958 logging.info('Checking if %s fits spec %r',
959 branch, self.branch_specs)
Chris Masone96f16632012-04-04 18:36:03 -0700960 if self._FitsSpec(branch):
Dan Shibde10772015-08-18 10:15:58 -0700961 logging.debug('Build %s fits the spec.', build)
Chris Masone05b19442012-04-17 13:37:55 -0700962 builds.extend(build)
Chris Masone96f16632012-04-04 18:36:03 -0700963 for build in builds:
Chris Masone3fba86f2012-04-03 10:06:56 -0700964 try:
Dan Shia25e0d42015-07-23 15:00:04 -0700965 if is_firmware_build:
966 firmware_rw_build = build
967 else:
968 cros_build = build
969 if self.test_source == Builds.FIRMWARE_RW:
970 test_source_build = firmware_rw_build
971 elif self.test_source == Builds.CROS:
972 test_source_build = cros_build
973 else:
974 test_source_build = None
Dan Shi2121a332016-02-25 14:22:22 -0800975 self._ScheduleSuite(scheduler, cros_build, firmware_rw_build,
Dan Shib49bb8b2016-03-01 15:29:27 -0800976 firmware_ro_build, test_source_build,
977 None, board, force)
Chris Masone3fba86f2012-04-03 10:06:56 -0700978 except deduping_scheduler.DedupingSchedulerException as e:
979 logging.error(e)
Chris Masonefad911a2012-03-29 12:30:26 -0700980 return True
981
982
Dan Shi2121a332016-02-25 14:22:22 -0800983 def _Run_LaunchControl_Builds(self, scheduler, launch_control_builds, board,
984 force=False):
985 """Run this task. Returns False if it should be destroyed.
986
987 Execute this task. Attempt to schedule the associated suite.
988 Return True if this task should be kept around, False if it
989 should be destroyed. This allows for one-shot Tasks.
990
991 @param scheduler: an instance of DedupingScheduler, as defined in
992 deduping_scheduler.py
993 @param launch_control_builds: A list of Launch Control builds.
994 @param board: the board against which to run self._suite.
995 @param force: Always schedule the suite.
996
997 @return True if the task should be kept, False if not
998
999 """
1000 logging.info('Running %s on %s', self._name, board)
1001 for build in launch_control_builds:
1002 try:
Dan Shi8446fac2016-03-02 22:07:39 -08001003 self._ScheduleSuite(scheduler, None, None, None,
1004 test_source_build=build,
Dan Shi2121a332016-02-25 14:22:22 -08001005 launch_control_build=build, board=board,
1006 force=force, run_prod_code=True)
1007 except deduping_scheduler.DedupingSchedulerException as e:
1008 logging.error(e)
1009 return True
1010
1011
1012 def Run(self, scheduler, branch_builds, board, force=False, mv=None,
1013 launch_control_builds=None):
1014 """Run this task. Returns False if it should be destroyed.
1015
1016 Execute this task. Attempt to schedule the associated suite.
1017 Return True if this task should be kept around, False if it
1018 should be destroyed. This allows for one-shot Tasks.
1019
1020 @param scheduler: an instance of DedupingScheduler, as defined in
1021 deduping_scheduler.py
1022 @param branch_builds: a dict mapping branch name to the build(s) to
1023 install for that branch, e.g.
1024 {'R18': ['x86-alex-release/R18-1655.0.0'],
1025 'R19': ['x86-alex-release/R19-2077.0.0']}
1026 @param board: the board against which to run self._suite.
1027 @param force: Always schedule the suite.
1028 @param mv: an instance of manifest_versions.ManifestVersions.
1029 @param launch_control_builds: A list of Launch Control builds.
1030
1031 @return True if the task should be kept, False if not
1032
1033 """
1034 if ((self._os_type == OS_TYPE_CROS and not branch_builds) or
1035 (self._os_type != OS_TYPE_CROS and not launch_control_builds)):
1036 logging.debug('No build to run, skip running %s on %s.', self._name,
1037 board)
1038 # Return True so the task will be kept, as the given build and board
1039 # do not match.
1040 return True
1041
1042 if self._os_type == OS_TYPE_CROS:
1043 return self._Run_CrOS_Builds(
1044 scheduler, branch_builds, board, force, mv)
1045 else:
1046 return self._Run_LaunchControl_Builds(
1047 scheduler, launch_control_builds, board, force)
1048
1049
Chris Masone013859b2012-04-01 13:45:26 -07001050class OneShotTask(Task):
1051 """A Task that can be run only once. Can schedule itself."""
Chris Masonefad911a2012-03-29 12:30:26 -07001052
1053
Dan Shi2121a332016-02-25 14:22:22 -08001054 def Run(self, scheduler, branch_builds, board, force=False, mv=None,
1055 launch_control_builds=None):
Chris Masone013859b2012-04-01 13:45:26 -07001056 """Run this task. Returns False, indicating it should be destroyed.
Chris Masonefad911a2012-03-29 12:30:26 -07001057
Chris Masone013859b2012-04-01 13:45:26 -07001058 Run this task. Attempt to schedule the associated suite.
1059 Return False, indicating to the caller that it should discard this task.
Chris Masonefad911a2012-03-29 12:30:26 -07001060
1061 @param scheduler: an instance of DedupingScheduler, as defined in
1062 deduping_scheduler.py
Chris Masone05b19442012-04-17 13:37:55 -07001063 @param branch_builds: a dict mapping branch name to the build(s) to
Chris Masone96f16632012-04-04 18:36:03 -07001064 install for that branch, e.g.
Chris Masone05b19442012-04-17 13:37:55 -07001065 {'R18': ['x86-alex-release/R18-1655.0.0'],
1066 'R19': ['x86-alex-release/R19-2077.0.0']}
Chris Masone96f16632012-04-04 18:36:03 -07001067 @param board: the board against which to run self._suite.
Chris Masonefad911a2012-03-29 12:30:26 -07001068 @param force: Always schedule the suite.
Dan Shia25e0d42015-07-23 15:00:04 -07001069 @param mv: an instance of manifest_versions.ManifestVersions.
Dan Shi2121a332016-02-25 14:22:22 -08001070 @param launch_control_builds: A list of Launch Control builds.
Dan Shia25e0d42015-07-23 15:00:04 -07001071
Chris Masonefad911a2012-03-29 12:30:26 -07001072 @return False
Dan Shia25e0d42015-07-23 15:00:04 -07001073
Chris Masonefad911a2012-03-29 12:30:26 -07001074 """
Dan Shia25e0d42015-07-23 15:00:04 -07001075 super(OneShotTask, self).Run(scheduler, branch_builds, board, force,
Dan Shi2121a332016-02-25 14:22:22 -08001076 mv, launch_control_builds)
Chris Masonefad911a2012-03-29 12:30:26 -07001077 return False