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

Unified Diff: build/android/pylib/results/presentation/test_results_presentation.py

Issue 2777353002: Upload the test results html file to google bucket. (Closed)
Patch Set: addressing case's comments Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/results/presentation/template/main.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/results/presentation/test_results_presentation.py
diff --git a/build/android/pylib/results/presentation/test_results_presentation.py b/build/android/pylib/results/presentation/test_results_presentation.py
index e8a49086f75ec182ac4b3ed73d8daa3dd01ef076..22ae575e667574b49e95a649dccbc82781b0e414 100755
--- a/build/android/pylib/results/presentation/test_results_presentation.py
+++ b/build/android/pylib/results/presentation/test_results_presentation.py
@@ -7,7 +7,10 @@
import argparse
import collections
import json
+import tempfile
+import time
import os
+import subprocess
import sys
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -232,7 +235,7 @@ def create_suite_table(results_dict):
footer_row)
-def results_to_html(results_dict, cs_base_url, master_name):
+def results_to_html(results_dict, cs_base_url, bucket):
"""Convert list of test results into html format."""
test_rows_header, test_rows = create_test_table(results_dict, cs_base_url)
@@ -256,10 +259,10 @@ def results_to_html(results_dict, cs_base_url, master_name):
os.path.join('template', 'main.html'))
return main_template.render( # pylint: disable=no-member
{'tb_values': [suite_table_values, test_table_values],
- 'master_name': master_name})
+ 'bucket': bucket})
-def result_details(json_path, cs_base_url, master_name):
+def result_details(json_path, cs_base_url, bucket):
"""Get result details from json path and then convert results to html."""
with open(json_path) as json_file:
@@ -272,21 +275,52 @@ def result_details(json_path, cs_base_url, master_name):
for testsuite_run in json_object['per_iteration_data']:
for test, test_runs in testsuite_run.iteritems():
results_dict[test].extend(test_runs)
- return results_to_html(results_dict, cs_base_url, master_name)
-
+ return results_to_html(results_dict, cs_base_url, bucket)
+
+
+def upload_to_google_bucket(html, test_name, builder_name, build_number,
+ bucket, server_url, content_type):
+ with tempfile.NamedTemporaryFile(suffix='.html') as temp_file:
+ temp_file.write(html)
+ temp_file.flush()
+ dest = 'html/%s_%s_%s_%s.html' % (
+ test_name, builder_name, build_number,
+ time.strftime('%Y_%m_%d_T%H_%M_%S'))
+ gsutil_path = os.path.join(BASE_DIR, 'third_party', 'catapult',
+ 'third_party', 'gsutil', 'gsutil.py')
+ subprocess.check_call(
+ 'python %s -h "Content-Type:%s" cp %s gs://%s/%s' % (
jbudorick 2017/03/29 23:26:06 nit: pass a list and use sys.executable instead of
BigBossZhiling 2017/03/29 23:55:22 Done.
+ gsutil_path, content_type, temp_file.name, bucket, dest),
+ shell=True)
+
+ return '%s/%s/%s' % (server_url, bucket, dest)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--json-file', help='Path of json file.', required=True)
parser.add_argument('--cs-base-url', help='Base url for code search.',
default='http://cs.chromium.org')
- parser.add_argument('--master-name', help='Master name in urls.')
+ parser.add_argument('--bucket', default='chromium-result-details')
+ parser.add_argument('--builder-name', help='Builder name.', required=True)
+ parser.add_argument('--build-number', help='Build number.', required=True)
+ parser.add_argument('--test-name', help='The name of the test.',
+ required=True)
+ parser.add_argument('--server-url', help='The url of the server.',
+ default='https://storage.googleapis.com')
+ parser.add_argument(
jbudorick 2017/03/29 23:26:06 What is this for downloadable pages? I imagine we
BigBossZhiling 2017/03/29 23:55:22 Done.
+ '--content-type',
+ help=('Content type, which is used to determine '
+ 'whether to download the file, or view in browser.'),
+ default='text/html')
args = parser.parse_args()
if os.path.exists(args.json_file):
result_html_string = result_details(args.json_file, args.cs_base_url,
- args.master_name)
- print result_html_string.encode('UTF-8')
+ args.bucket)
+ print upload_to_google_bucket(result_html_string.encode('UTF-8'),
+ args.test_name, args.builder_name,
+ args.build_number, args.bucket,
+ args.server_url, args.content_type)
else:
raise IOError('--json-file %s not found.' % args.json_file)
« no previous file with comments | « build/android/pylib/results/presentation/template/main.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698