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