Emily Hanley | 08a62aea | 2018-02-07 14:41:01 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """Custom swarming triggering script. |
| 6 | |
| 7 | This script does custom swarming triggering logic, to enable device affinity |
| 8 | for our bots, while lumping all trigger calls under one logical step. |
| 9 | |
| 10 | This script receives multiple machine configurations on the command line in the |
| 11 | form of quoted strings. These strings are JSON dictionaries that represent |
| 12 | entries in the "dimensions" array of the "swarming" dictionary in the |
| 13 | src/testing/buildbot JSON files. |
| 14 | |
| 15 | Scripts inheriting must have roughly the same command line interface as |
| 16 | swarming.py trigger. It modifies it in the following ways: |
| 17 | * Intercepts the dump-json argument, and creates its own by combining the |
| 18 | results from each trigger call. |
| 19 | * Scans through the multiple-trigger-configs dictionaries. For any key found, |
| 20 | deletes that dimension from the originally triggered task's dimensions. This |
| 21 | is what allows the Swarming dimensions to be replaced. Must contain the |
| 22 | dimension "id" for the perf device affinity use case. |
| 23 | * On a per-shard basis, adds the Swarming dimensions chosen from the |
| 24 | multiple-trigger-configs list to the dimensions for the shard. |
| 25 | |
| 26 | This script is normally called from the swarming recipe module in tools/build. |
| 27 | |
| 28 | """ |
| 29 | |
| 30 | import argparse |
| 31 | import json |
| 32 | import os |
| 33 | import subprocess |
| 34 | import sys |
| 35 | import tempfile |
| 36 | |
| 37 | import base_test_triggerer |
| 38 | |
| 39 | class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer): |
| 40 | def __init__(self): |
| 41 | super(PerfDeviceTriggerer, self).__init__() |
| 42 | |
| 43 | def append_additional_args(self, args): |
| 44 | if 'id' in args: |
| 45 | # Adds the bot id as an argument to the test. |
| 46 | return args + ['--bot', args[args.index('id') + 1]] |
| 47 | else: |
| 48 | raise Exception('Id must be present for perf device triggering') |
| 49 | |
| 50 | def select_config_indices(self, args, verbose): |
| 51 | # For perf we want to trigger a job for every valid config since |
| 52 | # each config represents exactly one bot in the perf swarming pool, |
| 53 | selected_configs = [] |
| 54 | for i in xrange(args.shards): |
| 55 | selected_configs.append(i) |
| 56 | return selected_configs |
| 57 | |
| 58 | |
| 59 | def main(): |
| 60 | triggerer = PerfDeviceTriggerer() |
| 61 | # Setup args for common contract of base class |
| 62 | parser = triggerer.setup_parser_contract( |
| 63 | argparse.ArgumentParser(description=__doc__)) |
| 64 | args, remaining = parser.parse_known_args() |
| 65 | return triggerer.trigger_tasks(args, remaining) |
| 66 | |
| 67 | if __name__ == '__main__': |
| 68 | sys.exit(main()) |
| 69 | |