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 | |
30 import urllib2 | 29 import urllib2 |
31 | 30 |
| 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 | |
40 _log = get_logger(__file__) | 38 _log = get_logger(__file__) |
41 | 39 |
42 | 40 |
43 class BuildBot(object): | 41 class Builder(object): |
44 """This class represents an interface to BuildBot-related functionality. | |
45 | 42 |
46 This includes fetching layout test results from Google Storage; | 43 def __init__(self, builder_name, buildbot): |
47 for more information about the layout test result format, see: | 44 self._name = builder_name |
48 https://www.chromium.org/developers/the-json-test-results-format | 45 self._buildbot = buildbot |
49 """ | |
50 | 46 |
51 def results_url(self, builder_name, build_number=None): | 47 def name(self): |
52 """Returns a URL for one set of archived layout test results. | 48 return self._name |
53 | 49 |
54 If a build number is given, this will be results for a particular run; | 50 def results_url(self): |
55 otherwise it will be the accumulated results URL, which should have | 51 return config_urls.chromium_results_url_base_for_builder(self._name) |
56 the latest results. | |
57 """ | |
58 if build_number: | |
59 url_base = self.builder_results_url_base(builder_name) | |
60 return "%s/%s/layout-test-results" % (url_base, build_number) | |
61 return self.accumulated_results_url_base(builder_name) | |
62 | 52 |
63 def builder_results_url_base(self, builder_name): | 53 def latest_layout_test_results_url(self): |
64 """Returns the URL for the given builder's directory in Google Storage. | 54 return config_urls.chromium_accumulated_results_url_base_for_builder(sel
f._name) |
65 | |
66 Each builder has a directory in the GS bucket, and the directory | |
67 name is the builder name transformed to be more URL-friendly by | |
68 replacing all spaces, periods and parentheses with underscores. | |
69 """ | |
70 return '%s/%s' % (RESULTS_URL_BASE, re.sub('[ .()]', '_', builder_name)) | |
71 | 55 |
72 @memoized | 56 @memoized |
73 def accumulated_results_url_base(self, builder_name): | 57 def latest_layout_test_results(self): |
74 return self.builder_results_url_base(builder_name) + "/results/layout-te
st-results" | 58 return self.fetch_layout_test_results(self.latest_layout_test_results_ur
l()) |
| 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() |
75 | 68 |
76 def fetch_layout_test_results(self, results_url): | 69 def fetch_layout_test_results(self, results_url): |
77 """Returns a LayoutTestResults object for results fetched from a given U
RL.""" | |
78 # 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. |
79 # This may be able to be done by just adding a @memoized decorator. | |
80 results_file = NetworkTransaction(convert_404_to_None=True).run( | 71 results_file = NetworkTransaction(convert_404_to_None=True).run( |
81 lambda: self._fetch_file_from_results(results_url, "failing_results.
json")) | 72 lambda: self._fetch_file_from_results(results_url, "failing_results.
json")) |
82 revision = NetworkTransaction(convert_404_to_None=True).run( | 73 revision = NetworkTransaction(convert_404_to_None=True).run( |
83 lambda: self._fetch_file_from_results(results_url, "LAST_CHANGE")) | 74 lambda: self._fetch_file_from_results(results_url, "LAST_CHANGE")) |
84 if not revision: | 75 if not revision: |
85 results_file = None | 76 results_file = None |
86 return LayoutTestResults.results_from_string(results_file, revision) | 77 return LayoutTestResults.results_from_string(results_file, revision) |
87 | 78 |
88 def _fetch_file_from_results(self, results_url, file_name): | 79 def build(self, build_number): |
89 # It seems this can return None if the url redirects and then returns 40
4. | 80 return Build(self, build_number=build_number) |
90 # FIXME: This could use Web instead of using urllib2 directly. | 81 |
91 result = urllib2.urlopen("%s/%s" % (results_url, file_name)) | 82 |
92 if not result: | 83 class Build(object): |
93 return None | 84 |
94 # urlopen returns a file-like object which sometimes works fine with str
() | 85 def __init__(self, builder, build_number): |
95 # but sometimes is a addinfourl object. In either case calling read() i
s correct. | 86 self._builder = builder |
96 return result.read() | 87 self._number = build_number |
| 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 |