blob: fd79cebb152382cb07d5a7c1dbf22b49e40aa6f6 [file] [log] [blame]
Xinan Lin3ba18a02019-08-13 15:44:55 -07001# Copyright 2019 The Chromium OS Authors. All rights reserved.
Xinan Linc61196b2019-08-13 10:37:30 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Xinan Linc61196b2019-08-13 10:37:30 -07004"""Module for interacting with Buildbucket."""
Xinan Linc61196b2019-08-13 10:37:30 -07005
Xinan Lin9e4917d2019-11-04 10:58:47 -08006import collections
Xinan Lin3ba18a02019-08-13 15:44:55 -07007import datetime
linxinane5eb4552019-08-26 05:44:45 +00008import logging
Xinan Lin3ba18a02019-08-13 15:44:55 -07009import re
10import string
Jacob Kopczynskie56bf492020-08-07 13:20:12 -070011import types
Xinan Lin081b5d32020-03-23 17:37:55 -070012import uuid
Xinan Lin3ba18a02019-08-13 15:44:55 -070013
Xinan Lindf0698a2020-02-05 22:38:11 -080014import analytics
Xinan Lin3ba18a02019-08-13 15:44:55 -070015import build_lib
Xinan Linc61196b2019-08-13 10:37:30 -070016import constants
17import file_getter
18
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -070019from chromite.api.gen.test_platform import request_pb2 as ctp_request
Xinan Linc61196b2019-08-13 10:37:30 -070020from components import auth
Xinan Lin3ba18a02019-08-13 15:44:55 -070021from components.prpc import client as prpc_client
Prathmesh Prabhu2382a182019-09-07 21:18:10 -070022from infra_libs.buildbucket.proto import common_pb2 as bb_common_pb2
Xinan Lin3ba18a02019-08-13 15:44:55 -070023from infra_libs.buildbucket.proto import rpc_pb2, build_pb2
Xinan Linc61196b2019-08-13 10:37:30 -070024from infra_libs.buildbucket.proto.rpc_prpc_pb2 import BuildsServiceDescription
25
26from oauth2client import service_account
Xinan Lin3ba18a02019-08-13 15:44:55 -070027
28from google.protobuf import json_format, struct_pb2
Xinan Linc61196b2019-08-13 10:37:30 -070029
Xinan Linc61196b2019-08-13 10:37:30 -070030
Xinan Lin6e097382019-08-27 18:43:35 -070031GS_PREFIX = 'gs://chromeos-image-archive/'
32
Xinan Lin57e2d962020-03-30 17:24:53 -070033# The default prpc timeout(10 sec) is too short for the request_id
34# to propgate in buildbucket, and could not fully dedup the
35# ScheduleBuild request. Increase it while not hitting the default
36# GAE deadline(60 sec)
37PRPC_TIMEOUT_SEC = 55
38
39
Xinan Linc61196b2019-08-13 10:37:30 -070040def _get_client(address):
41 """Create a prpc client instance for given address."""
42 return prpc_client.Client(address, BuildsServiceDescription)
43
44
Xinan Lin3ba18a02019-08-13 15:44:55 -070045class BuildbucketRunError(Exception):
46 """Raised when interactions with buildbucket server fail."""
47
48
Xinan Linc61196b2019-08-13 10:37:30 -070049class TestPlatformClient(object):
50 """prpc client for cros_test_platform, aka frontdoor."""
Xinan Linc61196b2019-08-13 10:37:30 -070051 def __init__(self, address, project, bucket, builder):
52 self.client = _get_client(address)
53 self.builder = build_pb2.BuilderID(project=project,
54 bucket=bucket,
55 builder=builder)
56 self.scope = 'https://www.googleapis.com/auth/userinfo.email'
57 self.running_env = constants.environment()
58
Xinan Lin9e4917d2019-11-04 10:58:47 -080059 def multirequest_run(self, tasks, suite):
Xinan Lin1e8e7912020-07-31 09:52:16 -070060 """Call cros_test_platform Builder to schedule a batch of suite tests.
Xinan Lin3ba18a02019-08-13 15:44:55 -070061
62 Args:
Xinan Lin9e4917d2019-11-04 10:58:47 -080063 tasks: The suite tasks to run.
64 suite: suite name for the batch request.
65
66 Returns:
67 List of executed tasks.
Xinan Lin3ba18a02019-08-13 15:44:55 -070068
69 Raises:
70 BuildbucketRunError: if failed to get build info from task parameters.
71 """
Xinan Lin9e4917d2019-11-04 10:58:47 -080072 requests = []
73 executed_tasks = []
74 counter = collections.defaultdict(int)
Xinan Lindf0698a2020-02-05 22:38:11 -080075 task_executions = []
Xinan Lin9e4917d2019-11-04 10:58:47 -080076 for task in tasks:
77 try:
78 params = task.extract_params()
Xinan Linc54a7462020-04-17 15:39:01 -070079 if _should_skip(params):
80 continue
Xinan Lin8bb5b4b2020-07-21 23:17:55 -070081 req = _form_test_platform_request(params)
Xinan Lin9e4917d2019-11-04 10:58:47 -080082 req_json = json_format.MessageToJson(req)
83 counter_key = params['board']
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -070084 counter_key += '' if params['model'] in [None, 'None'
85 ] else ('_' + params['model'])
Xinan Lin9e4917d2019-11-04 10:58:47 -080086 counter[counter_key] += 1
87 req_name = counter_key
88 if counter[counter_key] > 1:
89 req_name += '_' + str(counter[counter_key] - 1)
90 requests.append('"%s": %s' % (req_name, req_json))
91 executed_tasks.append(task)
Xinan Lin083ba8f2020-02-06 13:55:18 -080092 if params.get('task_id'):
Xinan Lin9b17c5b2020-08-06 10:43:30 -070093 task_executions.append(
94 analytics.ExecutionTask(params['task_id'], req_name))
Xinan Lin9e4917d2019-11-04 10:58:47 -080095 except (ValueError, BuildbucketRunError):
Xinan Linba3b9322020-04-24 15:08:12 -070096 logging.error('Failed to process task: %r', params)
Xinan Lin9e4917d2019-11-04 10:58:47 -080097 if not requests:
98 return []
99 try:
100 requests_json = '{ "requests": { %s } }' % ', '.join(requests)
Dhanya Ganeshedb78cb2020-07-20 19:40:50 +0000101 req_build = self._build_request(requests_json, _bb_tags(suite))
Xinan Lin9e4917d2019-11-04 10:58:47 -0800102 logging.debug('Raw request to buildbucket: %r', req_build)
linxinane5eb4552019-08-26 05:44:45 +0000103
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700104 if (self.running_env == constants.RunningEnv.ENV_STANDALONE
105 or self.running_env == constants.RunningEnv.ENV_DEVELOPMENT_SERVER):
Xinan Lin9e4917d2019-11-04 10:58:47 -0800106 # If running locally, use the staging service account.
107 sa_key = self._gen_service_account_key(
108 file_getter.STAGING_CLIENT_SECRETS_FILE)
109 cred = prpc_client.service_account_credentials(
110 service_account_key=sa_key)
111 else:
112 cred = prpc_client.service_account_credentials()
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700113 resp = self.client.ScheduleBuild(req_build,
114 credentials=cred,
115 timeout=PRPC_TIMEOUT_SEC)
Xinan Lin9e4917d2019-11-04 10:58:47 -0800116 logging.debug('Response from buildbucket: %r', resp)
Xinan Lindf0698a2020-02-05 22:38:11 -0800117 for t in task_executions:
118 t.update_result(resp)
119 try:
120 if not t.upload():
121 logging.warning('Failed to insert row: %r', t)
122 # For any exceptions from BQ, only log it.
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700123 except Exception as e: #pylint: disable=broad-except
124 logging.exception('Failed to insert row: %r, got error: %s', t,
125 str(e))
Xinan Lin9e4917d2019-11-04 10:58:47 -0800126 return executed_tasks
127 except Exception as e:
128 logging.debug('Failed to process tasks: %r', tasks)
129 logging.exception(str(e))
130 return []
Xinan Lin3ba18a02019-08-13 15:44:55 -0700131
Xinan Linc61196b2019-08-13 10:37:30 -0700132 def dummy_run(self):
133 """Perform a dummy run of prpc call to cros_test_platform-dev."""
134
Xinan Lin9e4917d2019-11-04 10:58:47 -0800135 requests_json = '{ "requests": { "dummy": {} } }'
136 req_build = self._build_request(requests_json, tags=None)
Xinan Linc61196b2019-08-13 10:37:30 -0700137 # Use the staging service account to authorize the request.
138 sa_key = self._gen_service_account_key(
139 file_getter.STAGING_CLIENT_SECRETS_FILE)
140 cred = prpc_client.service_account_credentials(service_account_key=sa_key)
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700141 return self.client.ScheduleBuild(req_build,
142 credentials=cred,
143 timeout=PRPC_TIMEOUT_SEC)
Xinan Linc61196b2019-08-13 10:37:30 -0700144
Xinan Lin9e4917d2019-11-04 10:58:47 -0800145 def _build_request(self, reqs_json, tags):
Xinan Lin3ba18a02019-08-13 15:44:55 -0700146 """Generate ScheduleBuildRequest for calling buildbucket.
Xinan Linc61196b2019-08-13 10:37:30 -0700147
Xinan Lin3ba18a02019-08-13 15:44:55 -0700148 Args:
Xinan Lin9e4917d2019-11-04 10:58:47 -0800149 reqs_json: A json string of requests.
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700150 tags: A list of tags for the buildbucket build.
Xinan Linc61196b2019-08-13 10:37:30 -0700151
Xinan Lin3ba18a02019-08-13 15:44:55 -0700152 Returns:
153 A ScheduleBuildRequest instance.
154 """
Xinan Lin9e4917d2019-11-04 10:58:47 -0800155 requests_struct = struct_pb2.Struct()
156 recipe_struct = json_format.Parse(reqs_json, requests_struct)
Xinan Linc61196b2019-08-13 10:37:30 -0700157 return rpc_pb2.ScheduleBuildRequest(builder=self.builder,
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700158 properties=recipe_struct,
Xinan Lin081b5d32020-03-23 17:37:55 -0700159 request_id=str(uuid.uuid1()),
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700160 tags=tags)
Xinan Linc61196b2019-08-13 10:37:30 -0700161
162 def _gen_service_account_key(self, sa):
Xinan Lin3ba18a02019-08-13 15:44:55 -0700163 """Generate credentials to authorize the call.
Xinan Linc61196b2019-08-13 10:37:30 -0700164
Xinan Lin3ba18a02019-08-13 15:44:55 -0700165 Args:
166 sa: A string of the path to the service account json file.
Xinan Linc61196b2019-08-13 10:37:30 -0700167
Xinan Lin3ba18a02019-08-13 15:44:55 -0700168 Returns:
169 A service account key.
170 """
Xinan Linc61196b2019-08-13 10:37:30 -0700171 service_credentials = service_account.ServiceAccountCredentials
Xinan Lin3ba18a02019-08-13 15:44:55 -0700172 key = service_credentials.from_json_keyfile_name(sa, self.scope)
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700173 return auth.ServiceAccountKey(client_email=key.service_account_email,
174 private_key=key._private_key_pkcs8_pem,
175 private_key_id=key._private_key_id)
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700176
177
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700178def _form_test_platform_request(task_params):
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700179 """Generates test_platform.Request proto to send to buildbucket.
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700180
181 Args:
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700182 task_params: dict containing the parameters of a task from the suite queue.
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700183
184 Returns:
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700185 A ctp_request.Request instance.
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700186 """
187 build = _infer_build_from_task_params(task_params)
188 if build == 'None':
189 raise BuildbucketRunError('No proper build in task params: %r' %
190 task_params)
191 pool = _infer_pool_from_task_params(task_params)
192 timeout = _infer_timeout_from_task_params(task_params)
193
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700194 request = ctp_request.Request()
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700195 params = request.params
196
Xinan Lin4757d6f2020-03-24 22:20:31 -0700197 params.scheduling.CopyFrom(_scheduling_for_pool(pool))
Prathmesh Prabhu46156ff2020-06-20 00:18:52 -0700198 if task_params.get('qs_account') not in ['None', None]:
Xinan Lin4757d6f2020-03-24 22:20:31 -0700199 params.scheduling.qs_account = task_params.get('qs_account')
200 # Quota Scheduler has no concept of priority.
Xinan Lin8bb5b4b2020-07-21 23:17:55 -0700201 if (task_params.get('priority') not in ['None', None]
202 and not params.scheduling.qs_account):
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700203 params.scheduling.priority = int(task_params['priority'])
204
205 params.software_dependencies.add().chromeos_build = build
206 params.software_attributes.build_target.name = task_params['board']
Aviv Keshetc679faf2019-11-27 17:52:50 -0800207
208 gs_url = GS_PREFIX + task_params['test_source_build']
209 params.metadata.test_metadata_url = gs_url
210 params.metadata.debug_symbols_archive_url = gs_url
211
Jacob Kopczynskie56bf492020-08-07 13:20:12 -0700212 migration, nonempty = _set_migrations(task_params.get('migrations', []))
213 if nonempty:
214 params.migrations.CopyFrom(migration)
215
216 topic = task_params.get('pubsub_topic')
217 # Default value of the task_params fields is "None" rather than None
218 if topic not in [None, 'None']:
219 params.notification.pubsub_topic = topic
220
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700221 params.time.maximum_duration.FromTimedelta(timeout)
222
223 for key, value in _request_tags(task_params, build, pool).iteritems():
224 params.decorations.tags.append('%s:%s' % (key, value))
225
Xinan Lin7bf266a2020-06-10 23:54:26 -0700226 for d in _infer_user_defined_dimensions(task_params):
227 params.freeform_attributes.swarming_dimensions.append(d)
Xinan Linba3b9322020-04-24 15:08:12 -0700228
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700229 if task_params['model'] != 'None':
230 params.hardware_attributes.model = task_params['model']
231
232 if task_params['job_retry'] == 'True':
233 params.retry.allow = True
234 params.retry.max = constants.Buildbucket.MAX_RETRY
235
236 fw_rw_build = task_params.get(build_lib.BuildVersionKey.FW_RW_VERSION)
237 fw_ro_build = task_params.get(build_lib.BuildVersionKey.FW_RO_VERSION)
238 # Skip firmware field if None(unspecified) or 'None'(no such build).
239 if fw_ro_build not in (None, 'None'):
240 build = params.software_dependencies.add()
241 build.ro_firmware_build = fw_ro_build
242 if fw_rw_build not in (None, 'None'):
243 build = params.software_dependencies.add()
244 build.rw_firmware_build = fw_rw_build
245
246 request.test_plan.suite.add().name = task_params['suite']
247 return request
248
Jacob Kopczynskie56bf492020-08-07 13:20:12 -0700249def _set_migrations(migrations_list, migrations_pb=None):
250 """Translate list of migration names to a Migrations proto.
251
252 Args:
253 migrations_list: list of strings, each naming a migration to set.
254 migrations_pb: ctp_request.Request.Params.Migrations proto or None
255 Returns:
256 (migration, nonempty); tuple whose first element is a
257 ctp_request.Request.Params.Migrations proto object
258 and whose second element is whether that object has non-default attributes
259 Raises:
260 ValueError if a named migration is not in the Migrations proto
261 TypeError if a named migration cannot be set to True
262 """
263 errs= []
264 # Task flattens all fields so one-element lists are cast to single strings
265 if migrations_pb is None:
266 migrations_pb = ctp_request.Request.Params.Migrations()
267 if migrations_list == "None" or not migrations_list:
268 return (migrations_pb, False)
269 if isinstance(migrations_list, types.StringTypes):
270 migrations_list = [migrations_list]
271 nonempty = False
272 for name in migrations_list:
273 try:
274 # setattr on a protobuf is much safer than normal; trying to set an
275 # undefined field, or even one which is differently typed, is an error
276 setattr(migrations_pb, name, True)
277 nonempty = True
278 except (AttributeError, TypeError) as e:
279 errs.append(str(e))
280 if len(errs) > 0:
281 raise AttributeError('invalid fields: '+', '.join(errs))
282 return (migrations_pb, nonempty)
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700283
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700284def _scheduling_for_pool(pool):
285 """Assign appropriate pool name to scheduling instance.
286
287 Args:
Xinan Lin1516edb2020-07-05 23:13:54 -0700288 pool: string pool name (e.g. 'MANAGED_POOL_QUOTA', 'wificell').
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700289
290 Returns:
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700291 scheduling: A ctp_request.Request.Params.Scheduling instance.
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700292 """
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700293 mp = ctp_request.Request.Params.Scheduling.ManagedPool
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700294 if mp.DESCRIPTOR.values_by_name.get(pool) is not None:
Jacob Kopczynski408f3fd2020-08-07 13:31:59 -0700295 return ctp_request.Request.Params.Scheduling(managed_pool=mp.Value(pool))
296 return ctp_request.Request.Params.Scheduling(unmanaged_pool=pool)
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700297
298
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700299# Also see: A copy of this function in swarming_lib.py.
300def _infer_build_from_task_params(task_params):
301 """Infer the build to install on the DUT for the scheduled task.
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700302
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700303 Args:
304 task_params: The parameters of a task loaded from suite queue.
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700305
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700306 Returns:
307 A string representing the build to run.
308 """
309 cros_build = task_params[build_lib.BuildVersionKey.CROS_VERSION]
310 android_build = task_params[build_lib.BuildVersionKey.ANDROID_BUILD_VERSION]
311 testbed_build = task_params[build_lib.BuildVersionKey.TESTBED_BUILD_VERSION]
312 return cros_build or android_build or testbed_build
313
314
315def _infer_pool_from_task_params(task_params):
316 """Infer the pool to use for the scheduled task.
317
318 Args:
319 task_params: The parameters of a task loaded from suite queue.
320
321 Returns:
322 A string pool to schedule task in.
323 """
324 if task_params.get('override_qs_account'):
325 return 'DUT_POOL_QUOTA'
326 return task_params.get('override_pool') or task_params['pool']
327
328
329def _infer_timeout_from_task_params(task_params):
330 """Infer the timeout for the scheduled task.
331
332 Args:
333 task_params: The parameters of a task loaded from suite queue.
334
335 Returns:
336 A datetime.timedelta instance for the timeout.
337 """
338 timeout_mins = int(task_params['timeout_mins'])
339 # timeout's unit is hour.
340 if task_params.get('timeout'):
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700341 timeout_mins = max(int(task_params['timeout']) * 60, timeout_mins)
Prathmesh Prabhu06852fe2019-09-09 07:58:43 -0700342 if timeout_mins > constants.Buildbucket.MAX_BUILDBUCKET_TIMEOUT_MINS:
343 timeout_mins = constants.Buildbucket.MAX_BUILDBUCKET_TIMEOUT_MINS
344 return datetime.timedelta(minutes=timeout_mins)
345
Prathmesh Prabhu1918a8f2019-09-07 21:37:37 -0700346
Xinan Linba3b9322020-04-24 15:08:12 -0700347def _infer_user_defined_dimensions(task_params):
348 """Infer the dimensions defined by users.
349
350 Args:
351 task_params: The parameters of a task loaded from suite queue.
352
353 Returns:
354 A list of strings; an empty list if no dimensions set.
355
356 Raises:
357 ValueError: if dimension is not valid.
358 """
359 result = []
360 if task_params.get('dimensions') in (None, 'None'):
361 return result
362 for d in task_params.get('dimensions').split(','):
363 if len(d.split(':')) != 2:
364 raise ValueError(
365 'Job %s has invalid dimensions: %s' %
366 (task_params.get('name'), task_params.get('dimensions')))
367 result.append(d)
368 return result
369
370
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700371def _request_tags(task_params, build, pool):
372 """Infer tags to include in cros_test_platform request.
373
374 Args:
375 task_params: suite task parameters.
376 build: The build included in the request. Must not be None.
377 pool: The DUT pool used for the request. Must not be None.
378
379 Returns:
380 A dict of tags.
381 """
382 tags = {
Prathmesh Prabhuaf0857f2020-06-20 00:16:32 -0700383 'build': build,
384 'label-pool': pool,
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700385 }
Xinan Linfb63d572019-09-24 15:49:04 -0700386 if task_params.get('board') not in (None, 'None'):
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700387 tags['label-board'] = task_params['board']
Xinan Linfb63d572019-09-24 15:49:04 -0700388 if task_params.get('model') not in (None, 'None'):
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700389 tags['label-model'] = task_params['model']
Xinan Linfb63d572019-09-24 15:49:04 -0700390 if task_params.get('suite') not in (None, 'None'):
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700391 tags['suite'] = task_params['suite']
392 return tags
393
394
Xinan Linc8647112020-02-04 16:45:56 -0800395def _get_key_val_from_label(label):
396 """A helper to get key and value from the label.
397
398 Args:
399 label: A string of label, should be in the form of
400 key:value, e.g. 'pool:ChromeOSSkylab'.
401 """
402 res = label.split(':')
403 if len(res) == 2:
404 return res[0], res[1]
405 logging.warning('Failed to parse the label, %s', label)
406
407
Dhanya Ganeshedb78cb2020-07-20 19:40:50 +0000408def _bb_tags(suite):
409 """Get all the tags required for Buildbucket.
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700410
411 Args:
Dhanya Ganeshedb78cb2020-07-20 19:40:50 +0000412 suite: A string of suite name being scheduled.
Prathmesh Prabhu2382a182019-09-07 21:18:10 -0700413
414 Returns:
415 [bb_common_pb2.StringPair] tags to include the buildbucket request.
416 """
Dhanya Ganeshedb78cb2020-07-20 19:40:50 +0000417 return [bb_common_pb2.StringPair(key='suite', value=suite),
418 bb_common_pb2.StringPair(key='user_agent',
419 value='suite_scheduler')]
Xinan Linc54a7462020-04-17 15:39:01 -0700420
421
422def _should_skip(params):
423 """Decide whether to skip a task based on env and pool.
424
425 Suite request from staging may still have a small chance to run
426 in production. However, for unmanaged pools(e.g. wificell), which
427 usually are small, dev traffic is unacceptable.
428
429 Args:
430 params: dict containing the parameters of a task got from suite
431 queue.
432
433 Returns:
434 A boolean; true for suite targetting non-default pools from staging
435 env.
436 """
437 if constants.application_id() == constants.AppID.PROD_APP:
438 return False
Xinan Lin0d7910d2020-07-21 11:06:45 -0700439 return params['pool'] != 'MANAGED_POOL_QUOTA'