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

Side by Side Diff: appengine/findit/waterfall/identify_try_job_culprit_pipeline.py

Issue 1622813003: [Findit] Adding support for extracting revisions from dict instead of list (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 11 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 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 def _getFailedRevisionFromResultsDict(self, results_dict):
qyearsley 2016/01/24 21:01:06 Nit: In Chromium style, function names start with
lijeffrey 2016/01/26 00:34:52 Done.
16 """Finds the failed revision from the given dict of revisions.
17
18 Args:
19 results_dict: (dict) A dict that maps revisions to their results. For
20 example:
21
22 {
23 'rev1': 'passed',
24 'rev2': 'passed',
25 'rev3': 'failed',
26 }
27
28 Note results_dict is expected only to have one failed revision which
29 will be the one to be returned.
30
31 Returns:
32 The revision corresponding to a failed result, if any.
qyearsley 2016/01/24 21:01:05 Nit: Only need two spaces of indentation for Args
lijeffrey 2016/01/26 00:34:52 Done.
33 """
34 for revision, result in results_dict.iteritems():
35 if result.lower() == 'failed':
36 return revision
37 return None
38
15 # Arguments number differs from overridden method - pylint: disable=W0221 39 # Arguments number differs from overridden method - pylint: disable=W0221
16 def run( 40 def run(
17 self, master_name, builder_name, build_number, try_job_id, 41 self, master_name, builder_name, build_number, try_job_id,
18 compile_result): 42 compile_result):
19 culprit = None 43 culprit = None
20 44
21 if compile_result and len(compile_result.get('result', [])) > 0: 45 if compile_result:
22 # For compile failures, the try job will stop if one revision fails, so 46 failed_revision = None
23 # the culprit will be the last revision in the result. 47 result_list = compile_result.get('result')
24 result_for_last_checked_revision = compile_result['result'][-1] 48 if result_list and isinstance(result_list, list):
25 failed_revision = ( 49 # TODO(lijeffrey): The format for the result of the compile will change
26 result_for_last_checked_revision[0] if 50 # from a list to a dict. This branch is for backwards compatibility and
27 result_for_last_checked_revision[1].lower() == 'failed' else None) 51 # should be removed once result is returned as a dict from the compile
52 # recipe. The test recipe may need to be considered as well.
53
54 # For compile failures, the try job will stop if one revision fails, so
55 # the culprit will be the last revision in the result.
56 result_for_last_checked_revision = compile_result['result'][-1]
57 failed_revision = (
58 result_for_last_checked_revision[0] if
59 result_for_last_checked_revision[1].lower() == 'failed' else None)
60 elif isinstance(compile_result.get('analysis_info'), dict):
61 revision_results = compile_result.get(
62 'analysis_info', {}).get('result', {})
63 failed_revision = self._getFailedRevisionFromResultsDict(
64 revision_results)
stgao 2016/01/25 19:19:52 How about moving lines #46 - #64 into the new func
lijeffrey 2016/01/26 00:34:52 Done.
28 65
29 if failed_revision: 66 if failed_revision:
30 git_repo = GitRepository( 67 git_repo = GitRepository(
31 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) 68 'https://chromium.googlesource.com/chromium/src.git',
69 HttpClient())
lijeffrey 2016/01/23 02:24:09 oops I'll put this back
lijeffrey 2016/01/26 00:34:52 Done.
32 change_log = git_repo.GetChangeLog(failed_revision) 70 change_log = git_repo.GetChangeLog(failed_revision)
33 if change_log: 71 if change_log:
34 culprit = { 72 culprit = {
35 'revision': failed_revision, 73 'revision': failed_revision,
36 'commit_position': change_log.commit_position, 74 'commit_position': change_log.commit_position,
37 'review_url': change_log.code_review_url 75 'review_url': change_log.code_review_url
38 } 76 }
39 compile_result['culprit'] = culprit 77 compile_result['culprit'] = culprit
qyearsley 2016/01/24 21:01:06 This section (inside `if compile_result`) could po
lijeffrey 2016/01/26 00:34:52 Done.
40 78
41 # Store try job results. 79 # Store try job results.
42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) 80 try_job_result = WfTryJob.Get(master_name, builder_name, build_number)
43 if culprit: 81 if culprit:
44 if (try_job_result.compile_results and 82 if (try_job_result.compile_results and
45 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): 83 try_job_result.compile_results[-1]['try_job_id'] == try_job_id):
46 try_job_result.compile_results[-1].update(compile_result) 84 try_job_result.compile_results[-1].update(compile_result)
47 else: # pragma: no cover 85 else: # pragma: no cover
48 try_job_result.compile_results.append(compile_result) 86 try_job_result.compile_results.append(compile_result)
49 87
50 try_job_result.status = wf_analysis_status.ANALYZED 88 try_job_result.status = wf_analysis_status.ANALYZED
51 try_job_result.put() 89 try_job_result.put()
52 90
53 return culprit 91 return culprit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698