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

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

Issue 23176003: Create proper wrapper scripts to decouple from swarm_client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Had forgot to append _shim to one comment Created 7 years, 3 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
« no previous file with comments | « scripts/slave/swarming/get_swarm_results.py ('k') | scripts/slave/swarming/swarming_utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Takes in a test name and retrives all the output that the swarm server 6 """Takes in a test name and retrives all the output that the swarm server
7 has produced for tests with that name. This is expected to be called as a 7 has produced for tests with that name. This is expected to be called as a
8 build step.""" 8 build step.
9 """
9 10
11 import optparse
10 import os 12 import os
11 import sys 13 import sys
12 14
13 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 15 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
14 16
17 from common import chromium_utils
15 from common import find_depot_tools # pylint: disable=W0611 18 from common import find_depot_tools # pylint: disable=W0611
16 from common import gtest_utils 19 from common import gtest_utils
17 20
18 from slave.swarming import swarming_utils 21 from slave.swarming import swarming_utils
19 22
20 # From depot tools/ 23 # From depot_tools/
21 import fix_encoding 24 import fix_encoding
22 25
23 26
24 NO_OUTPUT_FOUND = ( 27 NO_OUTPUT_FOUND = (
25 'No output produced by the test, it may have failed to run.\n' 28 'No output produced by the test, it may have failed to run.\n'
26 'Showing all the output, including swarm specific output.\n' 29 'Showing all the output, including swarm specific output.\n'
27 '\n') 30 '\n')
28 31
29 32
30 def gen_shard_output(result, gtest_parser): 33 def gen_shard_output(result, gtest_parser):
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if shards_remaining: 74 if shards_remaining:
72 out += 'Not all shards were executed.\n' 75 out += 'Not all shards were executed.\n'
73 out += 'The following gtest shards weren\'t run:\n' 76 out += 'The following gtest shards weren\'t run:\n'
74 out += ''.join(' %d\n' % shard_id for shard_id in shards_remaining) 77 out += ''.join(' %d\n' % shard_id for shard_id in shards_remaining)
75 exit_code = exit_code or 1 78 exit_code = exit_code or 1
76 elif not failed_tests: 79 elif not failed_tests:
77 out += 'All tests passed.' 80 out += 'All tests passed.'
78 return out, exit_code 81 return out, exit_code
79 82
80 83
81 def GetSwarmResults( 84 def v0(client, options, test_name):
82 swarm_get_results, swarm_base_url, test_keys, timeout, max_threads): 85 """This code supports all the earliest versions of swarm_client.
86
87 This is before --version was added.
88 """
89 sys.path.insert(0, client)
90 import swarm_get_results # pylint: disable=F0401
91
92 timeout = swarm_get_results.DEFAULT_SHARD_WAIT_TIME
93 test_keys = swarm_get_results.get_test_keys(
94 options.swarming, test_name, timeout)
95 if not test_keys:
96 print >> sys.stderr, 'No test keys to get results with.'
97 return 1
98
99 if options.shards == -1:
100 options.shards = len(test_keys)
101 elif len(test_keys) < options.shards:
102 print >> sys.stderr, ('Warning: Test should have %d shards, but only %d '
103 'test keys were found' % (options.shards,
104 len(test_keys)))
105
83 gtest_parser = gtest_utils.GTestLogParser() 106 gtest_parser = gtest_utils.GTestLogParser()
84 exit_code = None 107 exit_code = None
85 shards_remaining = range(len(test_keys)) 108 shards_remaining = range(len(test_keys))
86 first_result = True 109 first_result = True
87 for index, result in swarm_get_results.yield_results( 110 for index, result in swarm_get_results.yield_results(
88 swarm_base_url, test_keys, timeout, max_threads): 111 options.swarming, test_keys, timeout, None):
89 assert index == result['config_instance_index'] 112 assert index == result['config_instance_index']
90 if first_result and result['num_config_instances'] != len(test_keys): 113 if first_result and result['num_config_instances'] != len(test_keys):
91 # There are more test_keys than actual shards. 114 # There are more test_keys than actual shards.
92 shards_remaining = shards_remaining[:result['num_config_instances']] 115 shards_remaining = shards_remaining[:result['num_config_instances']]
93 shards_remaining.remove(index) 116 shards_remaining.remove(index)
94 first_result = False 117 first_result = False
95 output, test_exit_code = gen_shard_output(result, gtest_parser) 118 output, test_exit_code = gen_shard_output(result, gtest_parser)
96 print output 119 print output
97 exit_code = max(exit_code, test_exit_code) 120 exit_code = max(exit_code, test_exit_code)
98 121
99 output, exit_code = gen_summary_output( 122 output, exit_code = gen_summary_output(
100 gtest_parser.FailedTests(), 123 gtest_parser.FailedTests(),
101 exit_code, 124 exit_code,
102 shards_remaining) 125 shards_remaining)
103 print output 126 print output
104 return exit_code 127 return exit_code
105 128
106 129
130 def determine_version_and_run_handler(client, options, test_name):
131 """Executes the proper handler based on the code layout and --version
132 support.
133 """
134 # TODO(maruel): Determine version when needed.
135 return v0(client, options, test_name)
136
137
138 def process_build_properties(options, name):
139 """Converts build properties and factory properties into expected flags."""
140 taskname = '%s-%s-%s' % (
141 options.build_properties.get('buildername'),
142 options.build_properties.get('buildnumber'),
143 name,
144 )
145 return taskname
146
147
107 def main(): 148 def main():
149 """Note: this is solely to run the current master's code and can totally
150 differ from the underlying script flags.
151
152 To update these flags:
153 - Update the following code to support both the previous flag and the new
154 flag.
155 - Change scripts/master/factory/swarm_commands.py to pass the new flag.
156 - Restart all the masters using swarming.
157 - Remove the old flag from this code.
158 """
108 client = swarming_utils.find_client(os.getcwd()) 159 client = swarming_utils.find_client(os.getcwd())
109 if not client: 160 if not client:
110 print >> sys.stderr, 'Failed to find swarm(ing)_client' 161 print >> sys.stderr, 'Failed to find swarm(ing)_client'
111 return 1 162 return 1
112 163
113 # TODO(maruel): Do not import, reproduce the same flags and forward to a 164 parser = optparse.OptionParser()
114 # subprocess.call() instead. 165 parser.add_option('-u', '--swarming', help='Swarm server')
115 sys.path.insert(0, client) 166 parser.add_option(
116 import swarm_get_results # pylint: disable=F0401 167 '-s', '--shards', type='int', default=-1, help='Number of shards')
168 chromium_utils.AddPropertiesOptions(parser)
169 (options, args) = parser.parse_args()
170 options.swarming = options.swarming.rstrip('/')
117 171
118 parser, options, test_name = swarm_get_results.parse_args() 172 if not args:
119 if not options.shards: 173 parser.error('Must specify one test name.')
120 parser.error('The number of shards expected must be passed in.') 174 elif len(args) > 1:
121 test_keys = swarm_get_results.get_test_keys( 175 parser.error('Must specify only one test name.')
122 options.url, test_name, options.timeout) 176 if options.build_properties:
123 if not test_keys: 177 # Loads the other flags implicitly.
124 parser.error('No test keys to get results with.') 178 task_name = process_build_properties(options, args[0])
125 179 else:
126 options.shards = int(options.shards) 180 task_name = args[0]
127 if options.shards == -1: 181 return determine_version_and_run_handler(client, options, task_name)
128 options.shards = len(test_keys)
129 elif len(test_keys) < options.shards:
130 print >> sys.stderr, ('Warning: Test should have %d shards, but only %d '
131 'test keys were found' % (options.shards,
132 len(test_keys)))
133
134 return GetSwarmResults(
135 swarm_get_results, options.url, test_keys, options.timeout, None)
136 182
137 183
138 if __name__ == '__main__': 184 if __name__ == '__main__':
139 fix_encoding.fix_encoding() 185 fix_encoding.fix_encoding()
140 sys.exit(main()) 186 sys.exit(main())
OLDNEW
« no previous file with comments | « scripts/slave/swarming/get_swarm_results.py ('k') | scripts/slave/swarming/swarming_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698