Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2009, Google Inc. All rights reserved. | 1 # Copyright (c) 2009, Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import re | |
| 29 import urllib2 | 30 import urllib2 |
| 30 | 31 |
| 31 import webkitpy.common.config.urls as config_urls | |
| 32 from webkitpy.common.memoized import memoized | 32 from webkitpy.common.memoized import memoized |
| 33 from webkitpy.common.net.layouttestresults import LayoutTestResults | 33 from webkitpy.common.net.layouttestresults import LayoutTestResults |
| 34 from webkitpy.common.net.networktransaction import NetworkTransaction | 34 from webkitpy.common.net.networktransaction import NetworkTransaction |
| 35 from webkitpy.common.system.logutils import get_logger | 35 from webkitpy.common.system.logutils import get_logger |
| 36 | 36 |
| 37 | 37 |
| 38 RESULTS_URL_BASE = 'https://storage.googleapis.com/chromium-layout-test-archives ' | |
| 39 | |
| 38 _log = get_logger(__file__) | 40 _log = get_logger(__file__) |
| 39 | 41 |
| 40 | 42 |
| 41 class Builder(object): | 43 class BuildBot(object): |
| 44 """This class represents an interface to BuildBot-related functionality. | |
| 42 | 45 |
| 43 def __init__(self, builder_name, buildbot): | 46 This includes fetching layout test results from Google Storage. |
| 44 self._name = builder_name | 47 """ |
|
dcampb
2016/07/15 17:33:26
Whats the benefit of not having a __init__ in this
qyearsley
2016/07/15 17:49:59
Good question -- __init__ methods aren't necessary
| |
| 45 self._buildbot = buildbot | |
| 46 | 48 |
| 47 def name(self): | 49 def results_url(self, builder_name, build_number=None): |
| 48 return self._name | 50 """Returns a URL for one set of archived layout test results. |
| 49 | 51 |
| 50 def results_url(self): | 52 If a build number is given, this will be results for a particular run; |
| 51 return config_urls.chromium_results_url_base_for_builder(self._name) | 53 otherwise it will be the accumulated results URL, which should have |
| 54 the latest results. | |
| 55 """ | |
| 56 if build_number: | |
| 57 url_base = self.builder_results_url_base(builder_name) | |
| 58 return "%s/%s/layout-test-results" % (url_base, build_number) | |
| 59 return self.accumulated_results_url_base(builder_name) | |
| 52 | 60 |
| 53 def latest_layout_test_results_url(self): | 61 def builder_results_url_base(self, builder_name): |
| 54 return config_urls.chromium_accumulated_results_url_base_for_builder(sel f._name) | 62 return '%s/%s' % (RESULTS_URL_BASE, re.sub('[ .()]', '_', builder_name)) |
|
wkorman
2016/07/19 22:46:27
What is this re sub doing and why? Perhaps add a c
qyearsley
2016/07/19 23:17:26
I think that replacing parentheses, dots and space
| |
| 55 | 63 |
| 56 @memoized | 64 @memoized |
| 57 def latest_layout_test_results(self): | 65 def accumulated_results_url_base(self, builder_name): |
| 58 return self.fetch_layout_test_results(self.latest_layout_test_results_ur l()) | 66 return self.builder_results_url_base(builder_name) + "/results/layout-te st-results" |
|
wkorman
2016/07/19 22:46:27
Is there a doc we can link to in class doc comment
qyearsley
2016/07/19 23:17:26
The official doc is supposed to be https://www.chr
| |
| 59 | |
| 60 def _fetch_file_from_results(self, results_url, file_name): | |
| 61 # It seems this can return None if the url redirects and then returns 40 4. | |
| 62 result = urllib2.urlopen("%s/%s" % (results_url, file_name)) | |
| 63 if not result: | |
| 64 return None | |
| 65 # urlopen returns a file-like object which sometimes works fine with str () | |
| 66 # but sometimes is a addinfourl object. In either case calling read() i s correct. | |
| 67 return result.read() | |
| 68 | 67 |
| 69 def fetch_layout_test_results(self, results_url): | 68 def fetch_layout_test_results(self, results_url): |
| 69 """Returns a LayoutTestResults object for results fetched from a given U RL.""" | |
| 70 # FIXME: This should cache that the result was a 404 and stop hitting th e network. | 70 # FIXME: This should cache that the result was a 404 and stop hitting th e network. |
| 71 # This may be able to be done by just adding a @memoized decorator. | |
| 71 results_file = NetworkTransaction(convert_404_to_None=True).run( | 72 results_file = NetworkTransaction(convert_404_to_None=True).run( |
| 72 lambda: self._fetch_file_from_results(results_url, "failing_results. json")) | 73 lambda: self._fetch_file_from_results(results_url, "failing_results. json")) |
| 73 revision = NetworkTransaction(convert_404_to_None=True).run( | 74 revision = NetworkTransaction(convert_404_to_None=True).run( |
| 74 lambda: self._fetch_file_from_results(results_url, "LAST_CHANGE")) | 75 lambda: self._fetch_file_from_results(results_url, "LAST_CHANGE")) |
| 75 if not revision: | 76 if not revision: |
| 76 results_file = None | 77 results_file = None |
|
dcampb
2016/07/15 17:33:26
Why is there a Builder object? Would it be benefic
qyearsley
2016/07/15 17:49:59
That's what this CL does -- after this change, the
| |
| 77 return LayoutTestResults.results_from_string(results_file, revision) | 78 return LayoutTestResults.results_from_string(results_file, revision) |
| 78 | 79 |
| 79 def build(self, build_number): | 80 def _fetch_file_from_results(self, results_url, file_name): |
| 80 return Build(self, build_number=build_number) | 81 # It seems this can return None if the url redirects and then returns 40 4. |
| 81 | 82 # FIXME: This could use Web instead of using urllib2 directly. |
| 82 | 83 result = urllib2.urlopen("%s/%s" % (results_url, file_name)) |
| 83 class Build(object): | 84 if not result: |
| 84 | 85 return None |
| 85 def __init__(self, builder, build_number): | 86 # urlopen returns a file-like object which sometimes works fine with str () |
| 86 self._builder = builder | 87 # but sometimes is a addinfourl object. In either case calling read() i s correct. |
| 87 self._number = build_number | 88 return result.read() |
| 88 | |
| 89 def results_url(self): | |
| 90 return "%s/%s/layout-test-results" % (self._builder.results_url(), self. _number) | |
| 91 | |
| 92 def builder(self): | |
| 93 return self._builder | |
| 94 | |
| 95 | |
| 96 class BuildBot(object): | |
| 97 | |
| 98 def builder_with_name(self, builder_name): | |
| 99 return Builder(builder_name, self) | |
| OLD | NEW |