blob: 86fcffe422c9b216c5f3d738fa524e21d6fb82b9 [file] [log] [blame]
Emily Hanley08a62aea2018-02-07 14:41:011#!/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
7This script does custom swarming triggering logic, to enable device affinity
8for our bots, while lumping all trigger calls under one logical step.
9
10This script receives multiple machine configurations on the command line in the
11form of quoted strings. These strings are JSON dictionaries that represent
12entries in the "dimensions" array of the "swarming" dictionary in the
13src/testing/buildbot JSON files.
14
15Scripts inheriting must have roughly the same command line interface as
16swarming.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
26This script is normally called from the swarming recipe module in tools/build.
27
28"""
29
30import argparse
31import json
32import os
33import subprocess
34import sys
35import tempfile
36
37import base_test_triggerer
38
39class 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
59def 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
67if __name__ == '__main__':
68 sys.exit(main())
69