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

Side by Side Diff: appengine/findit/crash/findit_for_client.py

Issue 2414523002: [Findit] Reorganizing findit_for_*.py (Closed)
Patch Set: Finally fixed the mock tests! Created 4 years, 1 month 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
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """This module is interfacas between clients-specific code and core.
6
7 Note, fracas and cracas are almost identical and fracas is an intermidiate
8 state while transfering to cracas, so they can be handled in the same code path
9 and can be referred to as chromecrash."""
10
11 import copy
12 import json
13 import logging
14
15 from google.appengine.ext import ndb
16
17 from common import appengine_util
18 from common import time_util
19 from crash import detect_regression_range
20 from crash import findit_for_chromecrash
21 from crash.type_enums import CrashClient
22 from model import analysis_status
23 from model.crash.crash_config import CrashConfig
24 from model.crash.fracas_crash_analysis import FracasCrashAnalysis
25 from model.crash.cracas_crash_analysis import CracasCrashAnalysis
26
27 # TODO(katesonia): Move this to fracas config.
28 _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE = '%s/crash/fracas-result-feedback?key=%s'
29 # TODO(katesonia): Move this to a common config in config page.
30 _SUPPORTED_CLIENTS = [CrashClient.FRACAS, CrashClient.CRACAS]
31
32
33 def CheckPolicyForClient(crash_identifiers, chrome_version, signature,
34 client_id, platform, stack_trace, customized_data):
35 """Checks if args pass client policy and updates parameters."""
36 if client_id not in _SUPPORTED_CLIENTS:
37 logging.info('Client %s is not supported by findit right now', client_id)
38 return False, None
39
40 config = CrashConfig.Get().GetClientConfig(client_id)
41 # Cracas and Fracas share the sampe policy.
42 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS:
43 channel = customized_data.get('channel')
44 # TODO(katesonia): Remove the default value after adding validity check to
45 # config.
46 if platform not in config.get(
47 'supported_platform_list_by_channel', {}).get(channel, []):
48 # Bail out if either the channel or platform is not supported yet.
49 logging.info('Ananlysis of channel %s, platform %s is not supported. '
50 'No analysis is scheduled for %s',
51 channel, platform, repr(crash_identifiers))
52 return False, None
53
54 # TODO(katesonia): Remove the default value after adding validity check to
55 # config.
56 for blacklist_marker in config.get('signature_blacklist_markers', []):
57 if blacklist_marker in signature:
58 logging.info('%s signature is not supported. '
59 'No analysis is scheduled for %s', blacklist_marker,
60 repr(crash_identifiers))
61 return False, None
62
63 # TODO(katesonia): Remove the default value after adding validity check to
64 # config.
65 platform_rename = config.get('platform_rename', {})
66 platform = platform_rename.get(platform, platform)
67
68 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
69 # TODO(katesonia): Add clusterfuzz policy check.
70 pass
71
72 return True, (crash_identifiers, chrome_version, signature, client_id,
73 platform, stack_trace, customized_data)
74
75
76 def GetAnalysisForClient(crash_identifiers, client_id):
77 """Gets analysis entity based on client id."""
78 if client_id == CrashClient.FRACAS:
79 return FracasCrashAnalysis.Get(crash_identifiers)
80 elif client_id == CrashClient.CRACAS: # pragma: no cover.
81 return CracasCrashAnalysis.Get(crash_identifiers)
82 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
83 # TODO(katesonia): Add ClusterfuzzCrashAnalysis model.
84 return None
85
86 return None
87
88
89 def CreateAnalysisForClient(crash_identifiers, client_id):
90 """Creates analysis entity based on client id."""
91 if client_id == CrashClient.FRACAS:
92 return FracasCrashAnalysis.Create(crash_identifiers)
93 elif client_id == CrashClient.CRACAS: # pragma: no cover.
94 return CracasCrashAnalysis.Create(crash_identifiers)
95 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
96 # TODO(katesonia): define ClusterfuzzCrashAnalysis.
97 return None
98
99 return None
100
101
102 def ResetAnalysis(analysis, chrome_version, signature,
103 client_id, platform, stack_trace, customized_data,
104 regression_range):
105 """Sets necessary info in the analysis for findit to run analysis."""
106 analysis.Reset()
107
108 # Set common properties.
109 analysis.crashed_version = chrome_version
110 analysis.stack_trace = stack_trace
111 analysis.signature = signature
112 analysis.platform = platform
113 analysis.client_id = client_id
114 analysis.regression_range = regression_range
115
116 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS:
117 # Set customized properties.
118 analysis.historical_metadata = customized_data.get('historical_metadata')
119 analysis.channel = customized_data.get('channel')
120 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
121 # TODO(katesonia): Set up clusterfuzz customized data.
122 pass
123
124 # Set analysis progress properties.
125 analysis.status = analysis_status.PENDING
126 analysis.requested_time = time_util.GetUTCNow()
127
128 analysis.put()
129
130
131 def GetPublishResultFromAnalysis(analysis, crash_identifiers, client_id):
132 """Gets result to be published to client from datastore analysis."""
133 analysis_result = copy.deepcopy(analysis.result)
134
135 if (analysis.client_id == CrashClient.FRACAS or
136 analysis.client_id == CrashClient.CRACAS):
137 analysis_result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % (
138 appengine_util.GetDefaultVersionHostname(), analysis.key.urlsafe())
139 if analysis_result['found']:
140 for cl in analysis_result['suspected_cls']:
141 cl['confidence'] = round(cl['confidence'], 2)
142 cl.pop('reason', None)
143 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
144 # TODO(katesonia): Post process clusterfuzz analysis result if needed.
145 pass
146
147 return {
148 'crash_identifiers': crash_identifiers,
149 'client_id': analysis.client_id,
150 'result': analysis_result,
151 }
152
153
154 def GetRegressionRange(client_id, customized_data):
155 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS:
156 return detect_regression_range.DetectRegressionRange(
157 customized_data.get('historical_metadata'))
158 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
159 # TODO(katesonia): Get regression range from customized_data from
160 # clusterfuzz.
161 return None
162
163 return None
164
165
166 def FindCulprit(analysis, repository):
167 if (analysis.client_id == CrashClient.FRACAS or
168 analysis.client_id == CrashClient.CRACAS):
169 return findit_for_chromecrash.FinditForChromeCrash(repository).FindCulprit(
170 analysis.signature, analysis.platform, analysis.stack_trace,
171 analysis.crashed_version, analysis.regression_range)
172 elif analysis.client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
173 # TODO(katesonia): Implement findit_for_clusterfuzz.
174 return {}, {}
175
176 return {'found': False}, {'found_suspects': False,
177 'has_regression_range': False}
OLDNEW
« no previous file with comments | « appengine/findit/crash/findit_for_chromecrash.py ('k') | appengine/findit/crash/findit_for_clusterfuzz.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698