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 from base_handler import BaseHandler | 5 from base_handler import BaseHandler |
| 6 from base_handler import Permission | 6 from base_handler import Permission |
| 7 from model.wf_analysis import WfAnalysis | 7 from model.wf_analysis import WfAnalysis |
| 8 from model import wf_analysis_status | 8 from model import wf_analysis_status |
| 9 from model.wf_try_job import WfTryJob | 9 from model.wf_try_job import WfTryJob |
| 10 from waterfall import buildbot | 10 from waterfall import buildbot |
| 11 | 11 |
| 12 | 12 |
| 13 def _GetTryJobResult(master_name, builder_name, build_number): | 13 def _GetTryJobBuildNumber(url): |
| 14 # Get the latest try job result if it's compile failure. | 14 build_keys = buildbot.ParseBuildUrl(url) |
| 15 return build_keys[2] | |
| 16 | |
| 17 | |
| 18 def _GetCulpritInfoForTryJobResult(try_job_key, culprits_info): | |
| 19 point_build_keys = try_job_key.split('/') | |
|
stgao
2016/02/02 21:08:32
what does 'point build' mean? Referred build?
chanli
2016/02/02 22:18:12
Right.. Done.
| |
| 20 try_job = WfTryJob.Get( | |
| 21 point_build_keys[0], point_build_keys[1], point_build_keys[2]) | |
| 22 if try_job: | |
| 23 if try_job.compile_results: | |
| 24 try_job_result = try_job.compile_results[-1] | |
| 25 elif try_job.test_results: | |
| 26 try_job_result = try_job.test_results[-1] | |
| 27 else: | |
| 28 try_job_result = None | |
| 29 | |
| 30 for culprit_info in culprits_info.values(): | |
| 31 if culprit_info['try_job_key'] != try_job_key: | |
| 32 continue | |
| 33 | |
| 34 culprit_info['status'] = ( | |
| 35 wf_analysis_status.TRY_JOB_STATUS_TO_DESCRIPTION[try_job.status]) | |
| 36 | |
| 37 if try_job_result: | |
| 38 if try_job_result.get('url'): | |
| 39 culprit_info['try_job_url'] = try_job_result['url'] | |
| 40 culprit_info['try_job_build_number'] = ( | |
| 41 _GetTryJobBuildNumber(try_job_result['url'])) | |
| 42 if try_job_result.get('culprit'): | |
| 43 try_job_culprits = try_job_result['culprit'] | |
| 44 step = culprit_info['step'] | |
| 45 test = culprit_info['test'] | |
| 46 if step in try_job_culprits: # pragma: no cover | |
| 47 if not try_job_culprits[step].get('tests',{}): # Only step level | |
| 48 culprit = try_job_culprits[step] | |
| 49 elif test in try_job_culprits[step]['tests']: # pragma: no cover | |
| 50 culprit = try_job_culprits[step]['tests'][test] | |
| 51 | |
| 52 culprit_info['revision'] = culprit['revision'] | |
| 53 culprit_info['commit_position'] = culprit['commit_position'] | |
|
stgao
2016/02/02 21:08:32
IIRC, in the other CL, we might just provide the r
chanli
2016/02/02 22:18:12
Done.
| |
| 54 culprit_info['review_url'] = culprit['review_url'] | |
| 55 | |
| 56 | |
| 57 def _GetAllTryJobResults(master_name, builder_name, build_number): | |
| 58 culprits_info = {} | |
| 59 try_job_keys = [] | |
| 60 | |
| 15 analysis = WfAnalysis.Get(master_name, builder_name, build_number) | 61 analysis = WfAnalysis.Get(master_name, builder_name, build_number) |
| 16 if not analysis: | 62 if not analysis: |
| 17 return {} | 63 return culprits_info |
| 18 | 64 |
| 19 failure_result_map = analysis.failure_result_map | 65 failure_result_map = analysis.failure_result_map |
| 66 if failure_result_map: | |
| 67 for failed_step in failure_result_map: | |
| 68 if isinstance(failure_result_map[failed_step], dict): | |
| 69 for failed_test, try_job_key in ( | |
| 70 failure_result_map[failed_step].iteritems()): | |
| 71 step_test_key = '%s-%s' % (failed_step, failed_test) | |
| 72 culprits_info[step_test_key] = { | |
| 73 'step': failed_step, | |
| 74 'test': failed_test, | |
| 75 'try_job_key': try_job_key | |
| 76 } | |
| 77 if try_job_key not in try_job_keys: | |
| 78 try_job_keys.append(try_job_key) | |
| 79 else: | |
| 80 culprits_info[failed_step] = { | |
| 81 'step': failed_step, | |
| 82 'test': 'N/A', | |
| 83 'try_job_key': failure_result_map[failed_step] | |
| 84 } | |
| 85 if (failure_result_map[failed_step] not in | |
| 86 try_job_keys): # pragma: no cover | |
| 87 try_job_keys.append(failure_result_map[failed_step]) | |
| 20 | 88 |
| 21 if failure_result_map and failure_result_map.get('compile'): | 89 for try_job_key in try_job_keys: |
| 22 try_job_key = failure_result_map['compile'] | 90 _GetCulpritInfoForTryJobResult(try_job_key, culprits_info) |
| 23 point_build_keys = try_job_key.split('/') | |
| 24 try_job = WfTryJob.Get( | |
| 25 point_build_keys[0], point_build_keys[1], point_build_keys[2]) | |
| 26 if try_job: | |
| 27 try_job_result = {} | |
| 28 try_job_result['status'] = ( | |
| 29 wf_analysis_status.STATUS_TO_DESCRIPTION[try_job.status]) | |
| 30 if try_job.compile_results: | |
| 31 if try_job.compile_results[-1].get('culprit'): | |
| 32 culprit = try_job.compile_results[-1]['culprit'] | |
| 33 try_job_result['revision'] = culprit['revision'] | |
| 34 try_job_result['commit_position'] = culprit['commit_position'] | |
| 35 try_job_result['review_url'] = culprit['review_url'] | |
| 36 if try_job.compile_results[-1].get('url'): | |
| 37 try_job_result['try_job_url'] = try_job.compile_results[-1]['url'] | |
| 38 return try_job_result | |
| 39 | 91 |
| 40 return {} | 92 return culprits_info |
| 41 | 93 |
| 42 | 94 |
| 43 class TryJobResult(BaseHandler): | 95 class TryJobResult(BaseHandler): |
| 44 PERMISSION_LEVEL = Permission.ANYONE | 96 PERMISSION_LEVEL = Permission.ANYONE |
| 45 | 97 |
| 46 def HandleGet(self): | 98 def HandleGet(self): |
| 47 """Get the latest try job result if it's compile failure.""" | 99 """Get the latest try job result if it's compile failure.""" |
| 48 url = self.request.get('url').strip() | 100 url = self.request.get('url').strip() |
| 49 build_keys = buildbot.ParseBuildUrl(url) | 101 build_keys = buildbot.ParseBuildUrl(url) |
| 50 | 102 |
| 51 if not build_keys: # pragma: no cover | 103 if not build_keys: # pragma: no cover |
| 52 return {'data': {}} | 104 return {'data': {}} |
| 53 | 105 |
| 54 data = _GetTryJobResult(*build_keys) | 106 data = _GetAllTryJobResults(*build_keys) |
| 55 | 107 |
| 56 return {'data': data} | 108 return {'data': data} |
| 57 | 109 |
| 58 def HandlePost(self): # pragma: no cover | 110 def HandlePost(self): # pragma: no cover |
| 59 return self.HandleGet() | 111 return self.HandleGet() |
| OLD | NEW |