| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 parse_cfg_dim = lambda d: d.split(':', 1) | 295 parse_cfg_dim = lambda d: d.split(':', 1) |
| 296 bucket_dims = map(parse_cfg_dim, bucket_cfg_dims) | 296 bucket_dims = map(parse_cfg_dim, bucket_cfg_dims) |
| 297 builder_dims = map(parse_cfg_dim, builder_cfg_dims) | 297 builder_dims = map(parse_cfg_dim, builder_cfg_dims) |
| 298 | 298 |
| 299 # Note: dimensions must be unique. | 299 # Note: dimensions must be unique. |
| 300 # Overwrite global dimensions by bucket-level dimensions, | 300 # Overwrite global dimensions by bucket-level dimensions, |
| 301 # then by builder-level dimensions. | 301 # then by builder-level dimensions. |
| 302 merged = {} | 302 merged = {} |
| 303 for ds in (global_dims, bucket_dims, builder_dims): | 303 for ds in (global_dims, bucket_dims, builder_dims): |
| 304 merged.update(ds) | 304 merged.update(ds) |
| 305 return sorted({'key': k, 'value': v} for k, v in merged.iteritems()) | 305 return sorted({'key': k, 'value': v} for k, v in merged.iteritems() if v) |
| 306 | 306 |
| 307 | 307 |
| 308 @ndb.tasklet | 308 @ndb.tasklet |
| 309 def create_task_async(build): | 309 def create_task_async(build): |
| 310 """Creates a swarming task for the build and mutates the build. | 310 """Creates a swarming task for the build and mutates the build. |
| 311 | 311 |
| 312 May be called only if is_for_swarming(build) == True. | 312 May be called only if is_for_swarming(build) == True. |
| 313 """ | 313 """ |
| 314 if build.lease_key: | 314 if build.lease_key: |
| 315 raise errors.InvalidInputError( | 315 raise errors.InvalidInputError( |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 def _extend_unique(target, items): | 685 def _extend_unique(target, items): |
| 686 for x in items: | 686 for x in items: |
| 687 if x not in target: # pragma: no branch | 687 if x not in target: # pragma: no branch |
| 688 target.append(x) | 688 target.append(x) |
| 689 | 689 |
| 690 | 690 |
| 691 class TaskToken(tokens.TokenKind): | 691 class TaskToken(tokens.TokenKind): |
| 692 expiration_sec = 60 * 60 * 24 # 24 hours. | 692 expiration_sec = 60 * 60 * 24 # 24 hours. |
| 693 secret_key = auth.SecretKey('swarming_task_token', scope='local') | 693 secret_key = auth.SecretKey('swarming_task_token', scope='local') |
| 694 version = 1 | 694 version = 1 |
| OLD | NEW |