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

Side by Side Diff: client/tools/parallel_execution.py

Issue 1233303003: Migrate and merge logging_utils from swarming_bot into client/utils. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Changed formatter Created 5 years, 5 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
OLDNEW
1 # Copyright 2014 The Swarming Authors. All rights reserved. 1 # Copyright 2014 The Swarming Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 that 2 # Use of this source code is governed under the Apache License, Version 2.0 that
3 # can be found in the LICENSE file. 3 # can be found in the LICENSE file.
4 4
5 """Toolset to run multiple Swarming tasks in parallel.""" 5 """Toolset to run multiple Swarming tasks in parallel."""
6 6
7 import getpass 7 import getpass
8 import json 8 import json
9 import os 9 import os
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import tempfile 12 import tempfile
13 import time 13 import time
14 14
15 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 15 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
16 ROOT_DIR = os.path.dirname(BASE_DIR) 16 ROOT_DIR = os.path.dirname(BASE_DIR)
17 17
18 sys.path.insert(0, ROOT_DIR) 18 sys.path.insert(0, ROOT_DIR)
19 19
20 import auth 20 import auth
21 import isolateserver 21 import isolateserver
22 from utils import logging_utils
22 from utils import threading_utils 23 from utils import threading_utils
23 from utils import tools 24 from utils import tools
24 25
25 26
26 def task_to_name(name, dimensions, isolated_hash): 27 def task_to_name(name, dimensions, isolated_hash):
27 """Returns a task name the same way swarming.py generates them.""" 28 """Returns a task name the same way swarming.py generates them."""
28 return '%s/%s/%s' % ( 29 return '%s/%s/%s' % (
29 name, 30 name,
30 '_'.join('%s=%s' % (k, v) for k, v in sorted(dimensions.iteritems())), 31 '_'.join('%s=%s' % (k, v) for k, v in sorted(dimensions.iteritems())),
31 isolated_hash) 32 isolated_hash)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 failed_tasks.append(task_name) 145 failed_tasks.append(task_name)
145 146
146 duration = time.time() - start 147 duration = time.time() - start
147 print('\nCompleted in %3.2fs' % duration) 148 print('\nCompleted in %3.2fs' % duration)
148 if failed_tasks: 149 if failed_tasks:
149 print('Detected the following failures:') 150 print('Detected the following failures:')
150 for task in sorted(failed_tasks): 151 for task in sorted(failed_tasks):
151 print(' %s' % task) 152 print(' %s' % task)
152 153
153 154
154 class OptionParser(tools.OptionParserWithLogging): 155 class OptionParser(logging_utils.OptionParserWithLogging):
155 def __init__(self, **kwargs): 156 def __init__(self, **kwargs):
156 tools.OptionParserWithLogging.__init__(self, **kwargs) 157 logging_utils.OptionParserWithLogging.__init__(self, **kwargs)
157 self.server_group = tools.optparse.OptionGroup(self, 'Server') 158 self.server_group = tools.optparse.OptionGroup(self, 'Server')
158 self.server_group.add_option( 159 self.server_group.add_option(
159 '-S', '--swarming', 160 '-S', '--swarming',
160 metavar='URL', default=os.environ.get('SWARMING_SERVER', ''), 161 metavar='URL', default=os.environ.get('SWARMING_SERVER', ''),
161 help='Swarming server to use') 162 help='Swarming server to use')
162 isolateserver.add_isolate_server_options(self.server_group) 163 isolateserver.add_isolate_server_options(self.server_group)
163 self.add_option_group(self.server_group) 164 self.add_option_group(self.server_group)
164 auth.add_auth_options(self) 165 auth.add_auth_options(self)
165 self.add_option( 166 self.add_option(
166 '-d', '--dimension', default=[], action='append', nargs=2, 167 '-d', '--dimension', default=[], action='append', nargs=2,
167 dest='dimensions', metavar='FOO bar', 168 dest='dimensions', metavar='FOO bar',
168 help='dimension to filter on') 169 help='dimension to filter on')
169 self.add_option( 170 self.add_option(
170 '--priority', type='int', 171 '--priority', type='int',
171 help='The lower value, the more important the task is. It may be ' 172 help='The lower value, the more important the task is. It may be '
172 'important to specify a higher priority since the default value ' 173 'important to specify a higher priority since the default value '
173 'will make the task to be triggered only when the bots are idle.') 174 'will make the task to be triggered only when the bots are idle.')
174 self.add_option( 175 self.add_option(
175 '--deadline', type='int', default=6*60*60, 176 '--deadline', type='int', default=6*60*60,
176 help='Seconds to allow the task to be pending for a bot to run before ' 177 help='Seconds to allow the task to be pending for a bot to run before '
177 'this task request expires.') 178 'this task request expires.')
178 179
179 def parse_args(self, *args, **kwargs): 180 def parse_args(self, *args, **kwargs):
180 options, args = tools.OptionParserWithLogging.parse_args( 181 options, args = logging_utils.OptionParserWithLogging.parse_args(
181 self, *args, **kwargs) 182 self, *args, **kwargs)
182 options.swarming = options.swarming.rstrip('/') 183 options.swarming = options.swarming.rstrip('/')
183 if not options.swarming: 184 if not options.swarming:
184 self.error('--swarming is required.') 185 self.error('--swarming is required.')
185 auth.process_auth_options(self, options) 186 auth.process_auth_options(self, options)
186 isolateserver.process_isolate_server_options(self, options, False) 187 isolateserver.process_isolate_server_options(self, options, False)
187 options.dimensions = dict(options.dimensions) 188 options.dimensions = dict(options.dimensions)
188 return options, args 189 return options, args
189 190
190 def format_description(self, _): 191 def format_description(self, _):
191 return self.description 192 return self.description
OLDNEW
« no previous file with comments | « client/tests/run_isolated_test.py ('k') | client/trace_inputs.py » ('j') | client/utils/tools.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698