aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua
diff options
context:
space:
mode:
authorGravatar borenet <borenet@google.com>2015-06-29 12:54:25 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-29 12:54:25 -0700
commit8cd8f9429a8a7d5c09c48f7cc9ab34073e01d945 (patch)
tree3bdf31dee7c73c3ab292b9a3ca01df2876094e5e /tools/lua
parent823b2a76e24bcac23e984dff025a7d53fc4aa584 (diff)
Add script for triggering Cluster Telemetry jobs using local scripts
Diffstat (limited to 'tools/lua')
-rw-r--r--tools/lua/ngrams.lua3
-rwxr-xr-xtools/lua/trigger_ct_lua103
2 files changed, 105 insertions, 1 deletions
diff --git a/tools/lua/ngrams.lua b/tools/lua/ngrams.lua
index c94ffb3b38..ddbbc9b2db 100644
--- a/tools/lua/ngrams.lua
+++ b/tools/lua/ngrams.lua
@@ -2,7 +2,8 @@
-- To test this locally, run:
-- $ GYP_DEFINES="skia_shared_lib=1" make lua_pictures
--- $ out/Debug/lua_pictures -q -r $SKP_DIR -l tools/lua/ngrams.lua > /tmp/lua-output && lua tools/lua/ngrams_aggregate.lua
+-- $ out/Debug/lua_pictures -q -r $SKP_DIR -l tools/lua/ngrams.lua > /tmp/lua-output
+-- $ lua tools/lua/ngrams_aggregate.lua
-- To run on Cluster Telemetry, copy and paste the contents of this file into
-- the box at https://skia-tree-status.appspot.com/skia-telemetry/lua_script,
diff --git a/tools/lua/trigger_ct_lua b/tools/lua/trigger_ct_lua
new file mode 100755
index 0000000000..78915548ae
--- /dev/null
+++ b/tools/lua/trigger_ct_lua
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+
+
+""" Trigger a Cluster Telemetry job with the given Lua script. """
+
+
+import argparse
+import base64
+import getpass
+import httplib2
+import json
+import subprocess
+import urllib
+
+
+CT_URL = 'https://skia-tree-status.appspot.com/skia-telemetry/'
+CT_ADD_LUA_TASK_URL = CT_URL + 'add_lua_task'
+CT_GET_SKP_REPOS_URL = CT_URL + 'get_skp_repos'
+CT_PENDING_TASKS_URL = CT_URL + 'pending_tasks'
+POST_DATA = ('username=%s'
+ '&password=%s'
+ '&description=%s'
+ '&lua_script=%s'
+ '&pagesets_type_and_chromium_build=%s')
+
+
+def trigger_ct_run(user, password, description, script, skp_repo,
+ aggregator=None):
+ """Trigger a Cluster Telemetry run of the given script."""
+ with open(script) as f:
+ script_contents = urllib.quote(base64.b64encode(f.read()))
+
+ body = POST_DATA % (user, password, description, script_contents, skp_repo)
+
+ if aggregator:
+ with open(aggregator) as f:
+ body += '&lua_aggregator=%s' % urllib.quote(base64.b64encode(f.read()))
+
+ resp, content = httplib2.Http().request(
+ CT_ADD_LUA_TASK_URL, 'POST', body=body)
+ if resp['status'] != '200':
+ raise Exception(
+ 'Failed to trigger Cluster Telemetry job: (%s): %s' % (
+ resp['status'], content))
+
+
+def parse_args():
+ """Parse command-line flags and obtain any additional information."""
+ parser = argparse.ArgumentParser(
+ description='Trigger a Cluster Telemetry job with the given Lua script.')
+ parser.add_argument('--script', help='Lua script to run', required=True)
+ parser.add_argument('--aggregator', help='Aggregator script')
+ parser.add_argument('--description', help='Description of the job.')
+ parser.add_argument('--email',
+ help=('Email address to send results. If not specified, '
+ 'the value of `git config user.email` is used.'))
+ parser.add_argument('--password_file',
+ help=('File in which the CT password is stored. Will '
+ 'prompt for password if not specified.'))
+ parser.add_argument('--skp_repo', default='10k',
+ help='Which set of SKPs to use, eg. "10k", "All"')
+ args = parser.parse_args()
+
+ # If the user provided their email address, use that. Otherwise obtain it
+ # from the Git config.
+ user = args.email
+ if not user:
+ user = subprocess.check_output(['git', 'config', 'user.email']).rstrip()
+
+ # Read the password from the password file, if provided, otherwise prompt.
+ if args.password_file:
+ with open(args.password_file) as f:
+ password = f.read().rstrip()
+ else:
+ password = getpass.getpass(
+ 'Enter the skia_status_password '
+ '(on https://valentine.corp.google.com/): ')
+
+ # Find an SKP repo to use.
+ resp, content = httplib2.Http().request(CT_GET_SKP_REPOS_URL, "GET")
+ if resp['status'] != '200':
+ raise Exception('Failed to obtain SKP repos from %s' % CT_GET_SKP_REPOS_URL)
+ skp_repos = json.loads(content)
+ chosen_skp_repo = skp_repos.get(args.skp_repo)[0]
+ if not chosen_skp_repo:
+ raise Exception('No generated SKPs exist for "%s"' % args.skp_repo)
+ skp_repo = '-'.join((args.skp_repo,
+ chosen_skp_repo[0],
+ chosen_skp_repo[1]))
+
+ return (user, password, args.description, args.script, skp_repo,
+ args.aggregator)
+
+
+def main():
+ user, password, description, script, skp_repo, aggregator = parse_args()
+ trigger_ct_run(user, password, description, script, skp_repo, aggregator)
+ print ('Successfully triggered Cluster Telemetry job. View the queue at %s' %
+ CT_PENDING_TASKS_URL)
+
+
+if __name__ == '__main__':
+ main()