Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 '-I', task_details.isolated['server'].encode('utf-8'), | 93 '-I', task_details.isolated['server'].encode('utf-8'), |
| 94 '--namespace', task_details.isolated['namespace'].encode('utf-8'), | 94 '--namespace', task_details.isolated['namespace'].encode('utf-8'), |
| 95 ]) | 95 ]) |
| 96 isolated_input = task_details.isolated.get('input') | 96 isolated_input = task_details.isolated.get('input') |
| 97 if isolated_input: | 97 if isolated_input: |
| 98 cmd.extend( | 98 cmd.extend( |
| 99 [ | 99 [ |
| 100 '--isolated', isolated_input, | 100 '--isolated', isolated_input, |
| 101 ]) | 101 ]) |
| 102 | 102 |
| 103 if task_details.cipd_input and task_details.cipd_input.get('packages'): | |
| 104 to_pkg = lambda p: '%s:%s' % (p['package_name'], p['version']) | |
| 105 cmd.extend( | |
| 106 [ | |
| 107 '--cipd-cache', os.path.join(bot_dir, 'cipd_cache'), | |
| 108 '--cipd-client-package', to_pkg( | |
|
M-A Ruel
2016/06/06 23:54:28
I'd prefer the to_pkg( on the next line then the f
nodir
2016/06/09 23:36:28
Done.
| |
| 109 task_details.cipd_input.get('client_package')), | |
| 110 '--cipd-server', task_details.cipd_input.get('server'), | |
| 111 ]) | |
| 112 for p in task_details.cipd_input['packages']: | |
| 113 cmd.extend(['--cipd-package', to_pkg(p)]) | |
| 114 | |
| 103 cmd.extend( | 115 cmd.extend( |
| 104 [ | 116 [ |
| 105 '--json', isolated_result, | 117 '--json', isolated_result, |
| 106 '--log-file', os.path.join(bot_dir, 'logs', 'run_isolated.log'), | 118 '--log-file', os.path.join(bot_dir, 'logs', 'run_isolated.log'), |
| 107 '--cache', os.path.join(bot_dir, 'cache'), | 119 '--cache', os.path.join(bot_dir, 'isolated_cache'), |
| 108 '--root-dir', os.path.join(work_dir, 'isolated'), | 120 '--root-dir', os.path.join(work_dir, 'isolated'), |
| 109 ]) | 121 ]) |
| 110 if min_free_space: | 122 if min_free_space: |
| 111 cmd.extend(('--min-free-space', str(min_free_space))) | 123 cmd.extend(('--min-free-space', str(min_free_space))) |
| 112 | 124 |
| 113 if task_details.hard_timeout: | 125 if task_details.hard_timeout: |
| 114 cmd.extend(('--hard-timeout', str(task_details.hard_timeout))) | 126 cmd.extend(('--hard-timeout', str(task_details.hard_timeout))) |
| 115 if task_details.grace_period: | 127 if task_details.grace_period: |
| 116 cmd.extend(('--grace-period', str(task_details.grace_period))) | 128 cmd.extend(('--grace-period', str(task_details.grace_period))) |
| 117 | 129 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 133 # Get all the data first so it fails early if the task details is invalid. | 145 # Get all the data first so it fails early if the task details is invalid. |
| 134 self.bot_id = data['bot_id'] | 146 self.bot_id = data['bot_id'] |
| 135 | 147 |
| 136 # Raw command. Only self.command or self.isolated.input can be set. | 148 # Raw command. Only self.command or self.isolated.input can be set. |
| 137 self.command = data['command'] or [] | 149 self.command = data['command'] or [] |
| 138 | 150 |
| 139 # Isolated command. Is a serialized version of task_request.FilesRef. | 151 # Isolated command. Is a serialized version of task_request.FilesRef. |
| 140 self.isolated = data['isolated'] | 152 self.isolated = data['isolated'] |
| 141 self.extra_args = data['extra_args'] | 153 self.extra_args = data['extra_args'] |
| 142 | 154 |
| 155 self.cipd_input = data.get('cipd_input') | |
| 156 | |
| 143 self.env = { | 157 self.env = { |
| 144 k.encode('utf-8'): v.encode('utf-8') for k, v in data['env'].iteritems() | 158 k.encode('utf-8'): v.encode('utf-8') for k, v in data['env'].iteritems() |
| 145 } | 159 } |
| 146 self.grace_period = data['grace_period'] | 160 self.grace_period = data['grace_period'] |
| 147 self.hard_timeout = data['hard_timeout'] | 161 self.hard_timeout = data['hard_timeout'] |
| 148 self.io_timeout = data['io_timeout'] | 162 self.io_timeout = data['io_timeout'] |
| 149 self.task_id = data['task_id'] | 163 self.task_id = data['task_id'] |
| 150 | 164 |
| 151 | 165 |
| 152 class MustExit(Exception): | 166 class MustExit(Exception): |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 if run_isolated_result.get('duration') is not None: | 473 if run_isolated_result.get('duration') is not None: |
| 460 # Calculate the real task duration as measured by run_isolated and | 474 # Calculate the real task duration as measured by run_isolated and |
| 461 # calculate the remaining overhead. | 475 # calculate the remaining overhead. |
| 462 params['bot_overhead'] = params['duration'] | 476 params['bot_overhead'] = params['duration'] |
| 463 params['duration'] = run_isolated_result['duration'] | 477 params['duration'] = run_isolated_result['duration'] |
| 464 params['bot_overhead'] -= params['duration'] | 478 params['bot_overhead'] -= params['duration'] |
| 465 params['bot_overhead'] -= run_isolated_result.get( | 479 params['bot_overhead'] -= run_isolated_result.get( |
| 466 'download', {}).get('duration', 0) | 480 'download', {}).get('duration', 0) |
| 467 params['bot_overhead'] -= run_isolated_result.get( | 481 params['bot_overhead'] -= run_isolated_result.get( |
| 468 'upload', {}).get('duration', 0) | 482 'upload', {}).get('duration', 0) |
| 483 params['bot_overhead'] -= run_isolated_result.get( | |
| 484 'cipd', {}).get('duration', 0) | |
| 469 if params['bot_overhead'] < 0: | 485 if params['bot_overhead'] < 0: |
| 470 params['bot_overhead'] = 0 | 486 params['bot_overhead'] = 0 |
| 471 isolated_stats = run_isolated_result.get('stats', {}).get('isolated') | 487 isolated_stats = run_isolated_result.get('stats', {}).get('isolated') |
| 472 if isolated_stats: | 488 if isolated_stats: |
| 473 params['isolated_stats'] = isolated_stats | 489 params['isolated_stats'] = isolated_stats |
| 490 cipd_stats = run_isolated_result.get('stats', {}).get('cipd') | |
| 491 if cipd_stats: | |
| 492 params['cipd_stats'] = cipd_stats | |
| 474 except (IOError, OSError, ValueError) as e: | 493 except (IOError, OSError, ValueError) as e: |
| 475 logging.error('Swallowing error: %s', e) | 494 logging.error('Swallowing error: %s', e) |
| 476 if not must_signal_internal_failure: | 495 if not must_signal_internal_failure: |
| 477 must_signal_internal_failure = str(e) | 496 must_signal_internal_failure = str(e) |
| 478 # TODO(maruel): Send the internal failure here instead of sending it through | 497 # TODO(maruel): Send the internal failure here instead of sending it through |
| 479 # bot_main, this causes a race condition. | 498 # bot_main, this causes a race condition. |
| 480 if exit_code is None: | 499 if exit_code is None: |
| 481 exit_code = -1 | 500 exit_code = -1 |
| 482 params['hard_timeout'] = had_hard_timeout | 501 params['hard_timeout'] = had_hard_timeout |
| 483 post_update(swarming_server, params, exit_code, stdout, output_chunk_start) | 502 post_update(swarming_server, params, exit_code, stdout, output_chunk_start) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 if options.start > now: | 540 if options.start > now: |
| 522 options.start = now | 541 options.start = now |
| 523 | 542 |
| 524 try: | 543 try: |
| 525 load_and_run( | 544 load_and_run( |
| 526 options.in_file, options.swarming_server, options.cost_usd_hour, | 545 options.in_file, options.swarming_server, options.cost_usd_hour, |
| 527 options.start, options.out_file, options.min_free_space) | 546 options.start, options.out_file, options.min_free_space) |
| 528 return 0 | 547 return 0 |
| 529 finally: | 548 finally: |
| 530 logging.info('quitting') | 549 logging.info('quitting') |
| OLD | NEW |