| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Python utility that triggers and waits for tasks to complete on CTFE.""" | 6 """Python utility that triggers and waits for tasks to complete on CTFE.""" |
| 7 | 7 |
| 8 import base64 | 8 import base64 |
| 9 import hashlib | 9 import hashlib |
| 10 import json | 10 import json |
| 11 import optparse | 11 import optparse |
| 12 import requests | 12 import requests |
| 13 import sys | 13 import sys |
| 14 import time | 14 import time |
| 15 | 15 |
| 16 | 16 |
| 17 CTFE_HOST = "http://ct.skia.org" | 17 CTFE_HOST = "https://ct.skia.org" |
| 18 CTFE_QUEUE = CTFE_HOST + '/queue/' | 18 CTFE_QUEUE = CTFE_HOST + '/queue/' |
| 19 CHROMIUM_PERF_TASK_POST_URI = CTFE_HOST + "/_/webhook_add_chromium_perf_task" | 19 CHROMIUM_PERF_TASK_POST_URI = CTFE_HOST + "/_/webhook_add_chromium_perf_task" |
| 20 GET_CHROMIUM_PERF_RUN_STATUS_URI = CTFE_HOST + "/get_chromium_perf_run_status" | 20 GET_CHROMIUM_PERF_RUN_STATUS_URI = CTFE_HOST + "/get_chromium_perf_run_status" |
| 21 CHROMIUM_PERF_RUNS_HISTORY = CTFE_HOST + "/chromium_perf_runs/" | 21 CHROMIUM_PERF_RUNS_HISTORY = CTFE_HOST + "/chromium_perf_runs/" |
| 22 GCE_WEBHOOK_SALT_METADATA_URI = ( | 22 GCE_WEBHOOK_SALT_METADATA_URI = ( |
| 23 "http://metadata/computeMetadata/v1/project/attributes/" | 23 "http://metadata/computeMetadata/v1/project/attributes/" |
| 24 "webhook_request_salt") | 24 "webhook_request_salt") |
| 25 | 25 |
| 26 | 26 |
| 27 POLLING_FREQUENCY_SECS = 60 # 1 minute. | 27 POLLING_FREQUENCY_SECS = 60 # 1 minute. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 | 57 |
| 58 def _GetWebhookSaltFromMetadata(): | 58 def _GetWebhookSaltFromMetadata(): |
| 59 """Gets webhook_request_salt from GCE's metadata server.""" | 59 """Gets webhook_request_salt from GCE's metadata server.""" |
| 60 headers = {"Metadata-Flavor": "Google"} | 60 headers = {"Metadata-Flavor": "Google"} |
| 61 resp = requests.get(GCE_WEBHOOK_SALT_METADATA_URI, headers=headers) | 61 resp = requests.get(GCE_WEBHOOK_SALT_METADATA_URI, headers=headers) |
| 62 if resp.status_code != 200: | 62 if resp.status_code != 200: |
| 63 raise CtTrybotException( | 63 raise CtTrybotException( |
| 64 'Return code from %s was %s' % (GCE_WEBHOOK_SALT_METADATA_URI, | 64 'Return code from %s was %s' % (GCE_WEBHOOK_SALT_METADATA_URI, |
| 65 resp.status_code)) | 65 resp.status_code)) |
| 66 return resp.text | 66 return base64.standard_b64decode(resp.text) |
| 67 | 67 |
| 68 | 68 |
| 69 def _TriggerTask(options): | 69 def _TriggerTask(options): |
| 70 """Triggers the requested task on CTFE and returns the new task's ID.""" | 70 """Triggers the requested task on CTFE and returns the new task's ID.""" |
| 71 task = _CreateTaskJSON(options) | 71 task = _CreateTaskJSON(options) |
| 72 m = hashlib.sha512() | 72 m = hashlib.sha512() |
| 73 m.update(task) | 73 m.update(task) |
| 74 m.update('notverysecret' if options.local else _GetWebhookSaltFromMetadata()) | 74 m.update('notverysecret' if options.local else _GetWebhookSaltFromMetadata()) |
| 75 encoded = base64.standard_b64encode(m.digest()) | 75 encoded = base64.standard_b64encode(m.digest()) |
| 76 | 76 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 '', '--local', default=False, action='store_true', | 164 '', '--local', default=False, action='store_true', |
| 165 help='Uses a dummy metadata salt if this flag is true else it tries to ' | 165 help='Uses a dummy metadata salt if this flag is true else it tries to ' |
| 166 'get the salt from GCE metadata.') | 166 'get the salt from GCE metadata.') |
| 167 options, unused_args = option_parser.parse_args() | 167 options, unused_args = option_parser.parse_args() |
| 168 if (not options.issue or not options.patchset or not options.requester | 168 if (not options.issue or not options.patchset or not options.requester |
| 169 or not options.benchmark): | 169 or not options.benchmark): |
| 170 option_parser.error('Must specify issue, patchset, requester and benchmark') | 170 option_parser.error('Must specify issue, patchset, requester and benchmark') |
| 171 | 171 |
| 172 sys.exit(TriggerAndWait(options)) | 172 sys.exit(TriggerAndWait(options)) |
| 173 | 173 |
| OLD | NEW |