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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/net/buildbot.py

Issue 2152663003: Refactor the buildbot module in webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 4 years, 5 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
OLDNEW
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 for more information about the layout test result format, see:
45 self._buildbot = buildbot 48 https://www.chromium.org/developers/the-json-test-results-format
49 """
46 50
47 def name(self): 51 def results_url(self, builder_name, build_number=None):
48 return self._name 52 """Returns a URL for one set of archived layout test results.
49 53
50 def results_url(self): 54 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) 55 otherwise it will be the accumulated results URL, which should have
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)
52 62
53 def latest_layout_test_results_url(self): 63 def builder_results_url_base(self, builder_name):
54 return config_urls.chromium_accumulated_results_url_base_for_builder(sel f._name) 64 """Returns the URL for the given builder's directory in Google Storage.
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))
55 71
56 @memoized 72 @memoized
57 def latest_layout_test_results(self): 73 def accumulated_results_url_base(self, builder_name):
58 return self.fetch_layout_test_results(self.latest_layout_test_results_ur l()) 74 return self.builder_results_url_base(builder_name) + "/results/layout-te st-results"
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 75
69 def fetch_layout_test_results(self, results_url): 76 def fetch_layout_test_results(self, results_url):
77 """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. 78 # 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.
71 results_file = NetworkTransaction(convert_404_to_None=True).run( 80 results_file = NetworkTransaction(convert_404_to_None=True).run(
72 lambda: self._fetch_file_from_results(results_url, "failing_results. json")) 81 lambda: self._fetch_file_from_results(results_url, "failing_results. json"))
73 revision = NetworkTransaction(convert_404_to_None=True).run( 82 revision = NetworkTransaction(convert_404_to_None=True).run(
74 lambda: self._fetch_file_from_results(results_url, "LAST_CHANGE")) 83 lambda: self._fetch_file_from_results(results_url, "LAST_CHANGE"))
75 if not revision: 84 if not revision:
76 results_file = None 85 results_file = None
77 return LayoutTestResults.results_from_string(results_file, revision) 86 return LayoutTestResults.results_from_string(results_file, revision)
78 87
79 def build(self, build_number): 88 def _fetch_file_from_results(self, results_url, file_name):
80 return Build(self, build_number=build_number) 89 # It seems this can return None if the url redirects and then returns 40 4.
81 90 # FIXME: This could use Web instead of using urllib2 directly.
82 91 result = urllib2.urlopen("%s/%s" % (results_url, file_name))
83 class Build(object): 92 if not result:
84 93 return None
85 def __init__(self, builder, build_number): 94 # urlopen returns a file-like object which sometimes works fine with str ()
86 self._builder = builder 95 # but sometimes is a addinfourl object. In either case calling read() i s correct.
87 self._number = build_number 96 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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698