| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # | 5 # |
| 6 # Most of this file was ported over from Blink's | 6 # Most of this file was ported over from Blink's |
| 7 # Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py | 7 # Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py |
| 8 # Tools/Scripts/webkitpy/common/net/file_uploader.py | 8 # Tools/Scripts/webkitpy/common/net/file_uploader.py |
| 9 # | 9 # |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 return result | 56 return result |
| 57 | 57 |
| 58 | 58 |
| 59 def AddPathToTrie(path, value, trie): | 59 def AddPathToTrie(path, value, trie): |
| 60 """Inserts a single path and value into a directory trie structure.""" | 60 """Inserts a single path and value into a directory trie structure.""" |
| 61 if not '/' in path: | 61 if not '/' in path: |
| 62 trie[path] = value | 62 trie[path] = value |
| 63 return | 63 return |
| 64 | 64 |
| 65 directory, _slash, rest = path.partition('/') | 65 directory, _, rest = path.partition('/') |
| 66 if not directory in trie: | 66 if not directory in trie: |
| 67 trie[directory] = {} | 67 trie[directory] = {} |
| 68 AddPathToTrie(rest, value, trie[directory]) | 68 AddPathToTrie(rest, value, trie[directory]) |
| 69 | 69 |
| 70 | 70 |
| 71 def TestTimingsTrie(individual_test_timings): | 71 def TestTimingsTrie(individual_test_timings): |
| 72 """Breaks a test name into dicts by directory | 72 """Breaks a test name into dicts by directory |
| 73 | 73 |
| 74 foo/bar/baz.html: 1ms | 74 foo/bar/baz.html: 1ms |
| 75 foo/bar/baz1.html: 3ms | 75 foo/bar/baz1.html: 3ms |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 # If there was an error don't write a results.json | 230 # If there was an error don't write a results.json |
| 231 # file at all as it would lose all the information on the | 231 # file at all as it would lose all the information on the |
| 232 # bot. | 232 # bot. |
| 233 _log.error('Archive directory is inaccessible. Not ' | 233 _log.error('Archive directory is inaccessible. Not ' |
| 234 'modifying or clobbering the results.json ' | 234 'modifying or clobbering the results.json ' |
| 235 'file: ' + str(error)) | 235 'file: ' + str(error)) |
| 236 return None | 236 return None |
| 237 | 237 |
| 238 builder_name = self._builder_name | 238 builder_name = self._builder_name |
| 239 if results_json and builder_name not in results_json: | 239 if results_json and builder_name not in results_json: |
| 240 _log.debug('Builder name (%s) is not in the results.json file.' | 240 _log.debug('Builder name (%s) is not in the results.json file.', |
| 241 % builder_name) | 241 builder_name) |
| 242 | 242 |
| 243 self._ConvertJSONToCurrentVersion(results_json) | 243 self._ConvertJSONToCurrentVersion(results_json) |
| 244 | 244 |
| 245 if builder_name not in results_json: | 245 if builder_name not in results_json: |
| 246 results_json[builder_name] = ( | 246 results_json[builder_name] = ( |
| 247 self._CreateResultsForBuilderJSON()) | 247 self._CreateResultsForBuilderJSON()) |
| 248 | 248 |
| 249 results_for_builder = results_json[builder_name] | 249 results_for_builder = results_json[builder_name] |
| 250 | 250 |
| 251 if builder_name: | 251 if builder_name: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 # Set uploading timeout in case appengine server is having problems. | 290 # Set uploading timeout in case appengine server is having problems. |
| 291 # 120 seconds are more than enough to upload test results. | 291 # 120 seconds are more than enough to upload test results. |
| 292 uploader = _FileUploader(url, 120) | 292 uploader = _FileUploader(url, 120) |
| 293 try: | 293 try: |
| 294 response = uploader.UploadAsMultipartFormData(files, attrs) | 294 response = uploader.UploadAsMultipartFormData(files, attrs) |
| 295 if response: | 295 if response: |
| 296 if response.code == 200: | 296 if response.code == 200: |
| 297 _log.info('JSON uploaded.') | 297 _log.info('JSON uploaded.') |
| 298 else: | 298 else: |
| 299 _log.debug( | 299 _log.debug( |
| 300 "JSON upload failed, %d: '%s'" % | 300 "JSON upload failed, %d: '%s'", response.code, response.read()) |
| 301 (response.code, response.read())) | |
| 302 else: | 301 else: |
| 303 _log.error('JSON upload failed; no response returned') | 302 _log.error('JSON upload failed; no response returned') |
| 304 except Exception, err: | 303 except Exception, err: # pylint: disable=broad-except |
| 305 _log.error('Upload failed: %s' % err) | 304 _log.error('Upload failed: %s', err) |
| 306 return | 305 return |
| 307 | 306 |
| 308 def _GetTestTiming(self, test_name): | 307 def _GetTestTiming(self, test_name): |
| 309 """Returns test timing data (elapsed time) in second | 308 """Returns test timing data (elapsed time) in second |
| 310 for the given test_name.""" | 309 for the given test_name.""" |
| 311 if test_name in self._test_results_map: | 310 if test_name in self._test_results_map: |
| 312 # Floor for now to get time in seconds. | 311 # Floor for now to get time in seconds. |
| 313 return int(self._test_results_map[test_name].test_run_time) | 312 return int(self._test_results_map[test_name].test_run_time) |
| 314 return 0 | 313 return 0 |
| 315 | 314 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 error = http_error | 390 error = http_error |
| 392 except urllib2.URLError, url_error: | 391 except urllib2.URLError, url_error: |
| 393 error = url_error | 392 error = url_error |
| 394 | 393 |
| 395 if old_results: | 394 if old_results: |
| 396 # Strip the prefix and suffix so we can get the actual JSON object. | 395 # Strip the prefix and suffix so we can get the actual JSON object. |
| 397 old_results = StripJSONWrapper(old_results) | 396 old_results = StripJSONWrapper(old_results) |
| 398 | 397 |
| 399 try: | 398 try: |
| 400 results_json = json.loads(old_results) | 399 results_json = json.loads(old_results) |
| 401 except Exception: | 400 except Exception: # pylint: disable=broad-except |
| 402 _log.debug('results.json was not valid JSON. Clobbering.') | 401 _log.debug('results.json was not valid JSON. Clobbering.') |
| 403 # The JSON file is not valid JSON. Just clobber the results. | 402 # The JSON file is not valid JSON. Just clobber the results. |
| 404 results_json = {} | 403 results_json = {} |
| 405 else: | 404 else: |
| 406 _log.debug('Old JSON results do not exist. Starting fresh.') | 405 _log.debug('Old JSON results do not exist. Starting fresh.') |
| 407 results_json = {} | 406 results_json = {} |
| 408 | 407 |
| 409 return results_json, error | 408 return results_json, error |
| 410 | 409 |
| 411 def _InsertFailureSummaries(self, results_for_builder): | 410 def _InsertFailureSummaries(self, results_for_builder): |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 def _UploadData(self, content_type, data): | 637 def _UploadData(self, content_type, data): |
| 639 start = time.time() | 638 start = time.time() |
| 640 end = start + self._timeout_seconds | 639 end = start + self._timeout_seconds |
| 641 while time.time() < end: | 640 while time.time() < end: |
| 642 try: | 641 try: |
| 643 request = urllib2.Request(self._url, data, | 642 request = urllib2.Request(self._url, data, |
| 644 {'Content-Type': content_type}) | 643 {'Content-Type': content_type}) |
| 645 return urllib2.urlopen(request) | 644 return urllib2.urlopen(request) |
| 646 except urllib2.HTTPError as e: | 645 except urllib2.HTTPError as e: |
| 647 _log.warn("Received HTTP status %s loading \"%s\". " | 646 _log.warn("Received HTTP status %s loading \"%s\". " |
| 648 'Retrying in 10 seconds...' % (e.code, e.filename)) | 647 'Retrying in 10 seconds...', e.code, e.filename) |
| 649 time.sleep(10) | 648 time.sleep(10) |
| 650 | 649 |
| 651 | 650 |
| 652 def _GetMIMEType(filename): | 651 def _GetMIMEType(filename): |
| 653 return mimetypes.guess_type(filename)[0] or 'application/octet-stream' | 652 return mimetypes.guess_type(filename)[0] or 'application/octet-stream' |
| 654 | 653 |
| 655 | 654 |
| 656 # FIXME: Rather than taking tuples, this function should take more | 655 # FIXME: Rather than taking tuples, this function should take more |
| 657 # structured data. | 656 # structured data. |
| 658 def _EncodeMultipartFormData(fields, files): | 657 def _EncodeMultipartFormData(fields, files): |
| (...skipping 29 matching lines...) Expand all Loading... |
| 688 lines.append('') | 687 lines.append('') |
| 689 if isinstance(value, unicode): | 688 if isinstance(value, unicode): |
| 690 value = value.encode('utf-8') | 689 value = value.encode('utf-8') |
| 691 lines.append(value) | 690 lines.append(value) |
| 692 | 691 |
| 693 lines.append('--' + BOUNDARY + '--') | 692 lines.append('--' + BOUNDARY + '--') |
| 694 lines.append('') | 693 lines.append('') |
| 695 body = CRLF.join(lines) | 694 body = CRLF.join(lines) |
| 696 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY | 695 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY |
| 697 return content_type, body | 696 return content_type, body |
| OLD | NEW |