Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: scripts/slave/swarming/trigger_swarm_shim.py

Issue 139343011: Add swarming_run_shim.py to run swarming tasks as annotated tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: tested Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
M-A Ruel 2014/01/24 03:19:00 this file will be removed soon, no master after be
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.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 client, swarming, isolate_server, priority, tasks, task_prefix, slave_os): 51 client, swarming, isolate_server, priority, tasks, task_prefix, slave_os):
52 """Handles swarm_client/swarming.py starting r219798.""" 52 """Handles swarm_client/swarming.py starting r219798."""
53 cmd = [ 53 cmd = [
54 sys.executable, 54 sys.executable,
55 os.path.join(client, 'swarming.py'), 55 os.path.join(client, 'swarming.py'),
56 'trigger', 56 'trigger',
57 '--swarming', swarming, 57 '--swarming', swarming,
58 '--isolate-server', isolate_server, 58 '--isolate-server', isolate_server,
59 '--os', slave_os, 59 '--os', slave_os,
60 '--task-prefix', task_prefix, 60 '--task-prefix', task_prefix,
61 '--priority', priority, 61 '--priority', str(priority),
62 ] 62 ]
63 63
64 for i in tasks: 64 for i in tasks:
65 cmd.append('--task') 65 cmd.append('--task')
66 cmd.extend(i) 66 cmd.extend(i)
67 67
68 # Enable profiling on the -dev server. 68 # Enable profiling on the -dev server.
69 if '-dev' in swarming: 69 if '-dev' in swarming:
70 cmd.append('--profile') 70 cmd.append('--profile')
71 71
72 print(' '.join(cmd)) 72 print(' '.join(cmd))
73 sys.stdout.flush() 73 sys.stdout.flush()
74 return subprocess.call(cmd, cwd=client) 74 return subprocess.call(cmd, cwd=client)
75 75
76 76
77 def v0_3( 77 def v0_3(
78 client, swarming, isolate_server, priority, tasks, task_prefix, slave_os): 78 client, swarming, isolate_server, priority, tasks, task_prefix, slave_os):
79 """Handles swarm_client/swarming.py starting 7c543276f08.""" 79 """Handles swarm_client/swarming.py starting 7c543276f08."""
80 ret = 0 80 ret = 0
81 for isolated_hash, test_name, shards, gtest_filter in tasks: 81 for isolated_hash, test_name, shards, gtest_filter in tasks:
82 cmd = [ 82 cmd = [
83 sys.executable, 83 sys.executable,
84 os.path.join(client, 'swarming.py'), 84 os.path.join(client, 'swarming.py'),
85 'trigger', 85 'trigger',
86 '--swarming', swarming, 86 '--swarming', swarming,
87 '--isolate-server', isolate_server, 87 '--isolate-server', isolate_server,
88 '--os', slave_os, 88 '--os', slave_os,
89 '--priority', priority, 89 '--priority', str(priority),
90 '--shards', shards, 90 '--shards', str(shards),
91 '--task-name', task_prefix + test_name, 91 '--task-name', task_prefix + test_name,
92 isolated_hash, 92 isolated_hash,
93 ] 93 ]
94 # Enable profiling on the -dev server. 94 # Enable profiling on the -dev server.
95 if '-dev' in swarming: 95 if '-dev' in swarming:
96 cmd.append('--profile') 96 cmd.append('--profile')
97 if gtest_filter not in (None, '', '.', '*'): 97 if gtest_filter not in (None, '', '.', '*'):
98 cmd.extend(('--env', 'GTEST_FILTER', gtest_filter)) 98 cmd.extend(('--env', 'GTEST_FILTER', gtest_filter))
99 print(' '.join(cmd)) 99 print(' '.join(cmd))
100 sys.stdout.flush() 100 sys.stdout.flush()
101 ret = max(ret, subprocess.call(cmd, cwd=client)) 101 ret = max(ret, subprocess.call(cmd, cwd=client))
102 return ret 102 return ret
103 103
104 104
105 def v0_4(client, swarming, isolate_server, priority, tasks, slave_os): 105 def v0_4(client, swarming, isolate_server, priority, tasks, slave_os):
106 """Handles swarm_client/swarming.py starting b39e8cf08c.""" 106 """Handles swarm_client/swarming.py starting b39e8cf08c."""
107 ret = 0 107 ret = 0
108 for isolated_hash, test_name, shards, gtest_filter in tasks: 108 for isolated_hash, test_name, shards, gtest_filter in tasks:
109 selected_os = swarming_utils.OS_MAPPING[slave_os] 109 selected_os = swarming_utils.OS_MAPPING[slave_os]
110 task_name = '%s/%s/%s' % (test_name, selected_os, isolated_hash) 110 task_name = '%s/%s/%s' % (test_name, selected_os, isolated_hash)
111 cmd = [ 111 cmd = [
112 sys.executable, 112 sys.executable,
113 os.path.join(client, 'swarming.py'), 113 os.path.join(client, 'swarming.py'),
114 'trigger', 114 'trigger',
115 '--swarming', swarming, 115 '--swarming', swarming,
116 '--isolate-server', isolate_server, 116 '--isolate-server', isolate_server,
117 '--dimension', 'os', selected_os, 117 '--dimension', 'os', selected_os,
118 '--priority', priority, 118 '--priority', str(priority),
119 '--shards', shards, 119 '--shards', str(shards),
120 '--task-name', task_name, 120 '--task-name', task_name,
121 isolated_hash, 121 isolated_hash,
122 ] 122 ]
123 # Enable profiling on the -dev server. 123 # Enable profiling on the -dev server.
124 if '-dev' in swarming: 124 if '-dev' in swarming:
125 cmd.append('--profile') 125 cmd.append('--profile')
126 if gtest_filter not in (None, '', '.', '*'): 126 if gtest_filter not in (None, '', '.', '*'):
127 cmd.extend(('--env', 'GTEST_FILTER', gtest_filter)) 127 cmd.extend(('--env', 'GTEST_FILTER', gtest_filter))
128 print('Triggering %s' % task_name) 128 print('Triggering %s' % task_name)
129 print(' '.join(cmd)) 129 print(' '.join(cmd))
130 sys.stdout.flush() 130 sys.stdout.flush()
131 ret = max(ret, subprocess.call(cmd, cwd=client)) 131 ret = max(ret, subprocess.call(cmd, cwd=client))
132 return ret 132 return ret
133 133
134 134
135 def determine_version_and_run_handler( 135 def trigger(
136 client, swarming, isolate_server, priority, tasks, task_prefix, slave_os): 136 client, swarming, isolate_server, priority, tasks, task_prefix, slave_os):
137 """Executes the proper handler based on the code layout and --version support. 137 """Executes the proper handler based on the code layout and --version support.
138 """ 138 """
139 if os.path.isfile(os.path.join(client, 'swarm_get_results.py')): 139 if os.path.isfile(os.path.join(client, 'swarm_get_results.py')):
140 # Oh, that's old. This can be removed on 2014-01-01 and replaced on hard 140 # Oh, that's old. This can be removed on 2014-01-01 and replaced on hard
141 # failure if swarming.py doesn't exist. 141 # failure if swarming.py doesn't exist.
142 return v0(client, swarming, isolate_server, tasks, task_prefix, slave_os) 142 return v0(client, swarming, isolate_server, tasks, task_prefix, slave_os)
143 143
144 version = swarming_utils.get_version(client) 144 version = swarming_utils.get_version(client)
145 if version < (0, 3): 145 if version < (0, 3):
(...skipping 11 matching lines...) Expand all
157 def process_build_properties(options): 157 def process_build_properties(options):
158 """Converts build properties and factory properties into expected flags.""" 158 """Converts build properties and factory properties into expected flags."""
159 task_prefix = '%s-%s-' % ( 159 task_prefix = '%s-%s-' % (
160 options.build_properties['buildername'], 160 options.build_properties['buildername'],
161 options.build_properties['buildnumber'], 161 options.build_properties['buildnumber'],
162 ) 162 )
163 # target_os is not defined when using a normal builder, contrary to a 163 # target_os is not defined when using a normal builder, contrary to a
164 # xx_swarm_triggered buildbot<->swarming builder, and it's not needed since 164 # xx_swarm_triggered buildbot<->swarming builder, and it's not needed since
165 # the OS match, it's defined in builder/tester configurations. 165 # the OS match, it's defined in builder/tester configurations.
166 slave_os = options.build_properties.get('target_os', sys.platform) 166 slave_os = options.build_properties.get('target_os', sys.platform)
167 167 priority = swarming_utils.build_to_priority(options.build_properties)
168 # TODO(maruel): Also select the OS version.
169
170 # Determine the build type. This is used to determine the task priority. Lower
171 # is higher priority.
172 if options.build_properties.get('requester') == 'commit-bot@chromium.org':
173 # Commit queue job.
174 priority = '20'
175 elif (options.build_properties.get('requester') or
176 options.build_properties.get('testfilter')):
177 # Normal try job.
178 priority = '40'
179 else:
180 # FYI builder.
181 priority = '30'
182
183 return task_prefix, slave_os, priority 168 return task_prefix, slave_os, priority
184 169
185 170
186 def main(): 171 def main():
187 """Note: this is solely to run the current master's code and can totally 172 """Note: this is solely to run the current master's code and can totally
188 differ from the underlying script flags. 173 differ from the underlying script flags.
189 174
190 To update these flags: 175 To update these flags:
191 - Update the following code to support both the previous flag and the new 176 - Update the following code to support both the previous flag and the new
192 flag. 177 flag.
193 - Change scripts/master/factory/swarm_commands.py to pass the new flag. 178 - Change scripts/master/factory/swarm_commands.py to pass the new flag.
194 - Restart all the masters using swarming. 179 - Restart all the masters using swarming.
195 - Remove the old flag from this code. 180 - Remove the old flag from this code.
196 """ 181 """
197 client = swarming_utils.find_client(os.getcwd()) 182 client = swarming_utils.find_client(os.getcwd())
198 if not client: 183 if not client:
199 print >> sys.stderr, 'Failed to find swarm(ing)_client' 184 print >> sys.stderr, 'Failed to find swarm(ing)_client'
200 return 1 185 return 1
201 186
202 parser = optparse.OptionParser() 187 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__)
203 parser.add_option('--swarming') 188 parser.add_option('--swarming')
204 parser.add_option('--isolate-server') 189 parser.add_option('--isolate-server')
205 parser.add_option( 190 parser.add_option(
206 '--task', nargs=4, action='append', default=[], dest='tasks') 191 '--task', nargs=4, action='append', default=[], dest='tasks')
207 chromium_utils.AddPropertiesOptions(parser) 192 chromium_utils.AddPropertiesOptions(parser)
208 options, args = parser.parse_args() 193 options, args = parser.parse_args()
209 if args: 194 if args:
210 parser.error('Unsupported args: %s' % args) 195 parser.error('Unsupported args: %s' % args)
211 196
212 # Loads the other flags implicitly. 197 # Loads the other flags implicitly.
213 task_prefix, slave_os, priority = process_build_properties(options) 198 task_prefix, slave_os, priority = process_build_properties(options)
214 199
215 return determine_version_and_run_handler( 200 return trigger(
216 client, options.swarming, options.isolate_server, priority, 201 client, options.swarming, options.isolate_server, priority,
217 options.tasks, task_prefix, slave_os) 202 options.tasks, task_prefix, slave_os)
218 203
219 204
220 if __name__ == '__main__': 205 if __name__ == '__main__':
221 fix_encoding.fix_encoding() 206 fix_encoding.fix_encoding()
222 sys.exit(main()) 207 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698