| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2013 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 |
| 6 """This script acts as the liason between the master and the swarming_client |
| 7 code. |
| 8 |
| 9 This helps with master restarts and when swarming_client is updated. It helps |
| 10 support older versions of the client code, without having to complexify the |
| 11 master code. |
| 12 """ |
| 13 |
| 14 import optparse |
| 15 import os |
| 16 import subprocess |
| 17 import sys |
| 18 |
| 19 from common import chromium_utils |
| 20 from common import find_depot_tools # pylint: disable=W0611 |
| 21 |
| 22 from slave.swarming import swarming_utils |
| 23 |
| 24 # From depot tools/ |
| 25 import fix_encoding |
| 26 |
| 27 |
| 28 def v0(client, options): |
| 29 """Compatible up to the oldest swarm_client code.""" |
| 30 cmd = [ |
| 31 sys.executable, |
| 32 os.path.join(client, 'swarm_trigger_step.py'), |
| 33 '--swarm-url', options.swarming, |
| 34 '--data-server', options.isolate_server, |
| 35 '--os_image', options.os, |
| 36 '--test-name-prefix', options.task_prefix, |
| 37 ] |
| 38 for i in options.tasks: |
| 39 cmd.append('--run_from_hash') |
| 40 cmd.extend(i) |
| 41 |
| 42 print ' '.join(cmd) |
| 43 return subprocess.call(cmd, cwd=client) |
| 44 |
| 45 |
| 46 def determine_version_and_run_handler(client, options): |
| 47 """Executes the proper handler based on the code layout and --version support. |
| 48 """ |
| 49 # TODO(maruel): Determine version. |
| 50 return v0(client, options) |
| 51 |
| 52 |
| 53 def process_build_properties(options): |
| 54 """Converts build properties and factory properties into expected flags.""" |
| 55 options.task_prefix = '%s-%s-' % ( |
| 56 options.build_properties.get('buildername'), |
| 57 options.build_properties.get('buildnumber'), |
| 58 ) |
| 59 # target_os is not defined when using a normal builder (and it's not |
| 60 # needed since the OS match), it's defined in builder/tester configurations. |
| 61 options.os = options.build_properties.get('target_os', options.os) |
| 62 |
| 63 |
| 64 def main(): |
| 65 """Note: this is solely to run the current master's code and can totally |
| 66 differ from the underlying script flags. |
| 67 |
| 68 To update these flags: |
| 69 - Update the following code to support both the previous flag and the new |
| 70 flag. |
| 71 - Change scripts/master/factory/swarm_commands.py to pass the new flag. |
| 72 - Restart all the masters using swarming. |
| 73 - Remove the old flag from this code. |
| 74 """ |
| 75 client = swarming_utils.find_client(os.getcwd()) |
| 76 if not client: |
| 77 print >> sys.stderr, 'Failed to find swarm(ing)_client' |
| 78 return 1 |
| 79 |
| 80 parser = optparse.OptionParser() |
| 81 parser.add_option( |
| 82 '--os', default=sys.platform, |
| 83 help='it\'s possible to trigger a task on an OS while the client code ' |
| 84 'runs on another OS') |
| 85 parser.add_option('--swarming') |
| 86 parser.add_option('--isolate-server') |
| 87 parser.add_option('--task-prefix', help='task name prefix') |
| 88 parser.add_option( |
| 89 '--task', nargs=4, action='append', default=[], dest='tasks') |
| 90 chromium_utils.AddPropertiesOptions(parser) |
| 91 options, args = parser.parse_args() |
| 92 if args: |
| 93 parser.error('Unsupported args: %s' % args) |
| 94 |
| 95 if options.build_properties: |
| 96 # Loads the other flags implicitly. |
| 97 process_build_properties(options) |
| 98 |
| 99 return determine_version_and_run_handler(client, options) |
| 100 |
| 101 |
| 102 if __name__ == '__main__': |
| 103 fix_encoding.fix_encoding() |
| 104 sys.exit(main()) |
| OLD | NEW |