Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Runs hello_world.py, through hello_world.isolate, remotely on a Swarm slave. | 6 """Runs hello_world.py, through hello_world.isolate, remotely on a Swarm slave. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import datetime | 9 import datetime |
| 10 import getpass | 10 import getpass |
| 11 import hashlib | 11 import hashlib |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import shutil | 14 import shutil |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 import tempfile | 17 import tempfile |
| 18 | 18 |
| 19 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 19 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 20 sys.path.insert(0, os.path.dirname(ROOT_DIR)) | |
| 20 | 21 |
| 21 | 22 import swarming |
| 22 # Default servers. | |
| 23 ISOLATE_SERVER = 'https://isolateserver.appspot.com/' | |
|
M-A Ruel
2013/08/18 00:18:19
One less hardcoded string. :)
| |
| 24 SWARM_SERVER = 'https://chromium-swarm.appspot.com/' | |
| 25 | 23 |
| 26 | 24 |
| 27 def run(cmd, verbose): | 25 def run(cmd, verbose): |
| 28 if verbose: | 26 if verbose: |
| 29 cmd = cmd + ['--verbose'] | 27 cmd = cmd + ['--verbose'] |
| 30 print('Running: %s' % ' '.join(cmd)) | 28 print('Running: %s' % ' '.join(cmd)) |
| 31 cmd = [sys.executable, os.path.join(ROOT_DIR, '..', cmd[0])] + cmd[1:] | 29 cmd = [sys.executable, os.path.join(ROOT_DIR, '..', cmd[0])] + cmd[1:] |
| 32 if sys.platform != 'win32': | 30 if sys.platform != 'win32': |
| 33 cmd = ['time', '-p'] + cmd | 31 cmd = ['time', '-p'] + cmd |
| 34 subprocess.check_call(cmd) | 32 subprocess.check_call(cmd) |
| 35 | 33 |
| 36 | 34 |
| 37 def main(): | 35 def simple(isolate_server, swarm_server, prefix, verbose): |
| 38 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | |
| 39 parser.add_option( | |
| 40 '-i', '--isolate-server', | |
| 41 default=ISOLATE_SERVER, | |
| 42 help='Isolate server to use default:%default') | |
| 43 parser.add_option( | |
| 44 '-s', '--swarm-server', | |
| 45 default=SWARM_SERVER, | |
| 46 help='Isolate server to use default:%default') | |
| 47 parser.add_option('-v', '--verbose', action='store_true') | |
| 48 options, args = parser.parse_args() | |
| 49 if args: | |
| 50 parser.error('Unsupported argument %s' % args) | |
| 51 prefix = getpass.getuser() + '-' + datetime.datetime.now().isoformat() + '-' | |
| 52 | |
| 53 try: | 36 try: |
| 54 # All the files are put in a temporary directory. This is optional and | 37 # All the files are put in a temporary directory. This is optional and |
| 55 # simply done so the current directory doesn't have the following files | 38 # simply done so the current directory doesn't have the following files |
| 56 # created: | 39 # created: |
| 57 # - hello_world.isolated | 40 # - hello_world.isolated |
| 58 # - hello_world.isolated.state | 41 # - hello_world.isolated.state |
| 59 tempdir = tempfile.mkdtemp(prefix='hello_world') | 42 tempdir = tempfile.mkdtemp(prefix='hello_world') |
| 60 isolated = os.path.join(tempdir, 'hello_world.isolated') | 43 isolated = os.path.join(tempdir, 'hello_world.isolated') |
| 61 | 44 |
| 45 run( | |
| 46 [ | |
| 47 'isolate.py', | |
| 48 'check', | |
| 49 '--isolate', os.path.join(ROOT_DIR, 'hello_world.isolate'), | |
| 50 '--isolated', isolated, | |
| 51 ], | |
| 52 verbose) | |
| 53 | |
| 54 run( | |
| 55 [ | |
| 56 'swarming.py', | |
| 57 'run', | |
| 58 '--os_image', sys.platform, | |
| 59 '--server', swarm_server, | |
| 60 '--test-name-prefix', prefix, | |
| 61 '--cac', isolate_server, | |
| 62 isolated, | |
| 63 ], | |
| 64 verbose) | |
| 65 return 0 | |
| 66 finally: | |
| 67 shutil.rmtree(tempdir) | |
| 68 | |
| 69 | |
| 70 def involved(isolate_server, swarm_server, prefix, verbose): | |
| 71 """Runs all the steps involved individually, for demonstration purposes.""" | |
| 72 try: | |
| 73 # All the files are put in a temporary directory. This is optional and | |
| 74 # simply done so the current directory doesn't have the following files | |
| 75 # created: | |
| 76 # - hello_world.isolated | |
| 77 # - hello_world.isolated.state | |
| 78 tempdir = tempfile.mkdtemp(prefix='hello_world') | |
| 79 isolated = os.path.join(tempdir, 'hello_world.isolated') | |
| 80 | |
| 62 print('Archiving') | 81 print('Archiving') |
| 63 run( | 82 run( |
| 64 [ | 83 [ |
| 65 'isolate.py', | 84 'isolate.py', |
| 66 'hashtable', | 85 'hashtable', |
| 67 '--isolate', os.path.join(ROOT_DIR, 'hello_world.isolate'), | 86 '--isolate', os.path.join(ROOT_DIR, 'hello_world.isolate'), |
| 68 '--isolated', isolated, | 87 '--isolated', isolated, |
| 69 '--outdir', options.isolate_server, | 88 '--outdir', isolate_server, |
| 70 ], | 89 ], |
| 71 options.verbose) | 90 verbose) |
| 72 | |
| 73 # Note that swarm_trigger_and_get_results.py could be used to run and get | |
| 74 # results as a single call. | |
| 75 print('\nRunning') | |
| 76 hashval = hashlib.sha1(open(isolated, 'rb').read()).hexdigest() | 91 hashval = hashlib.sha1(open(isolated, 'rb').read()).hexdigest() |
| 77 run( | |
| 78 [ | |
| 79 'swarm_trigger_step.py', | |
| 80 '--os_image', sys.platform, | |
| 81 '--swarm-url', options.swarm_server, | |
| 82 '--test-name-prefix', prefix, | |
| 83 '--data-server', options.isolate_server, | |
| 84 '--run_from_hash', hashval, | |
| 85 'hello_world', | |
| 86 # Number of shards. | |
| 87 '1', | |
| 88 '*', | |
| 89 ], | |
| 90 options.verbose) | |
| 91 | |
| 92 print('\nGetting results') | |
| 93 run( | |
| 94 [ | |
| 95 'swarm_get_results.py', | |
| 96 '--url', options.swarm_server, | |
| 97 prefix + 'hello_world', | |
| 98 ], | |
| 99 options.verbose) | |
| 100 finally: | 92 finally: |
| 101 shutil.rmtree(tempdir) | 93 shutil.rmtree(tempdir) |
| 94 | |
| 95 print('\nRunning') | |
| 96 run( | |
| 97 [ | |
| 98 'swarming.py', | |
| 99 'trigger', | |
| 100 '--os_image', sys.platform, | |
| 101 '--server', swarm_server, | |
| 102 '--test-name-prefix', prefix, | |
| 103 '--cac', isolate_server, | |
| 104 '--task', | |
| 105 hashval, | |
| 106 'hello_world', | |
| 107 # Number of shards. | |
| 108 '1', | |
| 109 '*', | |
| 110 ], | |
| 111 verbose) | |
| 112 | |
| 113 print('\nGetting results') | |
| 114 run( | |
| 115 [ | |
| 116 'swarming.py', | |
| 117 'collect', | |
| 118 '--server', swarm_server, | |
| 119 prefix + 'hello_world', | |
| 120 ], | |
| 121 verbose) | |
| 102 return 0 | 122 return 0 |
| 103 | 123 |
| 104 | 124 |
| 125 def main(): | |
| 126 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | |
| 127 parser.add_option( | |
| 128 '-i', '--isolate-server', | |
| 129 default=swarming.ISOLATE_SERVER, | |
| 130 help='Isolate server to use default: %default') | |
| 131 parser.add_option( | |
| 132 '-s', '--swarm-server', | |
| 133 default=swarming.SWARM_SERVER, | |
| 134 help='Isolate server to use default: %default') | |
| 135 parser.add_option('-v', '--verbose', action='store_true') | |
| 136 parser.add_option( | |
| 137 '-S', '--short', action='store_true', | |
| 138 help='Use \'swarming.py run\' instead of running each step manually') | |
| 139 options, args = parser.parse_args() | |
| 140 if args: | |
| 141 parser.error('Unsupported argument %s' % args) | |
| 142 | |
| 143 prefix = getpass.getuser() + '-' + datetime.datetime.now().isoformat() + '-' | |
| 144 if options.short: | |
| 145 return simple( | |
| 146 options.isolate_server, options.swarm_server, prefix, options.verbose) | |
| 147 else: | |
| 148 return involved( | |
| 149 options.isolate_server, options.swarm_server, prefix, options.verbose) | |
| 150 | |
| 151 | |
| 105 if __name__ == '__main__': | 152 if __name__ == '__main__': |
| 106 sys.exit(main()) | 153 sys.exit(main()) |
| OLD | NEW |