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

Side by Side Diff: scripts/slave/swarming/get_swarm_results.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: add docstrings Created 7 years, 4 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
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
15 from common import find_depot_tools # pylint: disable=W0611 17 from common import find_depot_tools # pylint: disable=W0611
16 from common import gtest_utils 18 from common import gtest_utils
17 19
18 from slave.swarming import swarming_utils 20 from slave.swarming import swarming_utils
19 21
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if shards_remaining: 73 if shards_remaining:
72 out += 'Not all shards were executed.\n' 74 out += 'Not all shards were executed.\n'
73 out += 'The following gtest shards weren\'t run:\n' 75 out += 'The following gtest shards weren\'t run:\n'
74 out += ''.join(' %d\n' % shard_id for shard_id in shards_remaining) 76 out += ''.join(' %d\n' % shard_id for shard_id in shards_remaining)
75 exit_code = exit_code or 1 77 exit_code = exit_code or 1
76 elif not failed_tests: 78 elif not failed_tests:
77 out += 'All tests passed.' 79 out += 'All tests passed.'
78 return out, exit_code 80 return out, exit_code
79 81
80 82
81 def GetSwarmResults( 83 def v0(client, options, test_name):
Isaac (away) 2013/08/20 22:22:33 v0? Can you add a comment for what this does?
M-A Ruel 2013/08/23 02:18:33 There will be multiple version handler, this is wh
82 swarm_get_results, swarm_base_url, test_keys, timeout, max_threads): 84 sys.path.insert(0, client)
Isaac (away) 2013/08/20 22:22:33 This will repeatedly extend sys.path with each cal
M-A Ruel 2013/08/23 02:18:33 This function is only called once indirectly by ma
Isaac (away) 2013/08/26 02:35:46 I mean, can you verify that if you change swarm_ge
M-A Ruel 2013/08/26 14:15:39 My next CL is to delete swarm_get_results; https:/
85 import swarm_get_results # pylint: disable=F0401
86
87 timeout = swarm_get_results.DEFAULT_SHARD_WAIT_TIME
88 test_keys = swarm_get_results.get_test_keys(
89 options.swarming, test_name, timeout)
90 if not test_keys:
91 print >> sys.stderr, 'No test keys to get results with.'
92 return 1
93
94 options.shards = int(options.shards)
Isaac (away) 2013/08/20 22:22:33 not needed if you add type='int' to parser below.
M-A Ruel 2013/08/23 02:18:33 Done.
95 if options.shards == -1:
96 options.shards = len(test_keys)
97 elif len(test_keys) < options.shards:
98 print >> sys.stderr, ('Warning: Test should have %d shards, but only %d '
99 'test keys were found' % (options.shards,
100 len(test_keys)))
101
83 gtest_parser = gtest_utils.GTestLogParser() 102 gtest_parser = gtest_utils.GTestLogParser()
84 exit_code = None 103 exit_code = None
85 shards_remaining = range(len(test_keys)) 104 shards_remaining = range(len(test_keys))
86 first_result = True 105 first_result = True
87 for index, result in swarm_get_results.yield_results( 106 for index, result in swarm_get_results.yield_results(
88 swarm_base_url, test_keys, timeout, max_threads): 107 options.swarming, test_keys, timeout, None):
89 assert index == result['config_instance_index'] 108 assert index == result['config_instance_index']
90 if first_result and result['num_config_instances'] != len(test_keys): 109 if first_result and result['num_config_instances'] != len(test_keys):
91 # There are more test_keys than actual shards. 110 # There are more test_keys than actual shards.
92 shards_remaining = shards_remaining[:result['num_config_instances']] 111 shards_remaining = shards_remaining[:result['num_config_instances']]
93 shards_remaining.remove(index) 112 shards_remaining.remove(index)
94 first_result = False 113 first_result = False
95 output, test_exit_code = gen_shard_output(result, gtest_parser) 114 output, test_exit_code = gen_shard_output(result, gtest_parser)
96 print output 115 print output
97 exit_code = max(exit_code, test_exit_code) 116 exit_code = max(exit_code, test_exit_code)
98 117
99 output, exit_code = gen_summary_output( 118 output, exit_code = gen_summary_output(
100 gtest_parser.FailedTests(), 119 gtest_parser.FailedTests(),
101 exit_code, 120 exit_code,
102 shards_remaining) 121 shards_remaining)
103 print output 122 print output
104 return exit_code 123 return exit_code
105 124
106 125
126 def determine_version_and_run_handler(client, options, test_name):
127 """Executes the proper handler based on the code layout and --version
128 support.
129 """
130 # TODO(maruel): Determine version when needed.
131 return v0(client, options, test_name)
132
133
107 def main(): 134 def main():
135 """Note: this is solely to run the current master's code and can totally
136 differ from the underlying script flags.
137
138 To update these flags:
139 - Update the following code to support both the previous flag and the new
140 flag.
141 - Change scripts/master/factory/swarm_commands.py to pass the new flag.
142 - Restart all the masters using swarming.
143 - Remove the old flag from this code.
144 """
108 client = swarming_utils.find_client(os.getcwd()) 145 client = swarming_utils.find_client(os.getcwd())
109 if not client: 146 if not client:
110 print >> sys.stderr, 'Failed to find swarm(ing)_client' 147 print >> sys.stderr, 'Failed to find swarm(ing)_client'
111 return 1 148 return 1
112 149
113 # TODO(maruel): Do not import, reproduce the same flags and forward to a 150 parser = optparse.OptionParser()
114 # subprocess.call() instead. 151 parser.add_option('-u', '--swarming', help='Swarm server')
115 sys.path.insert(0, client) 152 parser.add_option('-s', '--shards', help='Number of shards')
Isaac (away) 2013/08/20 22:22:33 type='int'?
M-A Ruel 2013/08/23 02:18:33 Done.
116 import swarm_get_results # pylint: disable=F0401 153 (options, args) = parser.parse_args()
154 if not args:
155 parser.error('Must specify one test name.')
156 elif len(args) > 1:
157 parser.error('Must specify only one test name.')
158 options.swarming = options.swarming.rstrip('/')
117 159
118 parser, options, test_name = swarm_get_results.parse_args() 160 return determine_version_and_run_handler(client, options, args[0])
119 if not options.shards:
120 parser.error('The number of shards expected must be passed in.')
121 test_keys = swarm_get_results.get_test_keys(
122 options.url, test_name, options.timeout)
123 if not test_keys:
124 parser.error('No test keys to get results with.')
125
126 options.shards = int(options.shards)
127 if options.shards == -1:
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 161
137 162
138 if __name__ == '__main__': 163 if __name__ == '__main__':
139 fix_encoding.fix_encoding() 164 fix_encoding.fix_encoding()
140 sys.exit(main()) 165 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698