forked from luci/luci-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_swarming_run.py
executable file
·66 lines (57 loc) · 2 KB
/
2_swarming_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# Copyright 2012 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
"""Runs hello_world.py, through hello_world.isolate, remotely on a Swarming
bot.
It first 'compiles' hello_world.isolate into hello_word.isolated, then requests
via swarming.py to archives, run and collect results for this task.
It generates example_result.json as a task summary.
"""
import shutil
import subprocess
import sys
import tempfile
# Pylint can't find common.py that's in the same directory as this file.
# pylint: disable=F0401
import common
def main():
options = common.parse_args(use_isolate_server=True, use_swarming=True)
tempdir = tempfile.mkdtemp(prefix=u'hello_world')
try:
isolated_hash = common.isolate(
tempdir, options.isolate_server, options.swarming_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))
cmd = [
'swarming.py',
'run',
'--swarming', options.swarming,
'--isolate-server', options.isolate_server,
'--dimension', 'os', options.swarming_os,
'--dimension', 'pool', 'default',
'--task-name', options.task_name,
'--task-summary-json', 'example_result.json',
'--decorate',
'--isolated', isolated_hash,
]
if options.idempotent:
cmd.append('--idempotent')
if options.priority is not None:
cmd.extend(('--priority', str(options.priority)))
if options.service_account:
cmd.extend(('--service-account', options.service_account))
common.run(cmd, options.verbose)
with open('example_result.json', 'rb') as f:
print('example_result.json content:')
print(f.read())
return 0
except subprocess.CalledProcessError as e:
return e.returncode
finally:
shutil.rmtree(tempdir)
if __name__ == '__main__':
sys.exit(main())