| 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 model import wf_analysis_status | 7 from model import wf_analysis_status |
| 8 from model.wf_try_job import WfTryJob | 8 from model.wf_try_job import WfTryJob |
| 9 from pipeline_wrapper import BasePipeline | 9 from pipeline_wrapper import BasePipeline |
| 10 | 10 |
| 11 | 11 |
| 12 class IdentifyTryJobCulpritPipeline(BasePipeline): | 12 class IdentifyTryJobCulpritPipeline(BasePipeline): |
| 13 """A pipeline to identify culprit CL info based on try job compile results.""" | 13 """A pipeline to identify culprit CL info based on try job compile results.""" |
| 14 | 14 |
| 15 # Arguments number differs from overridden method - pylint: disable=W0221 | 15 @staticmethod |
| 16 def run( | 16 def _GetFailedRevisionFromResultsDict(results_dict): |
| 17 self, master_name, builder_name, build_number, try_job_id, | 17 """Finds the failed revision from the given dict of revisions. |
| 18 compile_result): | |
| 19 culprit = None | |
| 20 | 18 |
| 21 if compile_result and len(compile_result.get('result', [])) > 0: | 19 Args: |
| 20 results_dict: (dict) A dict that maps revisions to their results. For |
| 21 example: |
| 22 |
| 23 { |
| 24 'rev1': 'passed', |
| 25 'rev2': 'passed', |
| 26 'rev3': 'failed', |
| 27 } |
| 28 |
| 29 Note results_dict is expected only to have one failed revision which |
| 30 will be the one to be returned. |
| 31 |
| 32 Returns: |
| 33 The revision corresponding to a failed result, if any. |
| 34 """ |
| 35 for revision, result in results_dict.iteritems(): |
| 36 if result.lower() == 'failed': |
| 37 return revision |
| 38 return None |
| 39 |
| 40 @staticmethod |
| 41 def _GetFailedRevisionFromCompileResult(compile_result): |
| 42 """Determines the failed revision given compile_result. |
| 43 |
| 44 Args: |
| 45 compile_result: A dict containing the results from a compile. Curently two |
| 46 formats are supported. |
| 47 |
| 48 The old format: |
| 49 { |
| 50 'report': [ |
| 51 ['rev1', 'passed'], |
| 52 ['rev2', 'failed'] |
| 53 ], |
| 54 'url': try job url, |
| 55 'try_job_id': try job id |
| 56 } |
| 57 |
| 58 The new format: |
| 59 { |
| 60 'report': { |
| 61 'result': { |
| 62 'rev1': 'passed', |
| 63 'rev2': 'failed', |
| 64 }, |
| 65 ... (other metadata from the compile result) |
| 66 }, |
| 67 'url': try job url, |
| 68 'try_job_id': try job id |
| 69 } |
| 70 |
| 71 Returns: |
| 72 The failed revision from compile_results, or None if not found. |
| 73 """ |
| 74 if not compile_result: |
| 75 return None |
| 76 |
| 77 report = compile_result.get('report') |
| 78 |
| 79 if not report: |
| 80 return None |
| 81 |
| 82 failed_revision = None |
| 83 |
| 84 if isinstance(report, list): |
| 85 # TODO(lijeffrey): The format for the result of the compile will change |
| 86 # from a list to a dict. This branch is for backwards compatibility and |
| 87 # should be removed once result is returned as a dict from the compile |
| 88 # recipe. The test recipe may need to be considered as well. |
| 89 |
| 22 # For compile failures, the try job will stop if one revision fails, so | 90 # For compile failures, the try job will stop if one revision fails, so |
| 23 # the culprit will be the last revision in the result. | 91 # the culprit will be the last revision in the result. |
| 24 result_for_last_checked_revision = compile_result['result'][-1] | 92 result_for_last_checked_revision = report[-1] |
| 25 failed_revision = ( | 93 failed_revision = ( |
| 26 result_for_last_checked_revision[0] if | 94 result_for_last_checked_revision[0] if |
| 27 result_for_last_checked_revision[1].lower() == 'failed' else None) | 95 result_for_last_checked_revision[1].lower() == 'failed' else None) |
| 96 else: |
| 97 revision_results = report.get('result', {}) |
| 98 failed_revision = ( |
| 99 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict( |
| 100 revision_results)) |
| 28 | 101 |
| 29 if failed_revision: | 102 return failed_revision |
| 30 git_repo = GitRepository( | 103 |
| 31 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) | 104 @staticmethod |
| 32 change_log = git_repo.GetChangeLog(failed_revision) | 105 def _GetCulpritFromFailedRevision(failed_revision): |
| 33 if change_log: | 106 """Returns a culprit (dict) using failed_revision, or None.""" |
| 34 culprit = { | 107 if not failed_revision: |
| 35 'revision': failed_revision, | 108 return None |
| 36 'commit_position': change_log.commit_position, | 109 |
| 37 'review_url': change_log.code_review_url | 110 git_repo = GitRepository( |
| 38 } | 111 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) |
| 39 compile_result['culprit'] = culprit | 112 change_log = git_repo.GetChangeLog(failed_revision) |
| 113 |
| 114 if not change_log: |
| 115 return None |
| 116 |
| 117 return { |
| 118 'revision': failed_revision, |
| 119 'commit_position': change_log.commit_position, |
| 120 'review_url': change_log.code_review_url |
| 121 } |
| 122 |
| 123 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 124 def run(self, master_name, builder_name, build_number, try_job_id, |
| 125 compile_result): |
| 126 culprit = None |
| 127 failed_revision = self._GetFailedRevisionFromCompileResult(compile_result) |
| 128 culprit = self._GetCulpritFromFailedRevision(failed_revision) |
| 40 | 129 |
| 41 # Store try job results. | 130 # Store try job results. |
| 42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | 131 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| 43 if culprit: | 132 if culprit: |
| 133 compile_result['culprit'] = culprit |
| 44 if (try_job_result.compile_results and | 134 if (try_job_result.compile_results and |
| 45 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): | 135 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): |
| 46 try_job_result.compile_results[-1].update(compile_result) | 136 try_job_result.compile_results[-1].update(compile_result) |
| 47 else: # pragma: no cover | 137 else: # pragma: no cover |
| 48 try_job_result.compile_results.append(compile_result) | 138 try_job_result.compile_results.append(compile_result) |
| 49 | 139 |
| 50 try_job_result.status = wf_analysis_status.ANALYZED | 140 try_job_result.status = wf_analysis_status.ANALYZED |
| 51 try_job_result.put() | 141 try_job_result.put() |
| 52 | 142 |
| 53 return culprit | 143 return culprit |
| OLD | NEW |