| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Archives a .isolated file, triggers it on Swarm and get the results.""" | |
| 7 | |
| 8 import datetime | |
| 9 import getpass | |
| 10 import hashlib | |
| 11 import optparse | |
| 12 import os | |
| 13 import shutil | |
| 14 import subprocess | |
| 15 import sys | |
| 16 import tempfile | |
| 17 | |
| 18 import run_isolated | |
| 19 | |
| 20 | |
| 21 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 22 | |
| 23 | |
| 24 # Default servers. | |
| 25 ISOLATE_SERVER = 'https://isolateserver-dev.appspot.com/' | |
| 26 SWARM_SERVER = 'https://chromium-swarm-dev.appspot.com' | |
| 27 | |
| 28 | |
| 29 def run(cmd, verbose): | |
| 30 if verbose: | |
| 31 print('Running: %s' % ' '.join(cmd)) | |
| 32 cmd = [sys.executable, os.path.join(ROOT_DIR, cmd[0])] + cmd[1:] | |
| 33 if verbose and sys.platform != 'win32': | |
| 34 cmd = ['time', '-p'] + cmd | |
| 35 subprocess.check_call(cmd) | |
| 36 | |
| 37 | |
| 38 def doall(isolate, isolated, swarm_server, cad_server, slave_os, verbose): | |
| 39 """Does the archive, trigger and get results dance.""" | |
| 40 prefix = getpass.getuser() + '-' + datetime.datetime.now().isoformat() + '-' | |
| 41 shards = 1 | |
| 42 | |
| 43 if verbose: | |
| 44 os.environ.setdefault('ISOLATE_DEBUG', '2') | |
| 45 | |
| 46 tempdir = None | |
| 47 try: | |
| 48 if not isolated: | |
| 49 # A directory is used because isolated + '.state' will also be created. | |
| 50 tempdir = tempfile.mkdtemp(prefix='swarm_trigger_and_get_results') | |
| 51 isolated = os.path.join(tempdir, 'swarm_trigger.isolated') | |
| 52 step_name = os.path.basename(isolate).split('.', 1)[0] | |
| 53 else: | |
| 54 step_name = os.path.basename(isolated).split('.', 1)[0] | |
| 55 | |
| 56 print('Archiving') | |
| 57 cmd = [ | |
| 58 'isolate.py', | |
| 59 'hashtable', | |
| 60 '--outdir', cad_server, | |
| 61 '--isolated', isolated, | |
| 62 ] | |
| 63 if isolate: | |
| 64 cmd.extend(('--isolate', isolate)) | |
| 65 if slave_os: | |
| 66 cmd.extend(('-V', 'OS', run_isolated.FLAVOR_MAPPING[slave_os])) | |
| 67 run(cmd, verbose) | |
| 68 | |
| 69 print('\nRunning') | |
| 70 hashval = hashlib.sha1(open(isolated, 'rb').read()).hexdigest() | |
| 71 cmd = [ | |
| 72 'swarm_trigger_step.py', | |
| 73 '--swarm-url', swarm_server, | |
| 74 '--test-name-prefix', prefix, | |
| 75 '--data-server', cad_server, | |
| 76 '--run_from_hash', | |
| 77 hashval, | |
| 78 step_name, | |
| 79 str(shards), | |
| 80 '', | |
| 81 ] | |
| 82 if slave_os: | |
| 83 cmd.extend(('--os_image', slave_os)) | |
| 84 run(cmd, verbose) | |
| 85 | |
| 86 print('\nGetting results') | |
| 87 run( | |
| 88 [ | |
| 89 'swarm_get_results.py', | |
| 90 '--url', swarm_server, | |
| 91 prefix + step_name, | |
| 92 ], | |
| 93 verbose) | |
| 94 return 0 | |
| 95 finally: | |
| 96 if tempdir: | |
| 97 shutil.rmtree(tempdir) | |
| 98 | |
| 99 | |
| 100 def main(): | |
| 101 run_isolated.disable_buffering() | |
| 102 parser = optparse.OptionParser( | |
| 103 usage='%prog <options>', | |
| 104 description=sys.modules[__name__].__doc__) | |
| 105 parser.add_option('-i', '--isolate', help='.isolate file to use') | |
| 106 parser.add_option( | |
| 107 '-s', '--isolated', | |
| 108 help='.isolated file to use. One of -i or -s must be used.') | |
| 109 parser.add_option( | |
| 110 '-o', '--os_image', | |
| 111 metavar='OS', | |
| 112 help='Swarm OS image to request. Should be one of the valid sys.platform ' | |
| 113 'values like darwin, linux2 or win32.') | |
| 114 parser.add_option( | |
| 115 '-u', '--swarm-url', | |
| 116 metavar='URL', | |
| 117 default=SWARM_SERVER, | |
| 118 help='Specify the url of the Swarm server. Defaults to %default') | |
| 119 parser.add_option( | |
| 120 '-d', '--data-server', | |
| 121 default=ISOLATE_SERVER, | |
| 122 metavar='URL', | |
| 123 help='The server where all the test data is stored. Defaults to %default') | |
| 124 parser.add_option('-v', '--verbose', action='store_true') | |
| 125 options, args = parser.parse_args() | |
| 126 | |
| 127 if args: | |
| 128 parser.error('Use one of -i or -s but no unsupported arguments: %s' % args) | |
| 129 if not options.isolate and not options.isolated: | |
| 130 parser.error('Use one of -i or -s') | |
| 131 | |
| 132 return doall( | |
| 133 options.isolate, | |
| 134 options.isolated, | |
| 135 options.swarm_url, | |
| 136 options.data_server, | |
| 137 options.os_image, | |
| 138 options.verbose) | |
| 139 | |
| 140 | |
| 141 if __name__ == '__main__': | |
| 142 sys.exit(main()) | |
| OLD | NEW |