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 """This module contains functionality for starting build try jobs via HTTP. | 5 """This module contains functionality for starting build try jobs via HTTP. |
6 | 6 |
7 This includes both sending a request to start a job, and also related code | 7 This includes both sending a request to start a job, and also related code |
8 for querying the status of the job. | 8 for querying the status of the job. |
9 | 9 |
10 This module can be either run as a stand-alone script to send a request to a | 10 This module can be either run as a stand-alone script to send a request to a |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 import fetch_build | 22 import fetch_build |
23 | 23 |
24 # URL template for fetching JSON data about builds. | 24 # URL template for fetching JSON data about builds. |
25 BUILDER_JSON_URL = ('%(server_url)s/json/builders/%(bot_name)s/builds/' | 25 BUILDER_JSON_URL = ('%(server_url)s/json/builders/%(bot_name)s/builds/' |
26 '%(build_num)s?as_text=1&filter=0') | 26 '%(build_num)s?as_text=1&filter=0') |
27 | 27 |
28 # URL template for displaying build steps. | 28 # URL template for displaying build steps. |
29 BUILDER_HTML_URL = '%(server_url)s/builders/%(bot_name)s/builds/%(build_num)s' | 29 BUILDER_HTML_URL = '%(server_url)s/builders/%(bot_name)s/builds/%(build_num)s' |
30 | 30 |
31 # Try server status page URLs, used to get build status. | |
32 PERF_TRY_SERVER_URL = 'http://build.chromium.org/p/tryserver.chromium.perf' | |
33 LINUX_TRY_SERVER_URL = 'http://build.chromium.org/p/tryserver.chromium.linux' | |
34 | |
35 # Status codes that can be returned by the GetBuildStatus method | 31 # Status codes that can be returned by the GetBuildStatus method |
36 # From buildbot.status.builder. | 32 # From buildbot.status.builder. |
37 # See: http://docs.buildbot.net/current/developer/results.html | 33 # See: http://docs.buildbot.net/current/developer/results.html |
38 SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY, TRYPENDING = range(7) | 34 SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY, TRYPENDING = range(7) |
39 OK = (SUCCESS, WARNINGS) # These indicate build is complete. | 35 OK = (SUCCESS, WARNINGS) # These indicate build is complete. |
40 FAILED = (FAILURE, EXCEPTION, SKIPPED) # These indicate build failure. | 36 FAILED = (FAILURE, EXCEPTION, SKIPPED) # These indicate build failure. |
41 PENDING = (RETRY, TRYPENDING) # These indicate in progress or in pending queue. | 37 PENDING = (RETRY, TRYPENDING) # These indicate in progress or in pending queue. |
42 | 38 |
43 | 39 |
44 class ServerAccessError(Exception): | 40 class ServerAccessError(Exception): |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 140 |
145 Returns: | 141 Returns: |
146 A dictionary with build information if build exists, otherwise None. | 142 A dictionary with build information if build exists, otherwise None. |
147 """ | 143 """ |
148 builds_json = _FetchBuilderData(buildbot_url) | 144 builds_json = _FetchBuilderData(buildbot_url) |
149 if builds_json: | 145 if builds_json: |
150 return json.loads(builds_json) | 146 return json.loads(builds_json) |
151 return None | 147 return None |
152 | 148 |
153 | 149 |
154 def _GetBuildBotUrl(builder_type): | 150 def GetBuildStatus(build_num, bot_name, server_url): |
155 """Gets build bot URL for fetching build info. | |
156 | |
157 Bisect builder bots are hosted on tryserver.chromium.perf, though we cannot | |
158 access this tryserver using host and port number directly, so we use another | |
159 tryserver URL for the perf tryserver. | |
160 | |
161 Args: | |
162 builder_type: Determines what type of builder is used, e.g. "perf". | |
163 | |
164 Returns: | |
165 URL of the buildbot as a string. | |
166 """ | |
167 if builder_type == fetch_build.PERF_BUILDER: | |
168 return PERF_TRY_SERVER_URL | |
169 if builder_type == fetch_build.FULL_BUILDER: | |
170 return LINUX_TRY_SERVER_URL | |
171 raise NotImplementedError('Unsupported builder type "%s".' % builder_type) | |
172 | |
173 | |
174 def GetBuildStatus(build_num, bot_name, builder_type): | |
175 """Gets build status from the buildbot status page for a given build number. | 151 """Gets build status from the buildbot status page for a given build number. |
176 | 152 |
177 Args: | 153 Args: |
178 build_num: A build number on tryserver to determine its status. | 154 build_num: A build number on tryserver to determine its status. |
179 bot_name: Name of the bot where the build information is scanned. | 155 bot_name: Name of the bot where the build information is scanned. |
180 builder_type: Type of builder, e.g. "perf". | 156 server_url: URL of the buildbot. |
181 | 157 |
182 Returns: | 158 Returns: |
183 A pair which consists of build status (SUCCESS, FAILED or PENDING) and a | 159 A pair which consists of build status (SUCCESS, FAILED or PENDING) and a |
184 link to build status page on the waterfall. | 160 link to build status page on the waterfall. |
185 """ | 161 """ |
186 # TODO(prasadv, qyearsley): Make this a method of BuildArchive | |
187 # (which may be renamed to BuilderTryBot or Builder). | |
188 results_url = None | 162 results_url = None |
189 if build_num: | 163 if build_num: |
190 # Get the URL for requesting JSON data with status information. | 164 # Get the URL for requesting JSON data with status information. |
191 server_url = _GetBuildBotUrl(builder_type) | |
192 buildbot_url = BUILDER_JSON_URL % { | 165 buildbot_url = BUILDER_JSON_URL % { |
193 'server_url': server_url, | 166 'server_url': server_url, |
194 'bot_name': bot_name, | 167 'bot_name': bot_name, |
195 'build_num': build_num, | 168 'build_num': build_num, |
196 } | 169 } |
197 build_data = _GetBuildData(buildbot_url) | 170 build_data = _GetBuildData(buildbot_url) |
198 if build_data: | 171 if build_data: |
199 # Link to build on the buildbot showing status of build steps. | 172 # Link to build on the buildbot showing status of build steps. |
200 results_url = BUILDER_HTML_URL % { | 173 results_url = BUILDER_HTML_URL % { |
201 'server_url': server_url, | 174 'server_url': server_url, |
202 'bot_name': bot_name, | 175 'bot_name': bot_name, |
203 'build_num': build_num, | 176 'build_num': build_num, |
204 } | 177 } |
205 if _IsBuildFailed(build_data): | 178 if _IsBuildFailed(build_data): |
206 return (FAILED, results_url) | 179 return (FAILED, results_url) |
207 | 180 |
208 elif _IsBuildSuccessful(build_data): | 181 elif _IsBuildSuccessful(build_data): |
209 return (OK, results_url) | 182 return (OK, results_url) |
210 return (PENDING, results_url) | 183 return (PENDING, results_url) |
211 | 184 |
212 | 185 |
213 def GetBuildNumFromBuilder(build_reason, bot_name, builder_type): | 186 def GetBuildNumFromBuilder(build_reason, bot_name, server_url): |
214 """Gets build number on build status page for a given 'build reason'. | 187 """Gets build number on build status page for a given 'build reason'. |
215 | 188 |
216 This function parses the JSON data from buildbot page and collects basic | 189 This function parses the JSON data from buildbot page and collects basic |
217 information about the all the builds, and then uniquely identifies the build | 190 information about the all the builds, and then uniquely identifies the build |
218 based on the 'reason' attribute in builds's JSON data. | 191 based on the 'reason' attribute in builds's JSON data. |
219 | 192 |
220 The 'reason' attribute set is when a build request is posted, and it is used | 193 The 'reason' attribute set is when a build request is posted, and it is used |
221 to identify the build on status page. | 194 to identify the build on status page. |
222 | 195 |
223 Args: | 196 Args: |
224 build_reason: A unique build name set to build on tryserver. | 197 build_reason: A unique build name set to build on tryserver. |
225 bot_name: Name of the bot where the build information is scanned. | 198 bot_name: Name of the bot where the build information is scanned. |
226 builder_type: Type of builder, e.g. "perf". | 199 server_url: URL of the buildbot. |
227 | 200 |
228 Returns: | 201 Returns: |
229 A build number as a string if found, otherwise None. | 202 A build number as a string if found, otherwise None. |
230 """ | 203 """ |
231 # TODO(prasadv, qyearsley): Make this a method of BuildArchive | |
232 # (which may be renamed to BuilderTryBot or Builder). | |
233 # Gets the buildbot url for the given host and port. | |
234 server_url = _GetBuildBotUrl(builder_type) | |
235 buildbot_url = BUILDER_JSON_URL % { | 204 buildbot_url = BUILDER_JSON_URL % { |
236 'server_url': server_url, | 205 'server_url': server_url, |
237 'bot_name': bot_name, | 206 'bot_name': bot_name, |
238 'build_num': '_all', | 207 'build_num': '_all', |
239 } | 208 } |
240 builds_json = _FetchBuilderData(buildbot_url) | 209 builds_json = _FetchBuilderData(buildbot_url) |
241 if builds_json: | 210 if builds_json: |
242 builds_data = json.loads(builds_json) | 211 builds_data = json.loads(builds_json) |
243 for current_build in builds_data: | 212 for current_build in builds_data: |
244 if builds_data[current_build].get('reason') == build_reason: | 213 if builds_data[current_build].get('reason') == build_reason: |
245 return builds_data[current_build].get('number') | 214 return builds_data[current_build].get('number') |
246 return None | 215 return None |
OLD | NEW |