Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: appengine/findit/waterfall/build_failure_analysis_pipelines.py

Issue 2158533002: [Findit] Use unittest.mock for testing and create a shared method to mock pipeline. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 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 from datetime import datetime 5 from datetime import datetime
6 import logging 6 import logging
7 7
8 from google.appengine.ext import ndb 8 from google.appengine.ext import ndb
9 9
10 from common import appengine_util 10 from common import appengine_util
11 from common import constants 11 from common import constants
12 from model import analysis_status 12 from model import analysis_status
13 from model.wf_analysis import WfAnalysis 13 from model.wf_analysis import WfAnalysis
14 from waterfall import analyze_build_failure_pipeline 14 from waterfall.analyze_build_failure_pipeline import AnalyzeBuildFailurePipeline
15 15
16 16
17 @ndb.transactional 17 @ndb.transactional
18 def NeedANewAnalysis( 18 def NeedANewAnalysis(
19 master_name, builder_name, build_number, failed_steps, 19 master_name, builder_name, build_number, failed_steps,
20 build_completed, force): 20 build_completed, force):
21 """Checks status of analysis for the build and decides if a new one is needed. 21 """Checks status of analysis for the build and decides if a new one is needed.
22 22
23 A WfAnalysis entity for the given build will be created if none exists. 23 A WfAnalysis entity for the given build will be created if none exists.
24 When a new analysis is needed, this function will create and save a WfAnalysis 24 When a new analysis is needed, this function will create and save a WfAnalysis
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 force_try_job (bool): Indicate whether or not a try job should be run or 94 force_try_job (bool): Indicate whether or not a try job should be run or
95 rerun as long as a corresponding try bot is configured. 95 rerun as long as a corresponding try bot is configured.
96 queue_name (str): The task queue to be used for pipeline tasks. 96 queue_name (str): The task queue to be used for pipeline tasks.
97 97
98 Returns: 98 Returns:
99 A WfAnalysis instance. 99 A WfAnalysis instance.
100 """ 100 """
101 if NeedANewAnalysis( 101 if NeedANewAnalysis(
102 master_name, builder_name, build_number, failed_steps, 102 master_name, builder_name, build_number, failed_steps,
103 build_completed, force): 103 build_completed, force):
104 pipeline_job = analyze_build_failure_pipeline.AnalyzeBuildFailurePipeline( 104 pipeline_job = AnalyzeBuildFailurePipeline(
105 master_name, builder_name, build_number, build_completed, 105 master_name, builder_name, build_number, build_completed,
106 force_try_job) 106 force_try_job)
107 # Explicitly run analysis in the backend module "waterfall-backend". 107 # Explicitly run analysis in the backend module "waterfall-backend".
108 # Note: Just setting the target in queue.yaml does NOT work for pipeline 108 # Note: Just setting the target in queue.yaml does NOT work for pipeline
109 # when deployed to App Engine, but it does work in dev-server locally. 109 # when deployed to App Engine, but it does work in dev-server locally.
110 # A possible reason is that pipeline will pick a default target if none is 110 # A possible reason is that pipeline will pick a default target if none is
111 # specified explicitly, and the default target is used rather than the one 111 # specified explicitly, and the default target is used rather than the one
112 # in the queue.yaml file, but this contradicts the documentation in 112 # in the queue.yaml file, but this contradicts the documentation in
113 # https://cloud.google.com/appengine/docs/python/taskqueue/tasks#Task. 113 # https://cloud.google.com/appengine/docs/python/taskqueue/tasks#Task.
114 pipeline_job.target = appengine_util.GetTargetNameForModule( 114 pipeline_job.target = appengine_util.GetTargetNameForModule(
115 constants.WATERFALL_BACKEND) 115 constants.WATERFALL_BACKEND)
116 pipeline_job.start(queue_name=queue_name) 116 pipeline_job.start(queue_name=queue_name)
117 117
118 logging.info('An analysis was scheduled for build %s, %s, %s: %s', 118 logging.info('An analysis was scheduled for build %s, %s, %s: %s',
119 master_name, builder_name, build_number, 119 master_name, builder_name, build_number,
120 pipeline_job.pipeline_status_path()) 120 pipeline_job.pipeline_status_path())
121 121
122 return WfAnalysis.Get(master_name, builder_name, build_number) 122 return WfAnalysis.Get(master_name, builder_name, build_number)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698