| 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): | 179 def ScheduleAnalysisForFlake(request, user_email, is_admin): |
| 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 | 186 |
| 187 Returns: | 187 Returns: |
| 188 True if an analysis was scheduled; False if a new analysis is not needed; | 188 True if an analysis was scheduled; False if a new analysis is not needed; |
| 189 None if the user has no permission to. | 189 None if the user has no permission to. |
| 190 """ | 190 """ |
| 191 assert len(request.build_steps) > 0, 'At least 1 build step is needed!' | 191 assert len(request.build_steps) > 0, 'At least 1 build step is needed!' |
| 192 | 192 |
| 193 if not is_admin and not _IsAuthorizedUser(user_email): | 193 if not IsAuthorizedUser(user_email, is_admin): |
| 194 return None | 194 return None |
| 195 request.user_emails = [user_email] | 195 request.user_emails = [user_email] |
| 196 | 196 |
| 197 manually_triggered = user_email.endswith('@google.com') | 197 manually_triggered = user_email.endswith('@google.com') |
| 198 | 198 |
| 199 for build_step in request.build_steps: | 199 for build_step in request.build_steps: |
| 200 step_mapper.FindMatchingWaterfallStep(build_step) | 200 step_mapper.FindMatchingWaterfallStep(build_step) |
| 201 | 201 |
| 202 version_number, build_step = _CheckForNewAnalysis(request) | 202 version_number, build_step = _CheckForNewAnalysis(request) |
| 203 if version_number and build_step: | 203 if version_number and build_step: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 217 request.put() | 217 request.put() |
| 218 logging.info('A new analysis was triggered successfully: %s', | 218 logging.info('A new analysis was triggered successfully: %s', |
| 219 analysis.key) | 219 analysis.key) |
| 220 return True | 220 return True |
| 221 else: | 221 else: |
| 222 logging.info('But no new analysis was not triggered!') | 222 logging.info('But no new analysis was not triggered!') |
| 223 else: | 223 else: |
| 224 logging.info('No new analysis is needed: %s', request) | 224 logging.info('No new analysis is needed: %s', request) |
| 225 | 225 |
| 226 return False | 226 return False |
| OLD | NEW |