Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: appengine/findit/handlers/try_job_result.py

Issue 1652603003: [Findit] Modify result page to display tryjob result for test failure. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@1228-try-job-pipeline-for-test-failure
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(*referred_build_keys)
21 if not try_job:
22 return
23
24 if try_job.compile_results:
25 try_job_result = try_job.compile_results[-1]
26 elif try_job.test_results:
27 try_job_result = try_job.test_results[-1]
28 else:
29 try_job_result = None
30
31 for culprit_info in culprits_info.values():
32 if culprit_info['try_job_key'] != try_job_key:
33 continue
34
35 culprit_info['status'] = (
36 wf_analysis_status.TRY_JOB_STATUS_TO_DESCRIPTION[try_job.status])
37
38 if try_job_result:
39 if try_job_result.get('url'):
40 culprit_info['try_job_url'] = try_job_result['url']
41 culprit_info['try_job_build_number'] = (
42 _GetTryJobBuildNumber(try_job_result['url']))
43 if try_job_result.get('culprit'):
44 try_job_culprits = try_job_result['culprit']
45 step = culprit_info['step']
46 test = culprit_info['test']
47 if not try_job_culprits.get(step, {}).get('tests'):
48 # Only step level
49 culprit = try_job_culprits[step]
50 elif test in try_job_culprits.get(step).get('tests'):
51 culprit = try_job_culprits[step]['tests'][test]
52 else: # pragma: no cover
53 continue # No culprit for test found.
54
55 culprit_info['revision'] = culprit.get('revision')
56 culprit_info['commit_position'] = culprit.get('commit_position')
57 culprit_info['review_url'] = culprit.get('review_url')
58
59
60 def _GetAllTryJobResults(master_name, builder_name, build_number):
61 culprits_info = {}
62 try_job_keys = []
63
15 analysis = WfAnalysis.Get(master_name, builder_name, build_number) 64 analysis = WfAnalysis.Get(master_name, builder_name, build_number)
16 if not analysis: 65 if not analysis:
17 return {} 66 return culprits_info
18 67
19 failure_result_map = analysis.failure_result_map 68 failure_result_map = analysis.failure_result_map
69 if failure_result_map:
70 # failure_result_map uses step_names as keys and saves referred try_job_keys
71 # If non-swarming, step_name and referred_try_job_key match directly as:
72 # step_name: try_job_key
73 # If swarming, add one more layer of tests, so the format would be:
74 # step_name: {
75 # test_name1: try_job_key1,
76 # test_name2: try_job_key2,
77 # ...
78 # }
79 for failed_step in failure_result_map:
80 if isinstance(failure_result_map[failed_step], dict):
81 for failed_test, try_job_key in (
82 failure_result_map[failed_step].iteritems()):
83 step_test_key = '%s-%s' % (failed_step, failed_test)
84 culprits_info[step_test_key] = {
85 'step': failed_step,
86 'test': failed_test,
87 'try_job_key': try_job_key
88 }
89 if try_job_key not in try_job_keys:
90 try_job_keys.append(try_job_key)
91 else:
92 culprits_info[failed_step] = {
93 'step': failed_step,
94 'test': 'N/A',
95 'try_job_key': failure_result_map[failed_step]
96 }
97 if (failure_result_map[failed_step] not in
98 try_job_keys): # pragma: no cover
99 try_job_keys.append(failure_result_map[failed_step])
20 100
21 if failure_result_map and failure_result_map.get('compile'): 101 for try_job_key in try_job_keys:
22 try_job_key = failure_result_map['compile'] 102 _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 103
40 return {} 104 return culprits_info
41 105
42 106
43 class TryJobResult(BaseHandler): 107 class TryJobResult(BaseHandler):
44 PERMISSION_LEVEL = Permission.ANYONE 108 PERMISSION_LEVEL = Permission.ANYONE
45 109
46 def HandleGet(self): 110 def HandleGet(self):
47 """Get the latest try job result if it's compile failure.""" 111 """Get the latest try job result if it's compile failure."""
48 url = self.request.get('url').strip() 112 url = self.request.get('url').strip()
49 build_keys = buildbot.ParseBuildUrl(url) 113 build_keys = buildbot.ParseBuildUrl(url)
50 114
51 if not build_keys: # pragma: no cover 115 if not build_keys: # pragma: no cover
52 return {'data': {}} 116 return {'data': {}}
53 117
54 data = _GetTryJobResult(*build_keys) 118 data = _GetAllTryJobResults(*build_keys)
55 119
56 return {'data': data} 120 return {'data': data}
57 121
58 def HandlePost(self): # pragma: no cover 122 def HandlePost(self): # pragma: no cover
59 return self.HandleGet() 123 return self.HandleGet()
OLDNEW
« no previous file with comments | « appengine/findit/handlers/test/try_job_result_test.py ('k') | appengine/findit/model/wf_analysis_status.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698