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 referred_build_keys = try_job_key.split('/') | |
| 20 try_job = WfTryJob.Get( | |
| 21 referred_build_keys[0], referred_build_keys[1], referred_build_keys[2]) | |
|
qyearsley
2016/02/03 18:38:28
Nit: indent should be 4 spaces
Also, if referred_
chanli
2016/02/03 19:24:42
Done.
| |
| 22 if try_job: | |
|
lijeffrey
2016/02/03 06:08:37
nit: maybe to make this slightly more readable do
chanli
2016/02/03 19:20:27
Done.
| |
| 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 | |
|
lijeffrey
2016/02/03 06:08:37
is it possible to make a test that covers this?
chanli
2016/02/03 19:20:27
This line has been removed since it'll never be re
| |
| 47 if not try_job_culprits[step].get('tests',{}): # Only step level | |
|
lijeffrey
2016/02/03 06:08:37
nit: whitespace 'tests', {}
chanli
2016/02/03 19:20:27
Done.
| |
| 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'] | |
|
lijeffrey
2016/02/03 06:08:37
nit: since the others are using .get, why not use
qyearsley
2016/02/03 18:38:28
Is "revision" required (cannot be None) and the ot
chanli
2016/02/03 19:20:27
This change is actually optional because revision
chanli
2016/02/03 19:24:42
It's actually more of culprit is created only when
| |
| 53 culprit_info['commit_position'] = culprit.get('commit_position') | |
| 54 culprit_info['review_url'] = culprit.get('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: |
|
lijeffrey
2016/02/03 06:08:37
nit: why not keep this the same, then declare culp
chanli
2016/02/03 19:20:27
To be consistent with below, I'm returning culprit
| |
| 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 # failure_result_map uses step_names as keys and save referred_try_job_keys. | |
|
lijeffrey
2016/02/03 06:08:37
nit: saves
lijeffrey
2016/02/03 06:08:37
what's referred_try_job_key?
chanli
2016/02/03 19:20:27
Done.
chanli
2016/02/03 19:20:27
Is 'referred try_job_key' better? Basically it is
| |
| 68 # If non-swarming, step_name and referred_try_job_key matches directly as: | |
|
lijeffrey
2016/02/03 06:08:37
nit: match
chanli
2016/02/03 19:20:27
Done.
| |
| 69 # step_name: try_job_key | |
| 70 # If swarming, add one more layer of tests, so the format would be: | |
| 71 # step_name: { | |
| 72 # test_name1: try_job_key1, | |
| 73 # test_name2: try_job_key2, | |
| 74 # ... | |
| 75 # } | |
| 76 for failed_step in failure_result_map: | |
| 77 if isinstance(failure_result_map[failed_step], dict): | |
| 78 for failed_test, try_job_key in ( | |
| 79 failure_result_map[failed_step].iteritems()): | |
| 80 step_test_key = '%s-%s' % (failed_step, failed_test) | |
| 81 culprits_info[step_test_key] = { | |
| 82 'step': failed_step, | |
| 83 'test': failed_test, | |
| 84 'try_job_key': try_job_key | |
| 85 } | |
| 86 if try_job_key not in try_job_keys: | |
| 87 try_job_keys.append(try_job_key) | |
| 88 else: | |
| 89 culprits_info[failed_step] = { | |
| 90 'step': failed_step, | |
| 91 'test': 'N/A', | |
| 92 'try_job_key': failure_result_map[failed_step] | |
| 93 } | |
| 94 if (failure_result_map[failed_step] not in | |
| 95 try_job_keys): # pragma: no cover | |
| 96 try_job_keys.append(failure_result_map[failed_step]) | |
| 20 | 97 |
| 21 if failure_result_map and failure_result_map.get('compile'): | 98 for try_job_key in try_job_keys: |
| 22 try_job_key = failure_result_map['compile'] | 99 _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 | 100 |
| 40 return {} | 101 return culprits_info |
| 41 | 102 |
| 42 | 103 |
| 43 class TryJobResult(BaseHandler): | 104 class TryJobResult(BaseHandler): |
| 44 PERMISSION_LEVEL = Permission.ANYONE | 105 PERMISSION_LEVEL = Permission.ANYONE |
| 45 | 106 |
| 46 def HandleGet(self): | 107 def HandleGet(self): |
| 47 """Get the latest try job result if it's compile failure.""" | 108 """Get the latest try job result if it's compile failure.""" |
| 48 url = self.request.get('url').strip() | 109 url = self.request.get('url').strip() |
| 49 build_keys = buildbot.ParseBuildUrl(url) | 110 build_keys = buildbot.ParseBuildUrl(url) |
| 50 | 111 |
| 51 if not build_keys: # pragma: no cover | 112 if not build_keys: # pragma: no cover |
| 52 return {'data': {}} | 113 return {'data': {}} |
| 53 | 114 |
| 54 data = _GetTryJobResult(*build_keys) | 115 data = _GetAllTryJobResults(*build_keys) |
| 55 | 116 |
| 56 return {'data': data} | 117 return {'data': data} |
| 57 | 118 |
| 58 def HandlePost(self): # pragma: no cover | 119 def HandlePost(self): # pragma: no cover |
| 59 return self.HandleGet() | 120 return self.HandleGet() |
| OLD | NEW |