OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """This module integrates buildbucket with swarming. | 5 """This module integrates buildbucket with swarming. |
6 | 6 |
7 A bucket config may have "swarming" field that specifies how a builder | 7 A bucket config may have "swarming" field that specifies how a builder |
8 is mapped to a recipe. If build is scheduled for a bucket/builder | 8 is mapped to a recipe. If build is scheduled for a bucket/builder |
9 with swarming configuration, the integration overrides the default behavior. | 9 with swarming configuration, the integration overrides the default behavior. |
10 | 10 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 _extend_unique(swarming_tags, builder_cfg.swarming_tags) | 258 _extend_unique(swarming_tags, builder_cfg.swarming_tags) |
259 _extend_unique(swarming_tags, build.tags) | 259 _extend_unique(swarming_tags, build.tags) |
260 swarming_tags.sort() | 260 swarming_tags.sort() |
261 | 261 |
262 task_properties = task.setdefault('properties', {}) | 262 task_properties = task.setdefault('properties', {}) |
263 task_properties['dimensions'] = _prepare_dimensions( | 263 task_properties['dimensions'] = _prepare_dimensions( |
264 task_properties.get('dimensions', []), | 264 task_properties.get('dimensions', []), |
265 swarming_cfg.common_dimensions, | 265 swarming_cfg.common_dimensions, |
266 builder_cfg.dimensions | 266 builder_cfg.dimensions |
267 ) | 267 ) |
| 268 |
| 269 if swarming_cfg.common_execution_timeout_secs > 0: |
| 270 task_properties['execution_timeout_secs'] = ( |
| 271 swarming_cfg.common_execution_timeout_secs) |
268 if builder_cfg.execution_timeout_secs > 0: | 272 if builder_cfg.execution_timeout_secs > 0: |
269 task_properties['execution_timeout_secs'] = ( | 273 task_properties['execution_timeout_secs'] = ( |
270 builder_cfg.execution_timeout_secs) | 274 builder_cfg.execution_timeout_secs) |
271 | 275 |
272 task['pubsub_topic'] = ( | 276 task['pubsub_topic'] = ( |
273 'projects/%s/topics/%s' % | 277 'projects/%s/topics/%s' % |
274 (app_identity.get_application_id(), PUBSUB_TOPIC)) | 278 (app_identity.get_application_id(), PUBSUB_TOPIC)) |
275 task['pubsub_auth_token'] = TaskToken.generate() | 279 task['pubsub_auth_token'] = TaskToken.generate() |
276 task['pubsub_userdata'] = json.dumps({ | 280 task['pubsub_userdata'] = json.dumps({ |
277 'created_ts': utils.datetime_to_timestamp(utils.utcnow()), | 281 'created_ts': utils.datetime_to_timestamp(utils.utcnow()), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 'CANCELED', | 415 'CANCELED', |
412 'COMPLETED' | 416 'COMPLETED' |
413 ) | 417 ) |
414 if state in ('PENDING', 'RUNNING'): | 418 if state in ('PENDING', 'RUNNING'): |
415 build.status = model.BuildStatus.STARTED | 419 build.status = model.BuildStatus.STARTED |
416 elif state in terminal_states: | 420 elif state in terminal_states: |
417 build.status = model.BuildStatus.COMPLETED | 421 build.status = model.BuildStatus.COMPLETED |
418 if state == 'CANCELED': | 422 if state == 'CANCELED': |
419 build.result = model.BuildResult.CANCELED | 423 build.result = model.BuildResult.CANCELED |
420 build.cancelation_reason = model.CancelationReason.CANCELED_EXPLICITLY | 424 build.cancelation_reason = model.CancelationReason.CANCELED_EXPLICITLY |
421 elif state in ('TIMED_OUT', 'EXPIRED'): | 425 elif state == 'EXPIRED': |
| 426 # Task did not start. |
422 build.result = model.BuildResult.CANCELED | 427 build.result = model.BuildResult.CANCELED |
423 build.cancelation_reason = model.CancelationReason.TIMEOUT | 428 build.cancelation_reason = model.CancelationReason.TIMEOUT |
| 429 elif state == 'TIMED_OUT': |
| 430 # Task started, but timed out. |
| 431 build.result = model.BuildResult.FAILURE |
| 432 build.failure_reason = model.FailureReason.INFRA_FAILURE |
424 elif state == 'BOT_DIED' or result.get('internal_failure'): | 433 elif state == 'BOT_DIED' or result.get('internal_failure'): |
425 build.result = model.BuildResult.FAILURE | 434 build.result = model.BuildResult.FAILURE |
426 build.failure_reason = model.FailureReason.INFRA_FAILURE | 435 build.failure_reason = model.FailureReason.INFRA_FAILURE |
427 elif result.get('failure'): | 436 elif result.get('failure'): |
428 build.result = model.BuildResult.FAILURE | 437 build.result = model.BuildResult.FAILURE |
429 build.failure_reason = model.FailureReason.BUILD_FAILURE | 438 build.failure_reason = model.FailureReason.BUILD_FAILURE |
430 else: | 439 else: |
431 assert state == 'COMPLETED' | 440 assert state == 'COMPLETED' |
432 build.result = model.BuildResult.SUCCESS | 441 build.result = model.BuildResult.SUCCESS |
433 else: # pragma: no cover | 442 else: # pragma: no cover |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 def _extend_unique(target, items): | 683 def _extend_unique(target, items): |
675 for x in items: | 684 for x in items: |
676 if x not in target: # pragma: no branch | 685 if x not in target: # pragma: no branch |
677 target.append(x) | 686 target.append(x) |
678 | 687 |
679 | 688 |
680 class TaskToken(tokens.TokenKind): | 689 class TaskToken(tokens.TokenKind): |
681 expiration_sec = 60 * 60 * 24 # 24 hours. | 690 expiration_sec = 60 * 60 * 24 # 24 hours. |
682 secret_key = auth.SecretKey('swarming_task_token', scope='local') | 691 secret_key = auth.SecretKey('swarming_task_token', scope='local') |
683 version = 1 | 692 version = 1 |
OLD | NEW |