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