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

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

Issue 2272953002: [Findit] Moving check flake parameters to config (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Updating swarming settings config example Created 4 years, 3 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 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 copy 5 import copy
6 import logging 6 import logging
7 import time 7 import time
8 8
9 from google.appengine.ext import ndb
10
11 from common import time_util 9 from common import time_util
12 from common.http_client_appengine import HttpClientAppengine as HttpClient 10 from common.http_client_appengine import HttpClientAppengine as HttpClient
13 from common.pipeline_wrapper import BasePipeline 11 from common.pipeline_wrapper import BasePipeline
14 from model import analysis_status 12 from model import analysis_status
15 from waterfall import swarming_util 13 from waterfall import swarming_util
16 from waterfall import waterfall_config 14 from waterfall import waterfall_config
17 15
18 16
19 SLEEP_TIME_SECONDS = 10 17 class TriggerBaseSwarmingTaskPipeline(BasePipeline): # pragma: no cover.
20 DEADLINE_SECONDS = 5 * 60 # 5 minutes.
21
22
23 class TriggerBaseSwarmingTaskPipeline(BasePipeline): #pragma: no cover.
24 """A pipeline to trigger a Swarming task to re-run selected tests of a step. 18 """A pipeline to trigger a Swarming task to re-run selected tests of a step.
25 19
26 This pipeline only supports test steps that run on Swarming and support the 20 This pipeline only supports test steps that run on Swarming and support the
27 gtest filter. 21 gtest filter.
28 """ 22 """
29 23
30 def _GetSwarmingTaskName(self, ref_task_id): # pragma: no cover. 24 def _GetSwarmingTaskName(self, ref_task_id): # pragma: no cover.
31 return 'findit/deflake/ref_task_id/%s/%s' % ( 25 return 'findit/deflake/ref_task_id/%s/%s' % (
32 ref_task_id, time_util.GetUTCNow().strftime('%Y-%m-%d %H:%M:%S %f')) 26 ref_task_id, time_util.GetUTCNow().strftime('%Y-%m-%d %H:%M:%S %f'))
33 27
34 def _CreateNewSwarmingTaskRequest(self, ref_task_id, ref_request, master_name, 28 def _CreateNewSwarmingTaskRequest(self, ref_task_id, ref_request, master_name,
35 builder_name, build_number,step_name, 29 builder_name, build_number, step_name,
36 tests, iterations): 30 tests, iterations):
37 """Returns a SwarmingTaskRequest instance to run the given tests only.""" 31 """Returns a SwarmingTaskRequest instance to run the given tests only."""
32
38 # Make a copy of the referred request and drop or overwrite some fields. 33 # Make a copy of the referred request and drop or overwrite some fields.
39 new_request = copy.deepcopy(ref_request) 34 new_request = copy.deepcopy(ref_request)
40 new_request.name = self._GetSwarmingTaskName(ref_task_id) 35 new_request.name = self._GetSwarmingTaskName(ref_task_id)
41 new_request.parent_task_id = '' 36 new_request.parent_task_id = ''
42 new_request.user = '' 37 new_request.user = ''
43 38
44 # To force a fresh re-run and ignore cached result of any equivalent run. 39 # To force a fresh re-run and ignore cached result of any equivalent run.
45 new_request.idempotent = False 40 new_request.idempotent = False
46 41
47 # Set the gtest_filter to run the given tests only. 42 # Set the gtest_filter to run the given tests only.
(...skipping 17 matching lines...) Expand all
65 new_request.tags.append('ref_master:%s' % master_name) 60 new_request.tags.append('ref_master:%s' % master_name)
66 new_request.tags.append('ref_buildername:%s' % builder_name) 61 new_request.tags.append('ref_buildername:%s' % builder_name)
67 new_request.tags.append('ref_buildnumber:%s' % build_number) 62 new_request.tags.append('ref_buildnumber:%s' % build_number)
68 new_request.tags.append('ref_stepname:%s' % step_name) 63 new_request.tags.append('ref_stepname:%s' % step_name)
69 new_request.tags.append('ref_task_id:%s' % ref_task_id) 64 new_request.tags.append('ref_task_id:%s' % ref_task_id)
70 new_request.tags.append('ref_name:%s' % ref_name) 65 new_request.tags.append('ref_name:%s' % ref_name)
71 66
72 return new_request 67 return new_request
73 68
74 def _GetArgs(self, master_name, builder_name, build_number, step_name, tests): 69 def _GetArgs(self, master_name, builder_name, build_number, step_name, tests):
75 #returns an array you can pass into _GetSwarmingTask, _CreateSwarmingTask, 70 # Returns an array you can pass into _GetSwarmingTask, _CreateSwarmingTask,
76 #_NeedANewSwarmingTask as the arguments 71 # _NeedANewSwarmingTask as the arguments.
77 #Should be overwritten in child method 72
73 # Should be overwritten in child method.
78 raise NotImplementedError( 74 raise NotImplementedError(
79 '_GetArgs should be implemented in child class') 75 '_GetArgs should be implemented in child class')
80 76
81 def _GetSwarmingTask(self): 77 def _GetSwarmingTask(self):
82 # Get the appropriate kind of Swarming Task (Wf or Flake) 78 # Get the appropriate kind of Swarming Task (Wf or Flake).
83 # Should be overwritten in child method 79
80 # Should be overwritten in child method.
84 raise NotImplementedError( 81 raise NotImplementedError(
85 '_GetSwarmingTask should be implemented in child class') 82 '_GetSwarmingTask should be implemented in child class')
86 83
87 def _CreateSwarmingTask(self): 84 def _CreateSwarmingTask(self):
88 # Create the appropriate kind of Swarming Task (Wf or Flake) 85 # Create the appropriate kind of Swarming Task (Wf or Flake)
89 # Should be overwritten in child method 86
87 # Should be overwritten in child method.
90 raise NotImplementedError( 88 raise NotImplementedError(
91 '_CreateSwarmingTask should be implemented in child class') 89 '_CreateSwarmingTask should be implemented in child class')
92 90
93 def _NeedANewSwarmingTask(self, *args): 91 def _NeedANewSwarmingTask(self, *args):
94 swarming_task = self._GetSwarmingTask(*args) 92 swarming_task = self._GetSwarmingTask(*args)
95 if not swarming_task: 93 if not swarming_task:
96 swarming_task = self._CreateSwarmingTask(*args) 94 swarming_task = self._CreateSwarmingTask(*args)
97 swarming_task.status = analysis_status.PENDING 95 swarming_task.status = analysis_status.PENDING
98 swarming_task.put() 96 swarming_task.put()
99 return True 97 return True
100 else: 98 else:
101 # TODO(http://crbug.com/585676): Rerun the Swarming task if it runs into 99 # TODO(http://crbug.com/585676): Rerun the Swarming task if it runs into
102 # unexpected infra errors. 100 # unexpected infra errors.
103 return False 101 return False
104 102
105 def _GetSwarmingTaskId(self, *args): 103 def _GetSwarmingTaskId(self, *args):
104 swarming_settings = waterfall_config.GetSwarmingSettings()
105 wait_seconds = swarming_settings.get('get_swarming_task_id_wait_seconds')
106 timeout_seconds = swarming_settings.get(
107 'get_swarming_task_id_timeout_seconds')
108 deadline = time.time() + timeout_seconds
106 109
107 deadline = time.time() + DEADLINE_SECONDS
108 while time.time() < deadline: 110 while time.time() < deadline:
109 swarming_task = self._GetSwarmingTask(*args) 111 swarming_task = self._GetSwarmingTask(*args)
110 112
111 if not swarming_task: # pragma: no cover. Pipeline will retry. 113 if not swarming_task: # pragma: no cover. Pipeline will retry.
112 raise Exception('Swarming task was deleted unexpectedly!') 114 raise Exception('Swarming task was deleted unexpectedly!')
113 115
114 if swarming_task.task_id: 116 if swarming_task.task_id:
115 return swarming_task.task_id 117 return swarming_task.task_id
116 118
117 # Wait for the existing pipeline to start the Swarming task. 119 # Wait for the existing pipeline to start the Swarming task.
118 time.sleep(SLEEP_TIME_SECONDS) 120 time.sleep(wait_seconds)
119 121
120 raise Exception('Time out!') # pragma: no cover. Pipeline will retry. 122 raise Exception('Time out!') # pragma: no cover. Pipeline will retry.
121 123
122 def _GetIterationsToRerun(self): 124 def _GetIterationsToRerun(self):
123 # How many times we want to run the swarming rerun 125 # How many times we want to run the swarming rerun
124 # By default, it's what's in wf_config 126 # By default, it's what's in wf_config
125 raise NotImplementedError( 127 raise NotImplementedError(
126 '_GetIterationsToRerun should be implemented in child class') 128 '_GetIterationsToRerun should be implemented in child class')
127 129
128 # Arguments number differs from overridden method - pylint: disable=W0221 130 # Arguments number differs from overridden method - pylint: disable=W0221
129 def run(self, master_name, builder_name, build_number, step_name, tests): 131 def run(self, master_name, builder_name, build_number, step_name, tests):
130 """Triggers a new Swarming task to run the given tests. 132 """Triggers a new Swarming task to run the given tests.
131 133
132 Args: 134 Args:
133 master_name (str): The master name. 135 master_name (str): The master name.
134 builder_name (str): The builder name. 136 builder_name (str): The builder name.
135 build_number (str): The build number. 137 build_number (str): The build number.
136 step_name (str): The failed test step name. 138 step_name (str): The failed test step name.
137 tests (list): A list of test cases, eg: ['suite1.test1', 'suite2.testw2'] 139 tests (list): A list of test cases, eg: ['suite1.test1', 'suite2.testw2']
138 140
139 Returns: 141 Returns:
140 task_id (str): The new Swarming task that re-run the given tests. 142 task_id (str): The new Swarming task that re-run the given tests.
141 """ 143 """
142 call_args = self._GetArgs(master_name, builder_name, 144 call_args = self._GetArgs(master_name, builder_name,
143 build_number, step_name, tests) 145 build_number, step_name, tests)
144 # Check if a new Swarming Task is really needed. 146 # Check if a new Swarming Task is really needed.
145 if not self._NeedANewSwarmingTask(*call_args): 147 if not self._NeedANewSwarmingTask(*call_args):
146 return self._GetSwarmingTaskId(*call_args) 148 return self._GetSwarmingTaskId(*call_args)
147 assert tests 149 assert tests
148 http_client = HttpClient() 150 http_client = HttpClient()
149 151
150 # 0. Retrieve existing Swarming task ids for the given step. 152 # 0. Retrieve existing Swarming task ids for the given step.
151 swarming_task_items = swarming_util.ListSwarmingTasksDataByTags( 153 swarming_task_items = swarming_util.ListSwarmingTasksDataByTags(
(...skipping 19 matching lines...) Expand all
171 swarming_task = self._GetSwarmingTask(*call_args) 173 swarming_task = self._GetSwarmingTask(*call_args)
172 swarming_task.task_id = task_id 174 swarming_task.task_id = task_id
173 swarming_task.parameters['tests'] = tests 175 swarming_task.parameters['tests'] = tests
174 swarming_task.parameters['iterations_to_rerun'] = iterations_to_rerun 176 swarming_task.parameters['iterations_to_rerun'] = iterations_to_rerun
175 swarming_task.parameters['ref_name'] = swarming_util.GetTagValue( 177 swarming_task.parameters['ref_name'] = swarming_util.GetTagValue(
176 new_request.tags, 'ref_name') 178 new_request.tags, 'ref_name')
177 swarming_task.put() 179 swarming_task.put()
178 180
179 logging.info('A Swarming task was triggered:%s', task_id) 181 logging.info('A Swarming task was triggered:%s', task_id)
180 return task_id 182 return task_id
OLDNEW
« no previous file with comments | « appengine/findit/waterfall/test/wf_testcase.py ('k') | appengine/findit/waterfall/trigger_flake_swarming_task_pipeline.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698