blob: 4f459548f2501c98027d878447ad7f456399f214 [file] [log] [blame]
Marc-Antoine Ruel35448c42017-12-01 17:34:27 -05001#!/usr/bin/env python
2# coding: utf-8
3# Copyright 2012 The LUCI Authors. All rights reserved.
4# Use of this source code is governed under the Apache License, Version 2.0
5# that can be found in the LICENSE file.
6
7"""Runs hello_world.py, through hello_world.isolate, remotely on a Swarming
8slave.
9
10It compiles and archives via 'isolate.py archive', then discard the local files.
11After, it triggers and finally collects the results.
12"""
13
14import os
15import shutil
16import subprocess
17import sys
18import tempfile
19
20# Pylint can't find common.py that's in the same directory as this file.
21# pylint: disable=F0401
22import common
23
24
25def main():
26 args = common.parse_args(use_isolate_server=True, use_swarming=True)
27 try:
28 tempdir = tempfile.mkdtemp(prefix=u'hello_world')
29 try:
30 isolated_hash = common.archive(
31 tempdir, args.isolate_server, args.verbose, args.which)
32
33 json_file = os.path.join(tempdir, 'task.json').encode('utf-8')
34 common.note('Running on %s' % args.swarming)
35 cmd = [
36 'swarming.py',
37 'trigger',
38 '--swarming', args.swarming,
39 '--isolate-server', args.isolate_server,
40 '--task-name', args.task_name,
41 '--dump-json', json_file,
42 '--isolated', isolated_hash,
43 '--raw-cmd',
44 ]
45 for k, v in args.dimensions:
46 cmd.extend(('--dimension', k, v))
47 if args.idempotent:
48 cmd.append('--idempotent')
49 if args.priority is not None:
50 cmd.extend(('--priority', str(args.priority)))
51 if args.service_account:
52 cmd.extend(('--service-account', args.service_account))
53
54 cmd.extend(('--', args.which + u'.py', 'Dear 💩', '${ISOLATED_OUTDIR}'))
55 common.run(cmd, args.verbose)
56
57 common.note('Getting results from %s' % args.swarming)
58 resdir = os.path.join(tempdir, 'results').encode('utf-8')
59 common.run(
60 [
61 'swarming.py',
62 'collect',
63 '--swarming', args.swarming,
64 '--json', json_file,
65 '--task-output-dir', resdir,
66 ], args.verbose)
67 for root, _, files in os.walk(resdir):
68 for name in files:
69 p = os.path.join(root, name)
70 with open(p, 'rb') as f:
71 print('%s content:' % p)
72 print(f.read())
73 return 0
74 finally:
75 shutil.rmtree(tempdir)
76 except subprocess.CalledProcessError as e:
77 return e.returncode
78
79
80if __name__ == '__main__':
81 sys.exit(main())