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

Side by Side Diff: appengine/swarming/swarming_bot/bot_code/task_runner.py

Issue 2043853002: Complete CIPD integration (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@run-isolated-cipd
Patch Set: rebased and nit Created 4 years, 6 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 2013 The LUCI Authors. All rights reserved. 1 # Copyright 2013 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Runs a Swarming task. 5 """Runs a Swarming task.
6 6
7 Downloads all the necessary files to run the task, executes the command and 7 Downloads all the necessary files to run the task, executes the command and
8 streams results back to the Swarming server. 8 streams results back to the Swarming server.
9 9
10 The process exit code is 0 when the task was executed, even if the task itself 10 The process exit code is 0 when the task was executed, even if the task itself
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 '-I', task_details.isolated['server'].encode('utf-8'), 96 '-I', task_details.isolated['server'].encode('utf-8'),
97 '--namespace', task_details.isolated['namespace'].encode('utf-8'), 97 '--namespace', task_details.isolated['namespace'].encode('utf-8'),
98 ]) 98 ])
99 isolated_input = task_details.isolated.get('input') 99 isolated_input = task_details.isolated.get('input')
100 if isolated_input: 100 if isolated_input:
101 cmd.extend( 101 cmd.extend(
102 [ 102 [
103 '--isolated', isolated_input, 103 '--isolated', isolated_input,
104 ]) 104 ])
105 105
106 if task_details.cipd_input and task_details.cipd_input.get('packages'):
107 to_pkg = lambda p: '%s:%s' % (p['package_name'], p['version'])
108 cmd.extend(
109 [
110 '--cipd-cache', os.path.join(bot_dir, 'cipd_cache'),
111 '--cipd-client-package',
112 to_pkg(task_details.cipd_input.get('client_package')),
113 '--cipd-server', task_details.cipd_input.get('server'),
114 ])
115 for p in task_details.cipd_input['packages']:
116 cmd.extend(['--cipd-package', to_pkg(p)])
M-A Ruel 2016/06/10 02:06:42 (FYI only) Eventually we may have to pass this inf
117
106 cmd.extend( 118 cmd.extend(
107 [ 119 [
108 '--json', isolated_result, 120 '--json', isolated_result,
109 '--log-file', os.path.join(bot_dir, 'logs', 'run_isolated.log'), 121 '--log-file', os.path.join(bot_dir, 'logs', 'run_isolated.log'),
110 '--cache', os.path.join(bot_dir, 'cache'), 122 '--cache', os.path.join(bot_dir, 'isolated_cache'),
M-A Ruel 2016/06/17 17:38:32 Oh, this is problematic, now all the bots have a s
nodir 2016/06/17 18:58:57 I should not have done that
111 '--root-dir', os.path.join(work_dir, 'isolated'), 123 '--root-dir', os.path.join(work_dir, 'isolated'),
112 ]) 124 ])
113 if min_free_space: 125 if min_free_space:
114 cmd.extend(('--min-free-space', str(min_free_space))) 126 cmd.extend(('--min-free-space', str(min_free_space)))
115 127
116 if task_details.hard_timeout: 128 if task_details.hard_timeout:
117 cmd.extend(('--hard-timeout', str(task_details.hard_timeout))) 129 cmd.extend(('--hard-timeout', str(task_details.hard_timeout)))
118 if task_details.grace_period: 130 if task_details.grace_period:
119 cmd.extend(('--grace-period', str(task_details.grace_period))) 131 cmd.extend(('--grace-period', str(task_details.grace_period)))
120 132
(...skipping 15 matching lines...) Expand all
136 # Get all the data first so it fails early if the task details is invalid. 148 # Get all the data first so it fails early if the task details is invalid.
137 self.bot_id = data['bot_id'] 149 self.bot_id = data['bot_id']
138 150
139 # Raw command. Only self.command or self.isolated.input can be set. 151 # Raw command. Only self.command or self.isolated.input can be set.
140 self.command = data['command'] or [] 152 self.command = data['command'] or []
141 153
142 # Isolated command. Is a serialized version of task_request.FilesRef. 154 # Isolated command. Is a serialized version of task_request.FilesRef.
143 self.isolated = data['isolated'] 155 self.isolated = data['isolated']
144 self.extra_args = data['extra_args'] 156 self.extra_args = data['extra_args']
145 157
158 self.cipd_input = data.get('cipd_input')
159
146 self.env = { 160 self.env = {
147 k.encode('utf-8'): v.encode('utf-8') for k, v in data['env'].iteritems() 161 k.encode('utf-8'): v.encode('utf-8') for k, v in data['env'].iteritems()
148 } 162 }
149 self.grace_period = data['grace_period'] 163 self.grace_period = data['grace_period']
150 self.hard_timeout = data['hard_timeout'] 164 self.hard_timeout = data['hard_timeout']
151 self.io_timeout = data['io_timeout'] 165 self.io_timeout = data['io_timeout']
152 self.task_id = data['task_id'] 166 self.task_id = data['task_id']
153 167
154 168
155 class MustExit(Exception): 169 class MustExit(Exception):
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if run_isolated_result.get('duration') is not None: 524 if run_isolated_result.get('duration') is not None:
511 # Calculate the real task duration as measured by run_isolated and 525 # Calculate the real task duration as measured by run_isolated and
512 # calculate the remaining overhead. 526 # calculate the remaining overhead.
513 params['bot_overhead'] = params['duration'] 527 params['bot_overhead'] = params['duration']
514 params['duration'] = run_isolated_result['duration'] 528 params['duration'] = run_isolated_result['duration']
515 params['bot_overhead'] -= params['duration'] 529 params['bot_overhead'] -= params['duration']
516 params['bot_overhead'] -= run_isolated_result.get( 530 params['bot_overhead'] -= run_isolated_result.get(
517 'download', {}).get('duration', 0) 531 'download', {}).get('duration', 0)
518 params['bot_overhead'] -= run_isolated_result.get( 532 params['bot_overhead'] -= run_isolated_result.get(
519 'upload', {}).get('duration', 0) 533 'upload', {}).get('duration', 0)
534 params['bot_overhead'] -= run_isolated_result.get(
535 'cipd', {}).get('duration', 0)
520 if params['bot_overhead'] < 0: 536 if params['bot_overhead'] < 0:
521 params['bot_overhead'] = 0 537 params['bot_overhead'] = 0
522 isolated_stats = run_isolated_result.get('stats', {}).get('isolated') 538 isolated_stats = run_isolated_result.get('stats', {}).get('isolated')
523 if isolated_stats: 539 if isolated_stats:
524 params['isolated_stats'] = isolated_stats 540 params['isolated_stats'] = isolated_stats
541 cipd_stats = run_isolated_result.get('stats', {}).get('cipd')
542 if cipd_stats:
543 params['cipd_stats'] = cipd_stats
525 except (IOError, OSError, ValueError) as e: 544 except (IOError, OSError, ValueError) as e:
526 logging.error('Swallowing error: %s', e) 545 logging.error('Swallowing error: %s', e)
527 if not must_signal_internal_failure: 546 if not must_signal_internal_failure:
528 must_signal_internal_failure = str(e) 547 must_signal_internal_failure = str(e)
529 # TODO(maruel): Send the internal failure here instead of sending it through 548 # TODO(maruel): Send the internal failure here instead of sending it through
530 # bot_main, this causes a race condition. 549 # bot_main, this causes a race condition.
531 if exit_code is None: 550 if exit_code is None:
532 exit_code = -1 551 exit_code = -1
533 params['hard_timeout'] = had_hard_timeout 552 params['hard_timeout'] = had_hard_timeout
534 post_update( 553 post_update(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 if options.start > now: 594 if options.start > now:
576 options.start = now 595 options.start = now
577 596
578 try: 597 try:
579 load_and_run( 598 load_and_run(
580 options.in_file, options.swarming_server, options.cost_usd_hour, 599 options.in_file, options.swarming_server, options.cost_usd_hour,
581 options.start, options.out_file, options.min_free_space) 600 options.start, options.out_file, options.min_free_space)
582 return 0 601 return 0
583 finally: 602 finally:
584 logging.info('quitting') 603 logging.info('quitting')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698