Chromium Code Reviews| 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 additional_tag_filters(dict): More tag filters to be added. | |
|
chanli
2016/10/07 01:04:52
Nit: add other args as well?
stgao
2016/10/07 01:19:33
Done.
| |
| 96 """ | |
| 92 base_url = ('https://%s/_ah/api/swarming/v1/tasks/' | 97 base_url = ('https://%s/_ah/api/swarming/v1/tasks/' |
| 93 'list?tags=%s&tags=%s&tags=%s') % ( | 98 'list?tags=%s&tags=%s&tags=%s') % ( |
| 94 waterfall_config.GetSwarmingSettings().get('server_host'), | 99 waterfall_config.GetSwarmingSettings().get('server_host'), |
| 95 urllib.quote('master:%s' % master_name), | 100 urllib.quote('master:%s' % master_name), |
| 96 urllib.quote('buildername:%s' % builder_name), | 101 urllib.quote('buildername:%s' % builder_name), |
| 97 urllib.quote('buildnumber:%d' % build_number)) | 102 urllib.quote('buildnumber:%d' % build_number)) |
| 98 if step_name: | 103 additional_tag_filters = additional_tag_filters or {} |
| 99 base_url += '&tags=%s' % urllib.quote('stepname:%s' % step_name) | 104 for tag_name, tag_value in additional_tag_filters.iteritems(): |
| 105 base_url += '&tags=%s' % urllib.quote('%s:%s' % (tag_name, tag_value)) | |
| 100 | 106 |
| 101 items = [] | 107 items = [] |
| 102 cursor = None | 108 cursor = None |
| 103 | 109 |
| 104 while True: | 110 while True: |
| 105 if not cursor: | 111 if not cursor: |
| 106 url = base_url | 112 url = base_url |
| 107 else: | 113 else: |
| 108 url = base_url + '&cursor=%s' % urllib.quote(cursor) | 114 url = base_url + '&cursor=%s' % urllib.quote(cursor) |
| 109 new_data = _SendRequestToServer(url, http_client) | 115 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) | 201 ndb.put_multi(new_steps) |
| 196 return True | 202 return True |
| 197 | 203 |
| 198 | 204 |
| 199 def GetIsolatedDataForStep( | 205 def GetIsolatedDataForStep( |
| 200 master_name, builder_name, build_number, step_name, | 206 master_name, builder_name, build_number, step_name, |
| 201 http_client): | 207 http_client): |
| 202 """Returns the isolated data for a specific step.""" | 208 """Returns the isolated data for a specific step.""" |
| 203 step_isolated_data = [] | 209 step_isolated_data = [] |
| 204 data = ListSwarmingTasksDataByTags(master_name, builder_name, build_number, | 210 data = ListSwarmingTasksDataByTags(master_name, builder_name, build_number, |
| 205 http_client, step_name) | 211 http_client, {'stepname': step_name}) |
| 206 if not data: | 212 if not data: |
| 207 return step_isolated_data | 213 return step_isolated_data |
| 208 | 214 |
| 209 for item in data: | 215 for item in data: |
| 210 if item['failure'] and not item['internal_failure']: | 216 if item['failure'] and not item['internal_failure']: |
| 211 # Only retrieves test results from tasks which have failures and | 217 # Only retrieves test results from tasks which have failures and |
| 212 # the failure should not be internal infrastructure failure. | 218 # the failure should not be internal infrastructure failure. |
| 213 isolated_data = _GenerateIsolatedData(item['outputs_ref']) | 219 isolated_data = _GenerateIsolatedData(item['outputs_ref']) |
| 214 step_isolated_data.append(isolated_data) | 220 step_isolated_data.append(isolated_data) |
| 215 | 221 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 shard_results = [] | 369 shard_results = [] |
| 364 for isolated_data in list_isolated_data: | 370 for isolated_data in list_isolated_data: |
| 365 output_json = _DownloadTestResults(isolated_data, http_client) | 371 output_json = _DownloadTestResults(isolated_data, http_client) |
| 366 if not output_json: | 372 if not output_json: |
| 367 return None | 373 return None |
| 368 shard_results.append(output_json) | 374 shard_results.append(output_json) |
| 369 | 375 |
| 370 if len(list_isolated_data) == 1: | 376 if len(list_isolated_data) == 1: |
| 371 return shard_results[0] | 377 return shard_results[0] |
| 372 return _MergeSwarmingTestShards(shard_results) | 378 return _MergeSwarmingTestShards(shard_results) |
| OLD | NEW |