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

Side by Side Diff: build/android/pylib/results/presentation/test_results_presentation.py

Issue 2777353002: Upload the test results html file to google bucket. (Closed)
Patch Set: fix url Created 3 years, 8 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 | « build/android/pylib/results/presentation/template/main.html ('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
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 # 2 #
3 # Copyright 2017 The Chromium Authors. All rights reserved. 3 # Copyright 2017 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import argparse 7 import argparse
8 import collections 8 import collections
9 import json 9 import json
10 import tempfile
11 import time
10 import os 12 import os
13 import subprocess
11 import sys 14 import sys
12 15
13 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) 16 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
14 BASE_DIR = os.path.abspath(os.path.join( 17 BASE_DIR = os.path.abspath(os.path.join(
15 CURRENT_DIR, '..', '..', '..', '..', '..')) 18 CURRENT_DIR, '..', '..', '..', '..', '..'))
16 sys.path.append(os.path.join(BASE_DIR, 'third_party')) 19 sys.path.append(os.path.join(BASE_DIR, 'third_party'))
17 import jinja2 # pylint: disable=import-error 20 import jinja2 # pylint: disable=import-error
18 JINJA_ENVIRONMENT = jinja2.Environment( 21 JINJA_ENVIRONMENT = jinja2.Environment(
19 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), 22 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
20 autoescape=True) 23 autoescape=True)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if footer_row[FAIL_COUNT_INDEX]['data'] > 0: 228 if footer_row[FAIL_COUNT_INDEX]['data'] > 0:
226 footer_row[FAIL_COUNT_INDEX]['class'] += ' failure' 229 footer_row[FAIL_COUNT_INDEX]['class'] += ' failure'
227 else: 230 else:
228 footer_row[FAIL_COUNT_INDEX]['class'] += ' success' 231 footer_row[FAIL_COUNT_INDEX]['class'] += ' success'
229 232
230 return (header_row, 233 return (header_row,
231 [[suite_row] for suite_row in suite_row_dict.values()], 234 [[suite_row] for suite_row in suite_row_dict.values()],
232 footer_row) 235 footer_row)
233 236
234 237
235 def results_to_html(results_dict, cs_base_url, master_name): 238 def results_to_html(results_dict, cs_base_url, bucket, server_url):
236 """Convert list of test results into html format.""" 239 """Convert list of test results into html format."""
237 240
238 test_rows_header, test_rows = create_test_table(results_dict, cs_base_url) 241 test_rows_header, test_rows = create_test_table(results_dict, cs_base_url)
239 suite_rows_header, suite_rows, suite_row_footer = create_suite_table( 242 suite_rows_header, suite_rows, suite_row_footer = create_suite_table(
240 results_dict) 243 results_dict)
241 244
242 suite_table_values = { 245 suite_table_values = {
243 'table_id': 'suite-table', 246 'table_id': 'suite-table',
244 'table_headers': suite_rows_header, 247 'table_headers': suite_rows_header,
245 'table_row_blocks': suite_rows, 248 'table_row_blocks': suite_rows,
246 'table_footer': suite_row_footer, 249 'table_footer': suite_row_footer,
247 } 250 }
248 251
249 test_table_values = { 252 test_table_values = {
250 'table_id': 'test-table', 253 'table_id': 'test-table',
251 'table_headers': test_rows_header, 254 'table_headers': test_rows_header,
252 'table_row_blocks': test_rows, 255 'table_row_blocks': test_rows,
253 } 256 }
254 257
255 main_template = JINJA_ENVIRONMENT.get_template( 258 main_template = JINJA_ENVIRONMENT.get_template(
256 os.path.join('template', 'main.html')) 259 os.path.join('template', 'main.html'))
257 return main_template.render( # pylint: disable=no-member 260 return main_template.render( # pylint: disable=no-member
258 {'tb_values': [suite_table_values, test_table_values], 261 {'tb_values': [suite_table_values, test_table_values],
259 'master_name': master_name}) 262 'bucket': bucket, 'server_url': server_url})
260 263
261 264
262 def result_details(json_path, cs_base_url, master_name): 265 def result_details(json_path, cs_base_url, bucket, server_url):
263 """Get result details from json path and then convert results to html.""" 266 """Get result details from json path and then convert results to html."""
264 267
265 with open(json_path) as json_file: 268 with open(json_path) as json_file:
266 json_object = json.loads(json_file.read()) 269 json_object = json.loads(json_file.read())
267 270
268 if not 'per_iteration_data' in json_object: 271 if not 'per_iteration_data' in json_object:
269 return 'Error: json file missing per_iteration_data.' 272 return 'Error: json file missing per_iteration_data.'
270 273
271 results_dict = collections.defaultdict(list) 274 results_dict = collections.defaultdict(list)
272 for testsuite_run in json_object['per_iteration_data']: 275 for testsuite_run in json_object['per_iteration_data']:
273 for test, test_runs in testsuite_run.iteritems(): 276 for test, test_runs in testsuite_run.iteritems():
274 results_dict[test].extend(test_runs) 277 results_dict[test].extend(test_runs)
275 return results_to_html(results_dict, cs_base_url, master_name) 278 return results_to_html(results_dict, cs_base_url, bucket, server_url)
276 279
277 280
281 def upload_to_google_bucket(html, test_name, builder_name, build_number,
282 bucket, server_url, content_type):
283 with tempfile.NamedTemporaryFile(suffix='.html') as temp_file:
284 temp_file.write(html)
285 temp_file.flush()
286 dest = 'html/%s_%s_%s_%s.html' % (
287 test_name, builder_name, build_number,
288 time.strftime('%Y_%m_%d_T%H_%M_%S'))
289 gsutil_path = os.path.join(BASE_DIR, 'third_party', 'catapult',
290 'third_party', 'gsutil', 'gsutil.py')
291 subprocess.check_call([
292 sys.executable, gsutil_path, '-h', "Content-Type:%s" % content_type,
293 'cp', temp_file.name, 'gs://%s/%s' % (bucket, dest)])
294
295 return '%s/%s/%s' % (server_url, bucket, dest)
296
278 def main(): 297 def main():
279 parser = argparse.ArgumentParser() 298 parser = argparse.ArgumentParser()
280 parser.add_argument('--json-file', help='Path of json file.', required=True) 299 parser.add_argument('--json-file', help='Path of json file.', required=True)
281 parser.add_argument('--cs-base-url', help='Base url for code search.', 300 parser.add_argument('--cs-base-url', help='Base url for code search.',
282 default='http://cs.chromium.org') 301 default='http://cs.chromium.org')
283 parser.add_argument('--master-name', help='Master name in urls.') 302 parser.add_argument('--bucket', default='chromium-result-details')
303 parser.add_argument('--builder-name', help='Builder name.', required=True)
304 parser.add_argument('--build-number', help='Build number.', required=True)
305 parser.add_argument('--test-name', help='The name of the test.',
306 required=True)
307 parser.add_argument('--server-url', help='The url of the server.',
308 default='https://storage.googleapis.com')
309 parser.add_argument(
310 '--content-type',
311 help=('Content type, which is used to determine '
312 'whether to download the file, or view in browser.'),
313 default='text/html',
314 choices=['text/html', 'application/octet-stream'])
284 315
285 args = parser.parse_args() 316 args = parser.parse_args()
286 if os.path.exists(args.json_file): 317 if os.path.exists(args.json_file):
287 result_html_string = result_details(args.json_file, args.cs_base_url, 318 result_html_string = result_details(args.json_file, args.cs_base_url,
288 args.master_name) 319 args.bucket, args.server_url)
289 print result_html_string.encode('UTF-8') 320 print upload_to_google_bucket(result_html_string.encode('UTF-8'),
321 args.test_name, args.builder_name,
322 args.build_number, args.bucket,
323 args.server_url, args.content_type)
290 else: 324 else:
291 raise IOError('--json-file %s not found.' % args.json_file) 325 raise IOError('--json-file %s not found.' % args.json_file)
292 326
293 327
294 if __name__ == '__main__': 328 if __name__ == '__main__':
295 sys.exit(main()) 329 sys.exit(main())
OLDNEW
« 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