| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 import logging | 5 import logging |
| 6 | 6 |
| 7 from common import constants | 7 from common import constants |
| 8 from model.flake.flake_analysis_request import FlakeAnalysisRequest | 8 from model.flake.flake_analysis_request import FlakeAnalysisRequest |
| 9 from waterfall.flake import initialize_flake_pipeline | 9 from waterfall.flake import initialize_flake_pipeline |
| 10 from waterfall.flake import step_mapper | 10 from waterfall.flake import step_mapper |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 return _MergeNewRequestIntoExistingOne(request, previous_request) | 169 return _MergeNewRequestIntoExistingOne(request, previous_request) |
| 170 | 170 |
| 171 | 171 |
| 172 def _IsAuthorizedUser(user_email): | 172 def _IsAuthorizedUser(user_email): |
| 173 """Returns True if the given user email account is authorized for access.""" | 173 """Returns True if the given user email account is authorized for access.""" |
| 174 return user_email and ( | 174 return user_email and ( |
| 175 user_email in constants.WHITELISTED_APP_ACCOUNTS or | 175 user_email in constants.WHITELISTED_APP_ACCOUNTS or |
| 176 user_email.endswith('@google.com')) | 176 user_email.endswith('@google.com')) |
| 177 | 177 |
| 178 | 178 |
| 179 def ScheduleAnalysisForFlake(request, user_email, is_admin): | 179 def ScheduleAnalysisForFlake(request, user_email, is_admin, triggering_source): |
| 180 """Schedules an analysis on the flake in the given request if needed. | 180 """Schedules an analysis on the flake in the given request if needed. |
| 181 | 181 |
| 182 Args: | 182 Args: |
| 183 request (FlakeAnalysisRequest): The request to analyze a flake. | 183 request (FlakeAnalysisRequest): The request to analyze a flake. |
| 184 user_email (str): The email of the requester. | 184 user_email (str): The email of the requester. |
| 185 is_admin (bool): Whether the requester is an admin. | 185 is_admin (bool): Whether the requester is an admin. |
| 186 triggering_source (int): Where the request is coming from, either Findit |
| 187 UI (check flake page), pipeline (from analysis) or Findit API. |
| 186 | 188 |
| 187 Returns: | 189 Returns: |
| 188 True if an analysis was scheduled; False if a new analysis is not needed; | 190 True if an analysis was scheduled; False if a new analysis is not needed; |
| 189 None if the user has no permission to. | 191 None if the user has no permission to. |
| 190 """ | 192 """ |
| 191 assert len(request.build_steps) > 0, 'At least 1 build step is needed!' | 193 assert len(request.build_steps), 'At least 1 build step is needed!' |
| 192 | 194 |
| 193 if not is_admin and not _IsAuthorizedUser(user_email): | 195 if not is_admin and not _IsAuthorizedUser(user_email): |
| 194 return None | 196 return None |
| 195 request.user_emails = [user_email] | 197 request.user_emails = [user_email] |
| 196 | 198 |
| 197 manually_triggered = user_email.endswith('@google.com') | 199 manually_triggered = user_email.endswith('@google.com') |
| 198 | 200 |
| 199 for build_step in request.build_steps: | 201 for build_step in request.build_steps: |
| 200 step_mapper.FindMatchingWaterfallStep(build_step) | 202 step_mapper.FindMatchingWaterfallStep(build_step) |
| 201 | 203 |
| 202 version_number, build_step = _CheckForNewAnalysis(request) | 204 version_number, build_step = _CheckForNewAnalysis(request) |
| 203 if version_number and build_step: | 205 if version_number and build_step: |
| 204 # A new analysis is needed. | 206 # A new analysis is needed. |
| 205 logging.info('A new analysis is needed for: %s', build_step) | 207 logging.info('A new analysis is needed for: %s', build_step) |
| 206 analysis = initialize_flake_pipeline.ScheduleAnalysisIfNeeded( | 208 analysis = initialize_flake_pipeline.ScheduleAnalysisIfNeeded( |
| 207 build_step.wf_master_name, build_step.wf_builder_name, | 209 build_step.wf_master_name, build_step.wf_builder_name, |
| 208 build_step.wf_build_number, build_step.wf_step_name, | 210 build_step.wf_build_number, build_step.wf_step_name, |
| 209 request.name, allow_new_analysis=True, | 211 request.name, allow_new_analysis=True, |
| 210 manually_triggered=manually_triggered, | 212 manually_triggered=manually_triggered, user_email=user_email, |
| 213 triggering_source=triggering_source, |
| 211 queue_name=constants.WATERFALL_ANALYSIS_QUEUE) | 214 queue_name=constants.WATERFALL_ANALYSIS_QUEUE) |
| 212 if analysis: | 215 if analysis: |
| 213 # TODO: put this in a transaction. | 216 # TODO: put this in a transaction. |
| 214 request = FlakeAnalysisRequest.GetVersion( | 217 request = FlakeAnalysisRequest.GetVersion( |
| 215 key=request.name, version=version_number) | 218 key=request.name, version=version_number) |
| 216 request.analyses.append(analysis.key) | 219 request.analyses.append(analysis.key) |
| 217 request.put() | 220 request.put() |
| 218 logging.info('A new analysis was triggered successfully: %s', | 221 logging.info('A new analysis was triggered successfully: %s', |
| 219 analysis.key) | 222 analysis.key) |
| 220 return True | 223 return True |
| 221 else: | 224 else: |
| 222 logging.info('But no new analysis was not triggered!') | 225 logging.error('But new analysis was not triggered!') |
| 223 else: | 226 else: |
| 224 logging.info('No new analysis is needed: %s', request) | 227 logging.info('No new analysis is needed: %s', request) |
| 225 | 228 |
| 226 return False | 229 return False |
| OLD | NEW |