| OLD | NEW |
| (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 from datetime import datetime |
| 6 |
| 7 from google.appengine.ext import ndb |
| 8 |
| 9 from common import appengine_util |
| 10 from common import constants |
| 11 from model import analysis_status |
| 12 from model.flake.flake_swarming_task import FlakeSwarmingTask |
| 13 from model.flake.master_flake_analysis import MasterFlakeAnalysis |
| 14 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline |
| 15 |
| 16 |
| 17 @ndb.transactional |
| 18 def NeedANewAnalysis( |
| 19 master_name, builder_name, build_number, step_name, test_name): |
| 20 """Checks status of analysis for the test and decides if a new one is needed. |
| 21 |
| 22 A MasterFlakeAnalysis entity for the given parameters will be created if none |
| 23 exists. When a new analysis is needed, this function will create and |
| 24 save a MasterFlakeAnalysis entity to the datastore. |
| 25 |
| 26 Returns: |
| 27 True if an analysis is needed, otherwise False. |
| 28 """ |
| 29 master_flake_analysis = MasterFlakeAnalysis.Get( |
| 30 master_name, builder_name, build_number,step_name, test_name) |
| 31 |
| 32 if not master_flake_analysis: |
| 33 master_flake_analysis = MasterFlakeAnalysis.Create( |
| 34 master_name, builder_name, build_number, step_name, test_name) |
| 35 master_flake_analysis.status = analysis_status.PENDING |
| 36 master_flake_analysis.put() |
| 37 return True |
| 38 elif (master_flake_analysis.status == analysis_status.COMPLETED or |
| 39 master_flake_analysis.status == analysis_status.PENDING or |
| 40 master_flake_analysis.status == analysis_status.RUNNING): |
| 41 return False |
| 42 else: |
| 43 # TODO(caiw): Reset method. |
| 44 MasterFlakeAnalysis.Get( |
| 45 master_name, builder_name, build_number, |
| 46 step_name, test_name).key.delete() |
| 47 master_flake_analysis = MasterFlakeAnalysis.Create( |
| 48 master_name, builder_name, build_number, step_name, test_name) |
| 49 master_flake_analysis.status = analysis_status.PENDING |
| 50 master_flake_analysis.put() |
| 51 return True |
| 52 |
| 53 # Unused arguments - pylint: disable=W0612, W0613 |
| 54 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, |
| 55 test_name, force=False, |
| 56 queue_name=constants.DEFAULT_QUEUE): |
| 57 """Schedules an analysis if needed and returns the MasterFlakeAnalysis. |
| 58 |
| 59 When the build failure was already analyzed and a new analysis is scheduled, |
| 60 the returned WfAnalysis will still have the result of last completed analysis. |
| 61 |
| 62 Args: |
| 63 master_name (str): The master name of the failed test |
| 64 builder_name (str): The builder name of the failed test |
| 65 build_number (int): The build number of the failed test |
| 66 step_name (str): The name of the test suite |
| 67 test_name (str): The single test we are checking |
| 68 |
| 69 Returns: |
| 70 A MasterFlakeAnalysis instance. |
| 71 """ |
| 72 if NeedANewAnalysis( |
| 73 master_name, builder_name, build_number, step_name, test_name): |
| 74 pipeline_job = RecursiveFlakePipeline( |
| 75 master_name, builder_name, build_number, step_name, test_name, |
| 76 master_build_number=build_number) |
| 77 pipeline_job.target = appengine_util.GetTargetNameForModule( |
| 78 constants.WATERFALL_BACKEND) |
| 79 pipeline_job.start(queue_name=queue_name) |
| 80 return MasterFlakeAnalysis.Get( |
| 81 master_name, builder_name, build_number, step_name, test_name) |
| OLD | NEW |