| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return request.version_number, supported_build_step | 162 return request.version_number, supported_build_step |
| 163 else: | 163 else: |
| 164 # If no bug is attached to the previous analysis or the new request, or both | 164 # If no bug is attached to the previous analysis or the new request, or both |
| 165 # are attached to the same bug, start a new analysis with a different | 165 # are attached to the same bug, start a new analysis with a different |
| 166 # configuration. For a configuration that was analyzed 7 days ago, reset it | 166 # configuration. For a configuration that was analyzed 7 days ago, reset it |
| 167 # to use the new reported step of the same configuration. | 167 # to use the new reported step of the same configuration. |
| 168 # TODO: move this setting to config. | 168 # TODO: move this setting to config. |
| 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, is_admin): |
| 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 is_admin or (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, triggering_source): | 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 | 186 triggering_source (int): Where the request is coming from, either Findit |
| 187 UI (check flake page), pipeline (from analysis) or Findit API. | 187 UI (check flake page), pipeline (from analysis) or Findit API. |
| 188 | 188 |
| 189 Returns: | 189 Returns: |
| 190 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; |
| 191 None if the user has no permission to. | 191 None if the user has no permission to. |
| 192 """ | 192 """ |
| 193 assert len(request.build_steps), 'At least 1 build step is needed!' | 193 assert len(request.build_steps), 'At least 1 build step is needed!' |
| 194 | 194 |
| 195 if not is_admin and not _IsAuthorizedUser(user_email): | 195 if not IsAuthorizedUser(user_email, is_admin): |
| 196 return None | 196 return None |
| 197 request.user_emails = [user_email] | 197 request.user_emails = [user_email] |
| 198 | 198 |
| 199 manually_triggered = user_email.endswith('@google.com') | 199 manually_triggered = user_email.endswith('@google.com') |
| 200 | 200 |
| 201 for build_step in request.build_steps: | 201 for build_step in request.build_steps: |
| 202 step_mapper.FindMatchingWaterfallStep(build_step) | 202 step_mapper.FindMatchingWaterfallStep(build_step) |
| 203 | 203 |
| 204 version_number, build_step = _CheckForNewAnalysis(request) | 204 version_number, build_step = _CheckForNewAnalysis(request) |
| 205 if version_number and build_step: | 205 if version_number and build_step: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 request.put() | 220 request.put() |
| 221 logging.info('A new analysis was triggered successfully: %s', | 221 logging.info('A new analysis was triggered successfully: %s', |
| 222 analysis.key) | 222 analysis.key) |
| 223 return True | 223 return True |
| 224 else: | 224 else: |
| 225 logging.error('But new analysis was not triggered!') | 225 logging.error('But new analysis was not triggered!') |
| 226 else: | 226 else: |
| 227 logging.info('No new analysis is needed: %s', request) | 227 logging.info('No new analysis is needed: %s', request) |
| 228 | 228 |
| 229 return False | 229 return False |
| OLD | NEW |