| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2012 The Swarming Authors. All rights reserved. | |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 that | |
| 4 # can be found in the LICENSE file. | |
| 5 | |
| 6 """Runs hello_world.py, through hello_world.isolate, remotely on a Swarming | |
| 7 slave. | |
| 8 | |
| 9 It first 'compiles' hello_world.isolate into hello_word.isolated, then requests | |
| 10 via swarming.py to archives, run and collect results for this task. | |
| 11 """ | |
| 12 | |
| 13 import os | |
| 14 import shutil | |
| 15 import subprocess | |
| 16 import sys | |
| 17 import tempfile | |
| 18 | |
| 19 # Pylint can't find common.py that's in the same directory as this file. | |
| 20 # pylint: disable=F0401 | |
| 21 import common | |
| 22 | |
| 23 | |
| 24 def main(): | |
| 25 options = common.parse_args(use_isolate_server=True, use_swarming=True) | |
| 26 tempdir = tempfile.mkdtemp(prefix=u'hello_world') | |
| 27 try: | |
| 28 # All the files are put in a temporary directory. This is optional and | |
| 29 # simply done so the current directory doesn't have the following files | |
| 30 # created: | |
| 31 # - hello_world.isolated | |
| 32 # - hello_world.isolated.state | |
| 33 isolated = os.path.join(tempdir, 'hello_world.isolated') | |
| 34 | |
| 35 common.note( | |
| 36 'Creating hello_world.isolated. Note that this doesn\'t archives ' | |
| 37 'anything.') | |
| 38 common.run( | |
| 39 [ | |
| 40 'isolate.py', | |
| 41 'check', | |
| 42 '--isolate', os.path.join('payload', 'hello_world.isolate'), | |
| 43 '--isolated', isolated, | |
| 44 '--config-variable', 'OS', options.swarming_os, | |
| 45 ], options.verbose) | |
| 46 | |
| 47 common.note( | |
| 48 'Running the job remotely. This:\n' | |
| 49 ' - archives to %s\n' | |
| 50 ' - runs and collect results via %s' % | |
| 51 (options.isolate_server, options.swarming)) | |
| 52 cmd = [ | |
| 53 'swarming.py', | |
| 54 'run', | |
| 55 '--swarming', options.swarming, | |
| 56 '--isolate-server', options.isolate_server, | |
| 57 '--dimension', 'os', options.swarming_os, | |
| 58 '--task-name', options.task_name, | |
| 59 isolated, | |
| 60 ] | |
| 61 if options.idempotent: | |
| 62 cmd.append('--idempotent') | |
| 63 if options.priority is not None: | |
| 64 cmd.extend(('--priority', str(options.priority))) | |
| 65 common.run(cmd, options.verbose) | |
| 66 return 0 | |
| 67 except subprocess.CalledProcessError as e: | |
| 68 return e.returncode | |
| 69 finally: | |
| 70 shutil.rmtree(tempdir) | |
| 71 | |
| 72 | |
| 73 if __name__ == '__main__': | |
| 74 sys.exit(main()) | |
| OLD | NEW |