| 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 from common.git_repository import GitRepository | 5 from common.git_repository import GitRepository |
| 6 from common.http_client_appengine import HttpClientAppengine as HttpClient | 6 from common.http_client_appengine import HttpClientAppengine as HttpClient |
| 7 from common.pipeline_wrapper import BasePipeline | 7 from common.pipeline_wrapper import BasePipeline |
| 8 from model import analysis_status | 8 from model import analysis_status |
| 9 from model import result_status |
| 10 from model.wf_analysis import WfAnalysis |
| 9 from model.wf_try_job import WfTryJob | 11 from model.wf_try_job import WfTryJob |
| 10 from model.wf_try_job_data import WfTryJobData | 12 from model.wf_try_job_data import WfTryJobData |
| 11 from waterfall.try_job_type import TryJobType | 13 from waterfall.try_job_type import TryJobType |
| 12 | 14 |
| 13 | 15 |
| 14 GIT_REPO = GitRepository( | 16 GIT_REPO = GitRepository( |
| 15 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) | 17 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) |
| 16 | 18 |
| 17 | 19 |
| 20 def _GetResultAnalysisStatus(analysis, result): |
| 21 """Returns the analysis status based on existing status and try job result. |
| 22 |
| 23 Args: |
| 24 analysis: The WfAnalysis entity corresponding to this try job. |
| 25 result: A result dict containing the result of this try job. |
| 26 |
| 27 Returns: |
| 28 A result_status code. |
| 29 """ |
| 30 # Only return an updated analysis result status if no results were already |
| 31 # found (by the heuristic-based approach) but were by the try job. Note it is |
| 32 # possible the heuristic-based result was triaged before the completion of |
| 33 # this try job. |
| 34 old_result_status = analysis.result_status |
| 35 try_job_found_culprit = result and result.get('culprit') |
| 36 |
| 37 if (try_job_found_culprit and |
| 38 (old_result_status is None or |
| 39 old_result_status == result_status.NOT_FOUND_UNTRIAGED or |
| 40 old_result_status == result_status.NOT_FOUND_INCORRECT or |
| 41 old_result_status == result_status.NOT_FOUND_CORRECT)): |
| 42 return result_status.FOUND_UNTRIAGED |
| 43 |
| 44 return old_result_status |
| 45 |
| 46 |
| 47 def _GetSuspectedCLs(analysis, result): |
| 48 """Returns a list of suspected CLs. |
| 49 |
| 50 Args: |
| 51 analysis: The WfAnalysis entity corresponding to this try job. |
| 52 result: A result dict containing the culprit from the results of |
| 53 this try job. |
| 54 |
| 55 Returns: |
| 56 A combined list of suspected CLs from those already in analysis and those |
| 57 found by this try job. |
| 58 """ |
| 59 suspected_cls = analysis.suspected_cls[:] if analysis.suspected_cls else [] |
| 60 culprit = result.get('culprit') |
| 61 compile_cl_info = culprit.get('compile') |
| 62 |
| 63 if compile_cl_info: |
| 64 # Suspected CL is from compile failure. |
| 65 if compile_cl_info not in suspected_cls: |
| 66 suspected_cls.append(compile_cl_info) |
| 67 return suspected_cls |
| 68 |
| 69 # Suspected CLs are from test failures. |
| 70 for results in culprit.itervalues(): |
| 71 if results.get('revision'): |
| 72 # Non swarming test failures, only have step level failure info. |
| 73 cl_info = { |
| 74 'review_url': results.get('review_url'), |
| 75 'repo_name': results.get('repo_name'), |
| 76 'revision': results.get('revision'), |
| 77 'commit_position': results.get('commit_position') |
| 78 } |
| 79 if cl_info not in suspected_cls: |
| 80 suspected_cls.append(cl_info) |
| 81 else: |
| 82 for test_cl_info in results['tests'].values(): |
| 83 if test_cl_info not in suspected_cls: |
| 84 suspected_cls.append(test_cl_info) |
| 85 |
| 86 return suspected_cls |
| 87 |
| 88 |
| 18 class IdentifyTryJobCulpritPipeline(BasePipeline): | 89 class IdentifyTryJobCulpritPipeline(BasePipeline): |
| 19 """A pipeline to identify culprit CL info based on try job compile results.""" | 90 """A pipeline to identify culprit CL info based on try job compile results.""" |
| 20 | 91 |
| 21 def _GetCulpritInfo(self, failed_revisions): | 92 def _GetCulpritInfo(self, failed_revisions): |
| 22 """Gets commit_positions and review_urls for revisions.""" | 93 """Gets commit_positions and review_urls for revisions.""" |
| 23 culprits = {} | 94 culprits = {} |
| 95 # TODO(lijeffrey): remove hard-coded 'chromium' when DEPS file parsing is |
| 96 # supported. |
| 24 for failed_revision in failed_revisions: | 97 for failed_revision in failed_revisions: |
| 25 culprits[failed_revision] = { | 98 culprits[failed_revision] = { |
| 26 'revision': failed_revision | 99 'revision': failed_revision, |
| 100 'repo_name': 'chromium' |
| 27 } | 101 } |
| 28 change_log = GIT_REPO.GetChangeLog(failed_revision) | 102 change_log = GIT_REPO.GetChangeLog(failed_revision) |
| 29 if change_log: | 103 if change_log: |
| 30 culprits[failed_revision]['commit_position'] = ( | 104 culprits[failed_revision]['commit_position'] = ( |
| 31 change_log.commit_position) | 105 change_log.commit_position) |
| 32 culprits[failed_revision]['review_url'] = change_log.code_review_url | 106 culprits[failed_revision]['review_url'] = change_log.code_review_url |
| 33 | 107 |
| 34 return culprits | 108 return culprits |
| 35 | 109 |
| 36 @staticmethod | 110 @staticmethod |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 176 |
| 103 if step not in culprit_map: | 177 if step not in culprit_map: |
| 104 culprit_map[step] = { | 178 culprit_map[step] = { |
| 105 'tests': {} | 179 'tests': {} |
| 106 } | 180 } |
| 107 | 181 |
| 108 if (not test_result['failures'] and | 182 if (not test_result['failures'] and |
| 109 not culprit_map[step].get('revision')): | 183 not culprit_map[step].get('revision')): |
| 110 # Non swarming test failures, only have step level failure info. | 184 # Non swarming test failures, only have step level failure info. |
| 111 culprit_map[step]['revision'] = revision | 185 culprit_map[step]['revision'] = revision |
| 186 culprit_map[step]['repo_name'] = 'chromium' |
| 112 | 187 |
| 113 for failed_test in test_result['failures']: | 188 for failed_test in test_result['failures']: |
| 114 # Swarming tests, gets first failed revision for each test. | 189 # Swarming tests, gets first failed revision for each test. |
| 115 if failed_test not in culprit_map[step]['tests']: | 190 if failed_test not in culprit_map[step]['tests']: |
| 116 culprit_map[step]['tests'][failed_test] = { | 191 culprit_map[step]['tests'][failed_test] = { |
| 117 'revision': revision | 192 'revision': revision |
| 118 } | 193 } |
| 119 | 194 |
| 120 return culprit_map, failed_revisions | 195 return culprit_map, failed_revisions |
| 121 | 196 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 blame_list, result) | 245 blame_list, result) |
| 171 culprits = self._GetCulpritInfo(failed_revisions) | 246 culprits = self._GetCulpritInfo(failed_revisions) |
| 172 if culprits: | 247 if culprits: |
| 173 self._UpdateCulpritMapWithCulpritInfo(culprit_map, culprits) | 248 self._UpdateCulpritMapWithCulpritInfo(culprit_map, culprits) |
| 174 result['culprit'] = culprit_map | 249 result['culprit'] = culprit_map |
| 175 try_job_data.culprits = self._GetCulpritDataForTest(culprit_map) | 250 try_job_data.culprits = self._GetCulpritDataForTest(culprit_map) |
| 176 try_job_data.put() | 251 try_job_data.put() |
| 177 | 252 |
| 178 # Store try job results. | 253 # Store try job results. |
| 179 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | 254 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| 255 |
| 180 if culprits: | 256 if culprits: |
| 181 result_to_update = ( | 257 result_to_update = ( |
| 182 try_job_result.compile_results if | 258 try_job_result.compile_results if |
| 183 try_job_type == TryJobType.COMPILE else | 259 try_job_type == TryJobType.COMPILE else |
| 184 try_job_result.test_results) | 260 try_job_result.test_results) |
| 185 if (result_to_update and | 261 if (result_to_update and |
| 186 result_to_update[-1]['try_job_id'] == try_job_id): | 262 result_to_update[-1]['try_job_id'] == try_job_id): |
| 187 result_to_update[-1].update(result) | 263 result_to_update[-1].update(result) |
| 188 else: # pragma: no cover | 264 else: # pragma: no cover |
| 189 result_to_update.append(result) | 265 result_to_update.append(result) |
| 190 | 266 |
| 267 # Update analysis result and suspected CLs with results of this try job if |
| 268 # culprits were found. |
| 269 analysis = WfAnalysis.Get(master_name, builder_name, build_number) |
| 270 updated_result_status = _GetResultAnalysisStatus(analysis, result) |
| 271 updated_suspected_cls = _GetSuspectedCLs(analysis, result) |
| 272 |
| 273 if (analysis.result_status != updated_result_status or |
| 274 analysis.suspected_cls != updated_suspected_cls): |
| 275 analysis.result_status = updated_result_status |
| 276 analysis.suspected_cls = updated_suspected_cls |
| 277 analysis.put() |
| 278 |
| 191 try_job_result.status = analysis_status.COMPLETED | 279 try_job_result.status = analysis_status.COMPLETED |
| 192 try_job_result.put() | 280 try_job_result.put() |
| 193 | 281 |
| 194 return result.get('culprit') if result else None | 282 return result.get('culprit') if result else None |
| OLD | NEW |