Chromium Code Reviews| Index: scripts/slave/swarming/trigger_swarm.py |
| diff --git a/scripts/slave/swarming/trigger_swarm.py b/scripts/slave/swarming/trigger_swarm.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a1eb49e22137865b51bbef1d4f72514a316a07a7 |
| --- /dev/null |
| +++ b/scripts/slave/swarming/trigger_swarm.py |
| @@ -0,0 +1,119 @@ |
| +#!/usr/bin/env python |
|
Isaac (away)
2013/08/20 22:22:33
I'm confused what the purpose of this file is -- c
M-A Ruel
2013/08/23 02:18:33
It triggers a swarm job. Then get_swarm_results.py
|
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""This script acts as the liason between the master and the swarming_client |
| +code. |
| + |
| +This helps with master restarts and when swarming_client is updated. It helps |
| +support older versions of the client code, without having to complexify the |
| +master code. |
| +""" |
| + |
| +import optparse |
| +import os |
| +import subprocess |
| +import sys |
| + |
| +from common import find_depot_tools # pylint: disable=W0611 |
| + |
| +from slave.swarming import swarming_utils |
| + |
| +# From depot tools/ |
| +import fix_encoding |
| + |
| + |
| +PRIORITIES = { |
| + 'ci': 10, |
| + 'cq': 20, |
| + 'fyi': 30, |
| + 'tryjob': 40, |
| +} |
| + |
| + |
| +def v0(client, options): |
| + """Compatible up to the oldest swarm_client code.""" |
| + cmd = [ |
| + sys.executable, |
| + os.path.join(client, 'swarm_trigger_step.py'), |
| + '--swarm-url', options.swarming, |
| + '--data-server', options.isolate_server, |
| + '--os_image', options.os, |
| + '--test-name-prefix', options.prefix, |
| + ] |
| + for i in options.tasks: |
| + cmd.append('--run_from_hash') |
| + cmd.extend(i) |
| + |
| + print ' '.join(cmd) |
| + return subprocess.call(cmd, cwd=client) |
| + |
| + |
| +def v1(client, options): |
| + """Adds --priority support in r217581.""" |
| + cmd = [ |
| + sys.executable, |
| + os.path.join(client, 'swarm_trigger_step.py'), |
| + '--swarm-url', options.swarming, |
| + '--data-server', options.isolate_server, |
| + '--os_image', options.os, |
| + '--test-name-prefix', options.prefix, |
| + '--priority', str(PRIORITIES[options.type]), |
| + ] |
| + |
| + for i in options.tasks: |
| + cmd.append('--run_from_hash') |
| + cmd.extend(i) |
| + |
| + print ' '.join(cmd) |
| + return subprocess.call(cmd, cwd=client) |
| + |
| + |
| +def determine_version_and_run_handler(client, options): |
| + """Executes the proper handler based on the code layout and --version support. |
| + """ |
| + # TODO(maruel): Determine version. |
| + return v0(client, options) |
| + |
| + |
| +def main(): |
| + """Note: this is solely to run the current master's code and can totally |
| + differ from the underlying script flags. |
| + |
| + To update these flags: |
| + - Update the following code to support both the previous flag and the new |
| + flag. |
| + - Change scripts/master/factory/swarm_commands.py to pass the new flag. |
| + - Restart all the masters using swarming. |
| + - Remove the old flag from this code. |
| + """ |
| + client = swarming_utils.find_client(os.getcwd()) |
| + if not client: |
| + print >> sys.stderr, 'Failed to find swarm(ing)_client' |
| + return 1 |
| + |
| + parser = optparse.OptionParser() |
| + parser.add_option( |
| + '--os', |
| + help='it\'s possible to trigger a task on an OS while the client code ' |
| + 'runs on another OS') |
| + parser.add_option('--swarming') |
| + parser.add_option('--isolate-server') |
| + parser.add_option('--task-prefix', help='task name prefix') |
| + parser.add_option( |
| + '--type', |
| + choices=sorted(PRIORITIES), |
| + help='Type of job will define it\'s priority') |
| + parser.add_option( |
| + '--task', nargs=4, action='append', default=[], dest='tasks') |
| + options, args = parser.parse_args() |
| + if args: |
| + parser.error('Unsupported args: %s' % args) |
| + |
| + return determine_version_and_run_handler(client, options) |
| + |
| + |
| +if __name__ == '__main__': |
| + fix_encoding.fix_encoding() |
| + sys.exit(main()) |