def main(): options = common.parse_args(use_isolate_server=True, use_swarming=True) try: common.note( 'Archiving directory \'payload\' to %s' % options.isolate_server) payload_isolated_sha1 = common.capture( [ 'isolateserver.py', 'archive', '--isolate-server', options.isolate_server, 'payload', ]).split()[0] common.note( 'Archiving custom .isolated file to %s' % options.isolate_server) handle, isolated = tempfile.mkstemp( prefix='hello_world', suffix='.isolated') os.close(handle) try: data = { 'algo': 'sha-1', 'command': ['python', 'hello_world.py', 'Custom'], 'includes': [payload_isolated_sha1], 'version': '1.0', } with open(isolated, 'wb') as f: json.dump(data, f, sort_keys=True, separators=(',',':')) isolated_sha1 = common.capture( [ 'isolateserver.py', 'archive', '--isolate-server', options.isolate_server, isolated, ]).split()[0] finally: common.note('Deleting temporary file, it is not necessary anymore.') os.remove(isolated) # Now trigger as usual. You could look at run_exmaple_swarming_involved for # the involved way but use the short way here. task_name = common.unique_task_name() common.note('Running %s on %s' % (isolated_sha1, options.swarming)) common.run( [ 'swarming.py', 'run', '--swarming', options.swarming, '--isolate-server', options.isolate_server, '--dimension', 'os', options.swarming_os, '--task-name', task_name, isolated_sha1, ], options.verbose) return 0 except subprocess.CalledProcessError as e: print e.returncode or 1
def main(): options = common.parse_args(use_isolate_server=True, use_swarming=True) try: tempdir = tempfile.mkdtemp(prefix='hello_world') try: # All the files are put in a temporary directory. This is optional and # simply done so the current directory doesn't have the following files # created: # - hello_world.isolated # - hello_world.isolated.state isolated = os.path.join(tempdir, 'hello_world.isolated') common.note('Archiving to %s' % options.isolate_server) common.run( [ 'isolate.py', 'archive', '--isolate', os.path.join('payload', 'hello_world.isolate'), '--isolated', isolated, '--isolate-server', options.isolate_server, '--config-variable', 'OS', options.isolate_os, ], options.verbose) with open(isolated, 'rb') as f: hashval = hashlib.sha1(f.read()).hexdigest() finally: shutil.rmtree(tempdir) # At this point, the temporary directory is not needed anymore. tempdir = None task_name = common.unique_task_name() common.note('Running on %s' % options.swarming) common.run( [ 'swarming.py', 'trigger', '--swarming', options.swarming, '--isolate-server', options.isolate_server, '--dimension', 'os', options.swarming_os, '--task-name', task_name, hashval, ], options.verbose) common.note('Getting results from %s' % options.swarming) common.run( [ 'swarming.py', 'collect', '--swarming', options.swarming, task_name, ], options.verbose) return 0 except subprocess.CalledProcessError as e: print e.returncode or 1
def main(): options = common.parse_args(use_isolate_server=True, use_swarming=True) task_name = common.unique_task_name() tempdir = tempfile.mkdtemp(prefix='hello_world') try: # All the files are put in a temporary directory. This is optional and # simply done so the current directory doesn't have the following files # created: # - hello_world.isolated # - hello_world.isolated.state isolated = os.path.join(tempdir, 'hello_world.isolated') common.note( 'Creating hello_world.isolated. Note that this doesn\'t archives ' 'anything.') common.run( [ 'isolate.py', 'check', '--isolate', os.path.join('payload', 'hello_world.isolate'), '--isolated', isolated, '--config-variable', 'OS', options.isolate_os, ], options.verbose) common.note( 'Running the job remotely. This:\n' ' - archives to %s\n' ' - runs and collect results via %s' % (options.isolate_server, options.swarming)) common.run( [ 'swarming.py', 'run', '--swarming', options.swarming, '--isolate-server', options.isolate_server, '--dimension', 'os', options.swarming_os, '--task-name', task_name, isolated, ], options.verbose) return 0 except subprocess.CalledProcessError as e: return e.returncode finally: shutil.rmtree(tempdir)