| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This script acts as the liason between the master and the swarming_client | 6 """This script acts as the liason between the master and the swarming_client |
| 7 code. | 7 code. |
| 8 | 8 |
| 9 This helps with master restarts and when swarming_client is updated. It helps | 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 | 10 support older versions of the client code, without having to complexify the |
| 11 master code. | 11 master code. |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import optparse | 14 import optparse |
| 15 import os | 15 import os |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 from common import chromium_utils | 19 from common import chromium_utils |
| 20 from common import find_depot_tools # pylint: disable=W0611 | 20 from common import find_depot_tools # pylint: disable=W0611 |
| 21 | 21 |
| 22 from slave.swarming import swarming_utils | 22 from slave.swarming import swarming_utils |
| 23 | 23 |
| 24 # From depot tools/ | 24 # From depot tools/ |
| 25 import fix_encoding | 25 import fix_encoding |
| 26 | 26 |
| 27 | 27 |
| 28 PRIORITIES = { |
| 29 'ci': 10, |
| 30 'cq': 20, |
| 31 'fyi': 30, |
| 32 'tryjob': 40, |
| 33 } |
| 34 |
| 35 |
| 28 def v0(client, options): | 36 def v0(client, options): |
| 29 """Compatible up to the oldest swarm_client code.""" | 37 """Compatible up to the oldest swarm_client code.""" |
| 30 cmd = [ | 38 cmd = [ |
| 31 sys.executable, | 39 sys.executable, |
| 32 os.path.join(client, 'swarm_trigger_step.py'), | 40 os.path.join(client, 'swarm_trigger_step.py'), |
| 33 '--swarm-url', options.swarming, | 41 '--swarm-url', options.swarming, |
| 34 '--data-server', options.isolate_server, | 42 '--data-server', options.isolate_server, |
| 35 '--os_image', options.os, | 43 '--os_image', options.os, |
| 36 '--test-name-prefix', options.task_prefix, | 44 '--test-name-prefix', options.task_prefix, |
| 37 ] | 45 ] |
| 38 for i in options.tasks: | 46 for i in options.tasks: |
| 39 cmd.append('--run_from_hash') | 47 cmd.append('--run_from_hash') |
| 40 cmd.extend(i) | 48 cmd.extend(i) |
| 41 | 49 |
| 42 print ' '.join(cmd) | 50 print ' '.join(cmd) |
| 43 return subprocess.call(cmd, cwd=client) | 51 return subprocess.call(cmd, cwd=client) |
| 44 | 52 |
| 45 | 53 |
| 54 def v0_1(client, options): |
| 55 """Code starting around r218375. |
| 56 |
| 57 TODO(maruel): Put exact revision once committe.d |
| 58 """ |
| 59 cmd = [ |
| 60 sys.executable, |
| 61 os.path.join(client, 'swarming.py'), |
| 62 'trigger', |
| 63 '--swarming', options.swarming, |
| 64 '--isolate-server', options.isolate_server, |
| 65 '--os', options.os, |
| 66 '--task-prefix', options.task_prefix, |
| 67 '--priority', str(PRIORITIES[options.type]), |
| 68 ] |
| 69 |
| 70 for i in options.tasks: |
| 71 cmd.append('--task') |
| 72 cmd.extend(i) |
| 73 |
| 74 # Enable profiling on the -dev server. |
| 75 if '-dev' in options.swarming: |
| 76 cmd.append('--profile') |
| 77 |
| 78 print ' '.join(cmd) |
| 79 return subprocess.call(cmd, cwd=client) |
| 80 |
| 81 |
| 46 def determine_version_and_run_handler(client, options): | 82 def determine_version_and_run_handler(client, options): |
| 47 """Executes the proper handler based on the code layout and --version support. | 83 """Executes the proper handler based on the code layout and --version support. |
| 48 """ | 84 """ |
| 49 # TODO(maruel): Determine version. | 85 if os.path.isfile(os.path.join(client, 'swarm_get_results.py')): |
| 50 return v0(client, options) | 86 # Oh, that's old. |
| 87 return v0(client, options) |
| 88 return v0_1(client, options) |
| 51 | 89 |
| 52 | 90 |
| 53 def process_build_properties(options): | 91 def process_build_properties(options): |
| 54 """Converts build properties and factory properties into expected flags.""" | 92 """Converts build properties and factory properties into expected flags.""" |
| 55 options.task_prefix = '%s-%s-' % ( | 93 options.task_prefix = '%s-%s-' % ( |
| 56 options.build_properties.get('buildername'), | 94 options.build_properties.get('buildername'), |
| 57 options.build_properties.get('buildnumber'), | 95 options.build_properties.get('buildnumber'), |
| 58 ) | 96 ) |
| 59 # target_os is not defined when using a normal builder (and it's not | 97 # 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. | 98 # needed since the OS match), it's defined in builder/tester configurations. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 79 | 117 |
| 80 parser = optparse.OptionParser() | 118 parser = optparse.OptionParser() |
| 81 parser.add_option( | 119 parser.add_option( |
| 82 '--os', default=sys.platform, | 120 '--os', default=sys.platform, |
| 83 help='it\'s possible to trigger a task on an OS while the client code ' | 121 help='it\'s possible to trigger a task on an OS while the client code ' |
| 84 'runs on another OS') | 122 'runs on another OS') |
| 85 parser.add_option('--swarming') | 123 parser.add_option('--swarming') |
| 86 parser.add_option('--isolate-server') | 124 parser.add_option('--isolate-server') |
| 87 parser.add_option('--task-prefix', help='task name prefix') | 125 parser.add_option('--task-prefix', help='task name prefix') |
| 88 parser.add_option( | 126 parser.add_option( |
| 127 '--type', |
| 128 choices=sorted(PRIORITIES), |
| 129 default='fyi', |
| 130 help='Type of job will define it\'s priority') |
| 131 parser.add_option( |
| 89 '--task', nargs=4, action='append', default=[], dest='tasks') | 132 '--task', nargs=4, action='append', default=[], dest='tasks') |
| 90 chromium_utils.AddPropertiesOptions(parser) | 133 chromium_utils.AddPropertiesOptions(parser) |
| 91 options, args = parser.parse_args() | 134 options, args = parser.parse_args() |
| 92 if args: | 135 if args: |
| 93 parser.error('Unsupported args: %s' % args) | 136 parser.error('Unsupported args: %s' % args) |
| 94 | 137 |
| 95 if options.build_properties: | 138 if options.build_properties: |
| 96 # Loads the other flags implicitly. | 139 # Loads the other flags implicitly. |
| 97 process_build_properties(options) | 140 process_build_properties(options) |
| 98 | 141 |
| 99 return determine_version_and_run_handler(client, options) | 142 return determine_version_and_run_handler(client, options) |
| 100 | 143 |
| 101 | 144 |
| 102 if __name__ == '__main__': | 145 if __name__ == '__main__': |
| 103 fix_encoding.fix_encoding() | 146 fix_encoding.fix_encoding() |
| 104 sys.exit(main()) | 147 sys.exit(main()) |
| OLD | NEW |