| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import base64 | 5 import base64 |
| 6 from collections import defaultdict | 6 from collections import defaultdict |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import urllib | 9 import urllib |
| 10 import zlib | 10 import zlib |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 request.tags.extend(['findit:1', 'project:Chromium', 'purpose:post-commit']) | 81 request.tags.extend(['findit:1', 'project:Chromium', 'purpose:post-commit']) |
| 82 | 82 |
| 83 url = 'https://%s/_ah/api/swarming/v1/tasks/new' % swarming_settings.get( | 83 url = 'https://%s/_ah/api/swarming/v1/tasks/new' % swarming_settings.get( |
| 84 'server_host') | 84 'server_host') |
| 85 response_data = _SendRequestToServer(url, http_client, request.Serialize()) | 85 response_data = _SendRequestToServer(url, http_client, request.Serialize()) |
| 86 return json.loads(response_data)['task_id'] | 86 return json.loads(response_data)['task_id'] |
| 87 | 87 |
| 88 | 88 |
| 89 def ListSwarmingTasksDataByTags( | 89 def ListSwarmingTasksDataByTags( |
| 90 master_name, builder_name, build_number, http_client, step_name=None): | 90 master_name, builder_name, build_number, http_client, |
| 91 """Downloads tasks data from swarming server.""" | 91 additional_tag_filters=None): |
| 92 """Downloads tasks data from swarming server. |
| 93 |
| 94 Args: |
| 95 master_name(str): Value of the master tag. |
| 96 builder_name(str): Value of the buildername tag. |
| 97 build_number(int): Value of the buildnumber tag. |
| 98 http_client(RetryHttpClient): The http client to send HTTPs requests. |
| 99 additional_tag_filters(dict): More tag filters to be added. |
| 100 """ |
| 92 base_url = ('https://%s/_ah/api/swarming/v1/tasks/' | 101 base_url = ('https://%s/_ah/api/swarming/v1/tasks/' |
| 93 'list?tags=%s&tags=%s&tags=%s') % ( | 102 'list?tags=%s&tags=%s&tags=%s') % ( |
| 94 waterfall_config.GetSwarmingSettings().get('server_host'), | 103 waterfall_config.GetSwarmingSettings().get('server_host'), |
| 95 urllib.quote('master:%s' % master_name), | 104 urllib.quote('master:%s' % master_name), |
| 96 urllib.quote('buildername:%s' % builder_name), | 105 urllib.quote('buildername:%s' % builder_name), |
| 97 urllib.quote('buildnumber:%d' % build_number)) | 106 urllib.quote('buildnumber:%d' % build_number)) |
| 98 if step_name: | 107 additional_tag_filters = additional_tag_filters or {} |
| 99 base_url += '&tags=%s' % urllib.quote('stepname:%s' % step_name) | 108 for tag_name, tag_value in additional_tag_filters.iteritems(): |
| 109 base_url += '&tags=%s' % urllib.quote('%s:%s' % (tag_name, tag_value)) |
| 100 | 110 |
| 101 items = [] | 111 items = [] |
| 102 cursor = None | 112 cursor = None |
| 103 | 113 |
| 104 while True: | 114 while True: |
| 105 if not cursor: | 115 if not cursor: |
| 106 url = base_url | 116 url = base_url |
| 107 else: | 117 else: |
| 108 url = base_url + '&cursor=%s' % urllib.quote(cursor) | 118 url = base_url + '&cursor=%s' % urllib.quote(cursor) |
| 109 new_data = _SendRequestToServer(url, http_client) | 119 new_data = _SendRequestToServer(url, http_client) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 ndb.put_multi(new_steps) | 205 ndb.put_multi(new_steps) |
| 196 return True | 206 return True |
| 197 | 207 |
| 198 | 208 |
| 199 def GetIsolatedDataForStep( | 209 def GetIsolatedDataForStep( |
| 200 master_name, builder_name, build_number, step_name, | 210 master_name, builder_name, build_number, step_name, |
| 201 http_client): | 211 http_client): |
| 202 """Returns the isolated data for a specific step.""" | 212 """Returns the isolated data for a specific step.""" |
| 203 step_isolated_data = [] | 213 step_isolated_data = [] |
| 204 data = ListSwarmingTasksDataByTags(master_name, builder_name, build_number, | 214 data = ListSwarmingTasksDataByTags(master_name, builder_name, build_number, |
| 205 http_client, step_name) | 215 http_client, {'stepname': step_name}) |
| 206 if not data: | 216 if not data: |
| 207 return step_isolated_data | 217 return step_isolated_data |
| 208 | 218 |
| 209 for item in data: | 219 for item in data: |
| 210 if item['failure'] and not item['internal_failure']: | 220 if item['failure'] and not item['internal_failure']: |
| 211 # Only retrieves test results from tasks which have failures and | 221 # Only retrieves test results from tasks which have failures and |
| 212 # the failure should not be internal infrastructure failure. | 222 # the failure should not be internal infrastructure failure. |
| 213 isolated_data = _GenerateIsolatedData(item['outputs_ref']) | 223 isolated_data = _GenerateIsolatedData(item['outputs_ref']) |
| 214 step_isolated_data.append(isolated_data) | 224 step_isolated_data.append(isolated_data) |
| 215 | 225 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 shard_results = [] | 373 shard_results = [] |
| 364 for isolated_data in list_isolated_data: | 374 for isolated_data in list_isolated_data: |
| 365 output_json = _DownloadTestResults(isolated_data, http_client) | 375 output_json = _DownloadTestResults(isolated_data, http_client) |
| 366 if not output_json: | 376 if not output_json: |
| 367 return None | 377 return None |
| 368 shard_results.append(output_json) | 378 shard_results.append(output_json) |
| 369 | 379 |
| 370 if len(list_isolated_data) == 1: | 380 if len(list_isolated_data) == 1: |
| 371 return shard_results[0] | 381 return shard_results[0] |
| 372 return _MergeSwarmingTestShards(shard_results) | 382 return _MergeSwarmingTestShards(shard_results) |
| OLD | NEW |