Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: tools/lua/trigger_ct_lua

Issue 1214843002: Add script for triggering Cluster Telemetry jobs using local scripts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use the get_skp_repos endpoint to choose an SKP repo Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/lua/ngrams.lua ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3
4 """ Trigger a Cluster Telemetry job with the given Lua script. """
5
6
7 import argparse
8 import base64
9 import getpass
10 import httplib2
11 import json
12 import subprocess
13 import urllib
14
15
16 CT_URL = 'https://skia-tree-status.appspot.com/skia-telemetry/'
17 CT_ADD_LUA_TASK_URL = CT_URL + 'add_lua_task'
18 CT_GET_SKP_REPOS_URL = CT_URL + 'get_skp_repos'
19 CT_PENDING_TASKS_URL = CT_URL + 'pending_tasks'
20 POST_DATA = ('username=%s'
21 '&password=%s'
22 '&description=%s'
23 '&lua_script=%s'
24 '&pagesets_type_and_chromium_build=%s')
25
26
27 def trigger_ct_run(user, password, description, script, skp_repo,
28 aggregator=None):
29 """Trigger a Cluster Telemetry run of the given script."""
30 with open(script) as f:
31 script_contents = urllib.quote(base64.b64encode(f.read()))
32
33 body = POST_DATA % (user, password, description, script_contents, skp_repo)
34
35 if aggregator:
36 with open(aggregator) as f:
37 body += '&lua_aggregator=%s' % urllib.quote(base64.b64encode(f.read()))
38
39 resp, content = httplib2.Http('.cache').request(
40 CT_ADD_LUA_TASK_URL, 'POST', body=body)
41 if resp['status'] != '200':
42 raise Exception(
43 'Failed to trigger Cluster Telemetry job: (%s): %s' % (
44 resp['status'], content))
45
46
47 def parse_args():
48 """Parse command-line flags and obtain any additional information."""
49 parser = argparse.ArgumentParser(
50 description='Trigger a Cluster Telemetry job with the given Lua script.')
51 parser.add_argument('script', help='Lua script to run')
rmistry 2015/06/29 18:44:04 script -> --script ?
borenet 2015/06/29 19:11:53 Done. That changes it to optional, so I added 'req
52 parser.add_argument('--aggregator', help='Aggregator script')
rmistry 2015/06/29 18:44:04 Specify and check that script and aggregator are r
borenet 2015/06/29 19:11:53 Done for --script. --aggregator is intended to be
53 parser.add_argument('--description', help='Description of the job.')
54 parser.add_argument('--email', help='Email address to send results')
rmistry 2015/06/29 18:44:04 Email address to send results. Will use the output
borenet 2015/06/29 19:11:53 Done.
55 parser.add_argument('--password_file',
56 help='File in which the CT password is stored.')
rmistry 2015/06/29 18:44:04 File in which CT password is stored. Script will p
borenet 2015/06/29 19:11:53 Done.
57 parser.add_argument('--skp_repo', default='10k',
58 help='Which set of SKPs to use, eg. "10k", "all"')
rmistry 2015/06/29 18:44:04 all -> All (This is something I have regretted for
borenet 2015/06/29 19:11:53 Done.
59 args = parser.parse_args()
60
61 # If the user provided their email address, use that. Otherwise obtain it
62 # from the Git config.
63 user = args.email
64 if not user:
65 user = subprocess.check_output(['git', 'config', 'user.email']).rstrip()
66
67 # Read the password from the password file, if provided, otherwise prompt.
68 if args.password_file:
69 with open(args.password_file) as f:
70 password = f.read().rstrip()
71 else:
72 password = getpass.getpass(
73 'Enter the skia_status_password '
74 '(on https://valentine.corp.google.com/): ')
75
76 # Find an SKP repo to use.
77 resp, content = httplib2.Http('.cache').request(CT_GET_SKP_REPOS_URL, "GET")
78 if resp['status'] != '200':
79 raise Exception('Failed to obtain SKP repos from %s' % CT_GET_SKP_REPOS_URL)
80 skp_repos = json.loads(content)
81 chosen_skp_repo = skp_repos.get(args.skp_repo)[0]
82 if not chosen_skp_repo:
83 raise Exception('No generated SKPs exist for "%s"' % args.skp_repo)
84 skp_repo = '-'.join((args.skp_repo,
85 chosen_skp_repo[0],
86 chosen_skp_repo[1]))
87
88 return (user, password, args.description, args.script, skp_repo,
89 args.aggregator)
90
91
92 def main():
93 user, password, description, script, skp_repo, aggregator = parse_args()
94 trigger_ct_run(user, password, description, script, skp_repo, aggregator)
95 print ('Successfully triggered Cluster Telemetry job. View the queue at %s' %
96 CT_PENDING_TASKS_URL)
97
98
99 if __name__ == '__main__':
100 main()
OLDNEW
« no previous file with comments | « tools/lua/ngrams.lua ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698