James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 1 | # Copyright 2012-2014 Hewlett-Packard Development Company, L.P. |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 2 | # Copyright 2013 OpenStack Foundation |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 3 | # Copyright 2013 Antoine "hashar" Musso |
| 4 | # Copyright 2013 Wikimedia Foundation Inc. |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
James E. Blair | 71e9412 | 2012-12-24 17:53:08 -0800 | [diff] [blame] | 18 | import extras |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 19 | import json |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 20 | import logging |
Zhongyue Luo | 1c860d7 | 2012-07-19 11:03:56 +0800 | [diff] [blame] | 21 | import os |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 22 | import pickle |
Christian Berendt | 12d4d72 | 2014-06-07 21:03:45 +0200 | [diff] [blame] | 23 | from six.moves import queue as Queue |
Zhongyue Luo | 1c860d7 | 2012-07-19 11:03:56 +0800 | [diff] [blame] | 24 | import re |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 25 | import sys |
Zhongyue Luo | 1c860d7 | 2012-07-19 11:03:56 +0800 | [diff] [blame] | 26 | import threading |
James E. Blair | 71e9412 | 2012-12-24 17:53:08 -0800 | [diff] [blame] | 27 | import time |
Zhongyue Luo | 1c860d7 | 2012-07-19 11:03:56 +0800 | [diff] [blame] | 28 | import yaml |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 29 | |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 30 | import layoutvalidator |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 31 | import model |
James E. Blair | 11041d2 | 2014-05-02 14:49:53 -0700 | [diff] [blame] | 32 | from model import ActionReporter, Pipeline, Project, ChangeQueue |
| 33 | from model import EventFilter, ChangeishFilter |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame^] | 34 | from zuul import change_matcher |
Sergey Lukjanov | 5ba961b | 2013-12-27 01:21:04 +0400 | [diff] [blame] | 35 | from zuul import version as zuul_version |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 36 | |
James E. Blair | 71e9412 | 2012-12-24 17:53:08 -0800 | [diff] [blame] | 37 | statsd = extras.try_import('statsd.statsd') |
| 38 | |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 39 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 40 | def deep_format(obj, paramdict): |
| 41 | """Apply the paramdict via str.format() to all string objects found within |
| 42 | the supplied obj. Lists and dicts are traversed recursively. |
| 43 | |
| 44 | Borrowed from Jenkins Job Builder project""" |
| 45 | if isinstance(obj, str): |
| 46 | ret = obj.format(**paramdict) |
| 47 | elif isinstance(obj, list): |
| 48 | ret = [] |
| 49 | for item in obj: |
| 50 | ret.append(deep_format(item, paramdict)) |
| 51 | elif isinstance(obj, dict): |
| 52 | ret = {} |
| 53 | for item in obj: |
| 54 | exp_item = item.format(**paramdict) |
| 55 | |
| 56 | ret[exp_item] = deep_format(obj[item], paramdict) |
| 57 | else: |
| 58 | ret = obj |
| 59 | return ret |
| 60 | |
| 61 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 62 | class MergeFailure(Exception): |
| 63 | pass |
| 64 | |
| 65 | |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 66 | class ManagementEvent(object): |
| 67 | """An event that should be processed within the main queue run loop""" |
| 68 | def __init__(self): |
| 69 | self._wait_event = threading.Event() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 70 | self._exception = None |
| 71 | self._traceback = None |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 72 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 73 | def exception(self, e, tb): |
| 74 | self._exception = e |
| 75 | self._traceback = tb |
| 76 | self._wait_event.set() |
| 77 | |
| 78 | def done(self): |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 79 | self._wait_event.set() |
| 80 | |
| 81 | def wait(self, timeout=None): |
| 82 | self._wait_event.wait(timeout) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 83 | if self._exception: |
| 84 | raise self._exception, None, self._traceback |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 85 | return self._wait_event.is_set() |
| 86 | |
| 87 | |
| 88 | class ReconfigureEvent(ManagementEvent): |
| 89 | """Reconfigure the scheduler. The layout will be (re-)loaded from |
| 90 | the path specified in the configuration. |
| 91 | |
| 92 | :arg ConfigParser config: the new configuration |
| 93 | """ |
| 94 | def __init__(self, config): |
| 95 | super(ReconfigureEvent, self).__init__() |
| 96 | self.config = config |
| 97 | |
| 98 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 99 | class PromoteEvent(ManagementEvent): |
| 100 | """Promote one or more changes to the head of the queue. |
| 101 | |
| 102 | :arg str pipeline_name: the name of the pipeline |
| 103 | :arg list change_ids: a list of strings of change ids in the form |
| 104 | 1234,1 |
| 105 | """ |
| 106 | |
| 107 | def __init__(self, pipeline_name, change_ids): |
| 108 | super(PromoteEvent, self).__init__() |
| 109 | self.pipeline_name = pipeline_name |
| 110 | self.change_ids = change_ids |
| 111 | |
| 112 | |
James E. Blair | d27a96d | 2014-07-10 13:25:13 -0700 | [diff] [blame] | 113 | class EnqueueEvent(ManagementEvent): |
| 114 | """Enqueue a change into a pipeline |
| 115 | |
| 116 | :arg TriggerEvent trigger_event: a TriggerEvent describing the |
| 117 | trigger, pipeline, and change to enqueue |
| 118 | """ |
| 119 | |
| 120 | def __init__(self, trigger_event): |
| 121 | super(EnqueueEvent, self).__init__() |
| 122 | self.trigger_event = trigger_event |
| 123 | |
| 124 | |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 125 | class ResultEvent(object): |
| 126 | """An event that needs to modify the pipeline state due to a |
| 127 | result from an external system.""" |
| 128 | |
| 129 | pass |
| 130 | |
| 131 | |
| 132 | class BuildStartedEvent(ResultEvent): |
| 133 | """A build has started. |
| 134 | |
| 135 | :arg Build build: The build which has started. |
| 136 | """ |
| 137 | |
| 138 | def __init__(self, build): |
| 139 | self.build = build |
| 140 | |
| 141 | |
| 142 | class BuildCompletedEvent(ResultEvent): |
| 143 | """A build has completed |
| 144 | |
| 145 | :arg Build build: The build which has completed. |
| 146 | """ |
| 147 | |
| 148 | def __init__(self, build): |
| 149 | self.build = build |
| 150 | |
| 151 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 152 | class MergeCompletedEvent(ResultEvent): |
| 153 | """A remote merge operation has completed |
| 154 | |
| 155 | :arg BuildSet build_set: The build_set which is ready. |
| 156 | :arg str zuul_url: The URL of the Zuul Merger. |
| 157 | :arg bool merged: Whether the merge succeeded (changes with refs). |
| 158 | :arg bool updated: Whether the repo was updated (changes without refs). |
| 159 | :arg str commit: The SHA of the merged commit (changes with refs). |
| 160 | """ |
| 161 | |
| 162 | def __init__(self, build_set, zuul_url, merged, updated, commit): |
| 163 | self.build_set = build_set |
| 164 | self.zuul_url = zuul_url |
| 165 | self.merged = merged |
| 166 | self.updated = updated |
| 167 | self.commit = commit |
| 168 | |
| 169 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame^] | 170 | def toList(item): |
| 171 | if not item: |
| 172 | return [] |
| 173 | if isinstance(item, list): |
| 174 | return item |
| 175 | return [item] |
| 176 | |
| 177 | |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 178 | class Scheduler(threading.Thread): |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 179 | log = logging.getLogger("zuul.Scheduler") |
| 180 | |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 181 | def __init__(self): |
| 182 | threading.Thread.__init__(self) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 183 | self.daemon = True |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 184 | self.wake_event = threading.Event() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 185 | self.layout_lock = threading.Lock() |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 186 | self.run_handler_lock = threading.Lock() |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 187 | self._pause = False |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 188 | self._exit = False |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 189 | self._stopped = False |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 190 | self.launcher = None |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 191 | self.merger = None |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 192 | self.triggers = dict() |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 193 | self.reporters = dict() |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 194 | self.config = None |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 195 | |
| 196 | self.trigger_event_queue = Queue.Queue() |
| 197 | self.result_event_queue = Queue.Queue() |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 198 | self.management_event_queue = Queue.Queue() |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 199 | self.layout = model.Layout() |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 200 | |
Sergey Lukjanov | 5ba961b | 2013-12-27 01:21:04 +0400 | [diff] [blame] | 201 | self.zuul_version = zuul_version.version_info.version_string() |
Sergey Lukjanov | 5d0438d | 2013-12-24 03:36:39 +0400 | [diff] [blame] | 202 | self.last_reconfigured = None |
Sergey Lukjanov | 5ba961b | 2013-12-27 01:21:04 +0400 | [diff] [blame] | 203 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 204 | def stop(self): |
| 205 | self._stopped = True |
| 206 | self.wake_event.set() |
| 207 | |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 208 | def testConfig(self, config_path): |
James E. Blair | 04948c7 | 2013-07-25 23:03:17 -0700 | [diff] [blame] | 209 | return self._parseConfig(config_path) |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 210 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame^] | 211 | def _parseSkipIf(self, config_job): |
| 212 | cm = change_matcher |
| 213 | skip_matchers = [] |
| 214 | |
| 215 | for config_skip in config_job.get('skip-if', []): |
| 216 | nested_matchers = [] |
| 217 | |
| 218 | project_regex = config_skip.get('project') |
| 219 | if project_regex: |
| 220 | nested_matchers.append(cm.ProjectMatcher(project_regex)) |
| 221 | |
| 222 | branch_regex = config_skip.get('branch') |
| 223 | if branch_regex: |
| 224 | nested_matchers.append(cm.BranchMatcher(branch_regex)) |
| 225 | |
| 226 | file_regexes = toList(config_skip.get('all-files-match-any')) |
| 227 | if file_regexes: |
| 228 | file_matchers = [cm.FileMatcher(x) for x in file_regexes] |
| 229 | all_files_matcher = cm.MatchAllFiles(file_matchers) |
| 230 | nested_matchers.append(all_files_matcher) |
| 231 | |
| 232 | # All patterns need to match a given skip-if predicate |
| 233 | skip_matchers.append(cm.MatchAll(nested_matchers)) |
| 234 | |
| 235 | if skip_matchers: |
| 236 | # Any skip-if predicate can be matched to trigger a skip |
| 237 | return cm.MatchAny(skip_matchers) |
| 238 | |
James E. Blair | e5a847f | 2012-07-10 15:29:14 -0700 | [diff] [blame] | 239 | def _parseConfig(self, config_path): |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 240 | layout = model.Layout() |
| 241 | project_templates = {} |
| 242 | |
James E. Blair | e5a847f | 2012-07-10 15:29:14 -0700 | [diff] [blame] | 243 | if config_path: |
| 244 | config_path = os.path.expanduser(config_path) |
| 245 | if not os.path.exists(config_path): |
| 246 | raise Exception("Unable to read layout config file at %s" % |
| 247 | config_path) |
| 248 | config_file = open(config_path) |
| 249 | data = yaml.load(config_file) |
| 250 | |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 251 | validator = layoutvalidator.LayoutValidator() |
| 252 | validator.validate(data) |
| 253 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 254 | config_env = {} |
James E. Blair | e5a847f | 2012-07-10 15:29:14 -0700 | [diff] [blame] | 255 | for include in data.get('includes', []): |
| 256 | if 'python-file' in include: |
| 257 | fn = include['python-file'] |
| 258 | if not os.path.isabs(fn): |
Antoine Musso | 9adc6d4 | 2014-11-14 15:37:48 +0100 | [diff] [blame] | 259 | base = os.path.dirname(os.path.realpath(config_path)) |
James E. Blair | e5a847f | 2012-07-10 15:29:14 -0700 | [diff] [blame] | 260 | fn = os.path.join(base, fn) |
| 261 | fn = os.path.expanduser(fn) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 262 | execfile(fn, config_env) |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 263 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 264 | for conf_pipeline in data.get('pipelines', []): |
| 265 | pipeline = Pipeline(conf_pipeline['name']) |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 266 | pipeline.description = conf_pipeline.get('description') |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 267 | # TODO(jeblair): remove backwards compatibility: |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 268 | pipeline.source = self.triggers[conf_pipeline.get('source', |
| 269 | 'gerrit')] |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 270 | precedence = model.PRECEDENCE_MAP[conf_pipeline.get('precedence')] |
| 271 | pipeline.precedence = precedence |
James E. Blair | 5637019 | 2013-01-14 15:47:28 -0800 | [diff] [blame] | 272 | pipeline.failure_message = conf_pipeline.get('failure-message', |
| 273 | "Build failed.") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 274 | pipeline.merge_failure_message = conf_pipeline.get( |
| 275 | 'merge-failure-message', "Merge Failed.\n\nThis change was " |
| 276 | "unable to be automatically merged with the current state of " |
| 277 | "the repository. Please rebase your change and upload a new " |
| 278 | "patchset.") |
James E. Blair | 5637019 | 2013-01-14 15:47:28 -0800 | [diff] [blame] | 279 | pipeline.success_message = conf_pipeline.get('success-message', |
| 280 | "Build succeeded.") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 281 | pipeline.footer_message = conf_pipeline.get('footer-message', "") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 282 | pipeline.dequeue_on_new_patchset = conf_pipeline.get( |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 283 | 'dequeue-on-new-patchset', True) |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 284 | |
| 285 | action_reporters = {} |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 286 | for action in ['start', 'success', 'failure', 'merge-failure']: |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 287 | action_reporters[action] = [] |
| 288 | if conf_pipeline.get(action): |
| 289 | for reporter_name, params \ |
| 290 | in conf_pipeline.get(action).items(): |
| 291 | if reporter_name in self.reporters.keys(): |
| 292 | action_reporters[action].append(ActionReporter( |
| 293 | self.reporters[reporter_name], params)) |
| 294 | else: |
| 295 | self.log.error('Invalid reporter name %s' % |
| 296 | reporter_name) |
| 297 | pipeline.start_actions = action_reporters['start'] |
| 298 | pipeline.success_actions = action_reporters['success'] |
| 299 | pipeline.failure_actions = action_reporters['failure'] |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 300 | if len(action_reporters['merge-failure']) > 0: |
| 301 | pipeline.merge_failure_actions = \ |
| 302 | action_reporters['merge-failure'] |
| 303 | else: |
| 304 | pipeline.merge_failure_actions = action_reporters['failure'] |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 305 | |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 306 | pipeline.window = conf_pipeline.get('window', 20) |
| 307 | pipeline.window_floor = conf_pipeline.get('window-floor', 3) |
| 308 | pipeline.window_increase_type = conf_pipeline.get( |
| 309 | 'window-increase-type', 'linear') |
| 310 | pipeline.window_increase_factor = conf_pipeline.get( |
| 311 | 'window-increase-factor', 1) |
| 312 | pipeline.window_decrease_type = conf_pipeline.get( |
| 313 | 'window-decrease-type', 'exponential') |
| 314 | pipeline.window_decrease_factor = conf_pipeline.get( |
| 315 | 'window-decrease-factor', 2) |
| 316 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 317 | manager = globals()[conf_pipeline['manager']](self, pipeline) |
| 318 | pipeline.setManager(manager) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 319 | layout.pipelines[conf_pipeline['name']] = pipeline |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 320 | |
James E. Blair | 11041d2 | 2014-05-02 14:49:53 -0700 | [diff] [blame] | 321 | if 'require' in conf_pipeline: |
| 322 | require = conf_pipeline['require'] |
Clark Boylan | a9702ad | 2014-05-08 17:17:24 -0700 | [diff] [blame] | 323 | f = ChangeishFilter( |
| 324 | open=require.get('open'), |
| 325 | current_patchset=require.get('current-patchset'), |
| 326 | statuses=toList(require.get('status')), |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 327 | required_approvals=toList(require.get('approval'))) |
James E. Blair | 11041d2 | 2014-05-02 14:49:53 -0700 | [diff] [blame] | 328 | manager.changeish_filters.append(f) |
| 329 | |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 330 | # TODO: move this into triggers (may require pluggable |
| 331 | # configuration) |
| 332 | if 'gerrit' in conf_pipeline['trigger']: |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 333 | for trigger in toList(conf_pipeline['trigger']['gerrit']): |
| 334 | approvals = {} |
| 335 | for approval_dict in toList(trigger.get('approval')): |
| 336 | for k, v in approval_dict.items(): |
| 337 | approvals[k] = v |
James E. Blair | 1fbfceb | 2014-06-23 14:42:53 -0700 | [diff] [blame] | 338 | # Backwards compat for *_filter versions of these args |
| 339 | comments = toList(trigger.get('comment')) |
| 340 | if not comments: |
| 341 | comments = toList(trigger.get('comment_filter')) |
| 342 | emails = toList(trigger.get('email')) |
| 343 | if not emails: |
| 344 | emails = toList(trigger.get('email_filter')) |
| 345 | usernames = toList(trigger.get('username')) |
| 346 | if not usernames: |
| 347 | usernames = toList(trigger.get('username_filter')) |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 348 | f = EventFilter( |
| 349 | trigger=self.triggers['gerrit'], |
| 350 | types=toList(trigger['event']), |
| 351 | branches=toList(trigger.get('branch')), |
| 352 | refs=toList(trigger.get('ref')), |
| 353 | event_approvals=approvals, |
| 354 | comments=comments, |
| 355 | emails=emails, |
| 356 | usernames=usernames, |
| 357 | required_approvals=toList( |
| 358 | trigger.get('require-approval') |
| 359 | ) |
| 360 | ) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 361 | manager.event_filters.append(f) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 362 | if 'timer' in conf_pipeline['trigger']: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 363 | for trigger in toList(conf_pipeline['trigger']['timer']): |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 364 | f = EventFilter(trigger=self.triggers['timer'], |
| 365 | types=['timer'], |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 366 | timespecs=toList(trigger['time'])) |
| 367 | manager.event_filters.append(f) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 368 | if 'zuul' in conf_pipeline['trigger']: |
| 369 | for trigger in toList(conf_pipeline['trigger']['zuul']): |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 370 | f = EventFilter( |
| 371 | trigger=self.triggers['zuul'], |
| 372 | types=toList(trigger['event']), |
| 373 | pipelines=toList(trigger.get('pipeline')), |
| 374 | required_approvals=toList( |
| 375 | trigger.get('require-approval') |
| 376 | ) |
| 377 | ) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 378 | manager.event_filters.append(f) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 379 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 380 | for project_template in data.get('project-templates', []): |
| 381 | # Make sure the template only contains valid pipelines |
| 382 | tpl = dict( |
| 383 | (pipe_name, project_template.get(pipe_name)) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 384 | for pipe_name in layout.pipelines.keys() |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 385 | if pipe_name in project_template |
| 386 | ) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 387 | project_templates[project_template.get('name')] = tpl |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 388 | |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 389 | for config_job in data.get('jobs', []): |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 390 | job = layout.getJob(config_job['name']) |
James E. Blair | b095465 | 2012-06-01 11:32:01 -0700 | [diff] [blame] | 391 | # Be careful to only set attributes explicitly present on |
| 392 | # this job, to avoid squashing attributes set by a meta-job. |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 393 | m = config_job.get('queue-name', None) |
| 394 | if m: |
| 395 | job.queue_name = m |
James E. Blair | b095465 | 2012-06-01 11:32:01 -0700 | [diff] [blame] | 396 | m = config_job.get('failure-message', None) |
| 397 | if m: |
| 398 | job.failure_message = m |
| 399 | m = config_job.get('success-message', None) |
| 400 | if m: |
| 401 | job.success_message = m |
James E. Blair | 6aea36d | 2012-12-17 13:03:24 -0800 | [diff] [blame] | 402 | m = config_job.get('failure-pattern', None) |
| 403 | if m: |
| 404 | job.failure_pattern = m |
| 405 | m = config_job.get('success-pattern', None) |
| 406 | if m: |
| 407 | job.success_pattern = m |
James E. Blair | 222d498 | 2012-07-16 09:31:19 -0700 | [diff] [blame] | 408 | m = config_job.get('hold-following-changes', False) |
| 409 | if m: |
| 410 | job.hold_following_changes = True |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 411 | m = config_job.get('voting', None) |
| 412 | if m is not None: |
| 413 | job.voting = m |
James E. Blair | e5a847f | 2012-07-10 15:29:14 -0700 | [diff] [blame] | 414 | fname = config_job.get('parameter-function', None) |
| 415 | if fname: |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 416 | func = config_env.get(fname, None) |
James E. Blair | e5a847f | 2012-07-10 15:29:14 -0700 | [diff] [blame] | 417 | if not func: |
| 418 | raise Exception("Unable to find function %s" % fname) |
| 419 | job.parameter_function = func |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 420 | branches = toList(config_job.get('branch')) |
| 421 | if branches: |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 422 | job._branches = branches |
| 423 | job.branches = [re.compile(x) for x in branches] |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 424 | files = toList(config_job.get('files')) |
| 425 | if files: |
| 426 | job._files = files |
| 427 | job.files = [re.compile(x) for x in files] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame^] | 428 | skip_if_matcher = self._parseSkipIf(config_job) |
| 429 | if skip_if_matcher: |
| 430 | job.skip_if_matcher = skip_if_matcher |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 431 | swift = toList(config_job.get('swift')) |
| 432 | if swift: |
| 433 | for s in swift: |
| 434 | job.swift[s['name']] = s |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 435 | |
| 436 | def add_jobs(job_tree, config_jobs): |
| 437 | for job in config_jobs: |
| 438 | if isinstance(job, list): |
| 439 | for x in job: |
| 440 | add_jobs(job_tree, x) |
| 441 | if isinstance(job, dict): |
| 442 | for parent, children in job.items(): |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 443 | parent_tree = job_tree.addJob(layout.getJob(parent)) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 444 | add_jobs(parent_tree, children) |
| 445 | if isinstance(job, str): |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 446 | job_tree.addJob(layout.getJob(job)) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 447 | |
James E. Blair | 4795838 | 2013-01-10 17:26:02 -0800 | [diff] [blame] | 448 | for config_project in data.get('projects', []): |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 449 | project = Project(config_project['name']) |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 450 | shortname = config_project['name'].split('/')[-1] |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 451 | |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 452 | # This is reversed due to the prepend operation below, so |
| 453 | # the ultimate order is templates (in order) followed by |
| 454 | # statically defined jobs. |
| 455 | for requested_template in reversed( |
| 456 | config_project.get('template', [])): |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 457 | # Fetch the template from 'project-templates' |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 458 | tpl = project_templates.get( |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 459 | requested_template.get('name')) |
| 460 | # Expand it with the project context |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 461 | requested_template['name'] = shortname |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 462 | expanded = deep_format(tpl, requested_template) |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 463 | # Finally merge the expansion with whatever has been |
| 464 | # already defined for this project. Prepend our new |
| 465 | # jobs to existing ones (which may have been |
| 466 | # statically defined or defined by other templates). |
| 467 | for pipeline in layout.pipelines.values(): |
| 468 | if pipeline.name in expanded: |
| 469 | config_project.update( |
| 470 | {pipeline.name: expanded[pipeline.name] + |
| 471 | config_project.get(pipeline.name, [])}) |
James E. Blair | 12a92b1 | 2014-03-26 11:54:53 -0700 | [diff] [blame] | 472 | # TODO: future enhancement -- handle the case where |
| 473 | # duplicate jobs have different children and you want all |
| 474 | # of the children to run after a single run of the |
| 475 | # parent). |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 476 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 477 | layout.projects[config_project['name']] = project |
James E. Blair | 19deff2 | 2013-08-25 13:17:35 -0700 | [diff] [blame] | 478 | mode = config_project.get('merge-mode', 'merge-resolve') |
| 479 | project.merge_mode = model.MERGER_MAP[mode] |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 480 | for pipeline in layout.pipelines.values(): |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 481 | if pipeline.name in config_project: |
| 482 | job_tree = pipeline.addProject(project) |
| 483 | config_jobs = config_project[pipeline.name] |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 484 | add_jobs(job_tree, config_jobs) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 485 | |
James E. Blair | b095465 | 2012-06-01 11:32:01 -0700 | [diff] [blame] | 486 | # All jobs should be defined at this point, get rid of |
| 487 | # metajobs so that getJob isn't doing anything weird. |
James E. Blair | c28d1b0 | 2013-07-19 11:37:06 -0700 | [diff] [blame] | 488 | layout.metajobs = [] |
James E. Blair | b095465 | 2012-06-01 11:32:01 -0700 | [diff] [blame] | 489 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 490 | for pipeline in layout.pipelines.values(): |
| 491 | pipeline.manager._postConfig(layout) |
| 492 | |
| 493 | return layout |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 494 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 495 | def setLauncher(self, launcher): |
| 496 | self.launcher = launcher |
| 497 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 498 | def setMerger(self, merger): |
| 499 | self.merger = merger |
| 500 | |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 501 | def registerTrigger(self, trigger, name=None): |
| 502 | if name is None: |
| 503 | name = trigger.name |
| 504 | self.triggers[name] = trigger |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 505 | |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 506 | def registerReporter(self, reporter, name=None): |
| 507 | if name is None: |
| 508 | name = reporter.name |
| 509 | self.reporters[name] = reporter |
| 510 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 511 | def getProject(self, name): |
| 512 | self.layout_lock.acquire() |
| 513 | p = None |
| 514 | try: |
| 515 | p = self.layout.projects.get(name) |
| 516 | finally: |
| 517 | self.layout_lock.release() |
| 518 | return p |
| 519 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 520 | def addEvent(self, event): |
| 521 | self.log.debug("Adding trigger event: %s" % event) |
James E. Blair | 23ec1ba | 2013-01-04 18:06:10 -0800 | [diff] [blame] | 522 | try: |
| 523 | if statsd: |
| 524 | statsd.incr('gerrit.event.%s' % event.type) |
| 525 | except: |
| 526 | self.log.exception("Exception reporting event stats") |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 527 | self.trigger_event_queue.put(event) |
| 528 | self.wake_event.set() |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 529 | self.log.debug("Done adding trigger event: %s" % event) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 530 | |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 531 | def onBuildStarted(self, build): |
| 532 | self.log.debug("Adding start event for build: %s" % build) |
James E. Blair | 71e9412 | 2012-12-24 17:53:08 -0800 | [diff] [blame] | 533 | build.start_time = time.time() |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 534 | event = BuildStartedEvent(build) |
| 535 | self.result_event_queue.put(event) |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 536 | self.wake_event.set() |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 537 | self.log.debug("Done adding start event for build: %s" % build) |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 538 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 539 | def onBuildCompleted(self, build): |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 540 | self.log.debug("Adding complete event for build: %s" % build) |
James E. Blair | 71e9412 | 2012-12-24 17:53:08 -0800 | [diff] [blame] | 541 | build.end_time = time.time() |
James E. Blair | 23ec1ba | 2013-01-04 18:06:10 -0800 | [diff] [blame] | 542 | try: |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 543 | if statsd and build.pipeline: |
| 544 | jobname = build.job.name.replace('.', '_') |
| 545 | key = 'zuul.pipeline.%s.job.%s.%s' % (build.pipeline.name, |
| 546 | jobname, build.result) |
James E. Blair | 23ec1ba | 2013-01-04 18:06:10 -0800 | [diff] [blame] | 547 | if build.result in ['SUCCESS', 'FAILURE'] and build.start_time: |
| 548 | dt = int((build.end_time - build.start_time) * 1000) |
| 549 | statsd.timing(key, dt) |
| 550 | statsd.incr(key) |
James E. Blair | 7f4a190 | 2013-08-24 08:20:02 -0700 | [diff] [blame] | 551 | key = 'zuul.pipeline.%s.all_jobs' % build.pipeline.name |
| 552 | statsd.incr(key) |
James E. Blair | 23ec1ba | 2013-01-04 18:06:10 -0800 | [diff] [blame] | 553 | except: |
| 554 | self.log.exception("Exception reporting runtime stats") |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 555 | event = BuildCompletedEvent(build) |
| 556 | self.result_event_queue.put(event) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 557 | self.wake_event.set() |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 558 | self.log.debug("Done adding complete event for build: %s" % build) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 559 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 560 | def onMergeCompleted(self, build_set, zuul_url, merged, updated, commit): |
| 561 | self.log.debug("Adding merge complete event for build set: %s" % |
| 562 | build_set) |
| 563 | event = MergeCompletedEvent(build_set, zuul_url, |
| 564 | merged, updated, commit) |
| 565 | self.result_event_queue.put(event) |
| 566 | self.wake_event.set() |
| 567 | |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 568 | def reconfigure(self, config): |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 569 | self.log.debug("Prepare to reconfigure") |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 570 | event = ReconfigureEvent(config) |
| 571 | self.management_event_queue.put(event) |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 572 | self.wake_event.set() |
| 573 | self.log.debug("Waiting for reconfiguration") |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 574 | event.wait() |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 575 | self.log.debug("Reconfiguration complete") |
Sergey Lukjanov | 5d0438d | 2013-12-24 03:36:39 +0400 | [diff] [blame] | 576 | self.last_reconfigured = int(time.time()) |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 577 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 578 | def promote(self, pipeline_name, change_ids): |
| 579 | event = PromoteEvent(pipeline_name, change_ids) |
| 580 | self.management_event_queue.put(event) |
| 581 | self.wake_event.set() |
| 582 | self.log.debug("Waiting for promotion") |
| 583 | event.wait() |
| 584 | self.log.debug("Promotion complete") |
| 585 | |
James E. Blair | d27a96d | 2014-07-10 13:25:13 -0700 | [diff] [blame] | 586 | def enqueue(self, trigger_event): |
| 587 | event = EnqueueEvent(trigger_event) |
| 588 | self.management_event_queue.put(event) |
| 589 | self.wake_event.set() |
| 590 | self.log.debug("Waiting for enqueue") |
| 591 | event.wait() |
| 592 | self.log.debug("Enqueue complete") |
| 593 | |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 594 | def exit(self): |
| 595 | self.log.debug("Prepare to exit") |
| 596 | self._pause = True |
| 597 | self._exit = True |
| 598 | self.wake_event.set() |
| 599 | self.log.debug("Waiting for exit") |
| 600 | |
| 601 | def _get_queue_pickle_file(self): |
James E. Blair | 5a95c86 | 2012-07-09 15:11:17 -0700 | [diff] [blame] | 602 | if self.config.has_option('zuul', 'state_dir'): |
| 603 | state_dir = os.path.expanduser(self.config.get('zuul', |
| 604 | 'state_dir')) |
| 605 | else: |
| 606 | state_dir = '/var/lib/zuul' |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 607 | return os.path.join(state_dir, 'queue.pickle') |
| 608 | |
| 609 | def _save_queue(self): |
| 610 | pickle_file = self._get_queue_pickle_file() |
| 611 | events = [] |
| 612 | while not self.trigger_event_queue.empty(): |
| 613 | events.append(self.trigger_event_queue.get()) |
| 614 | self.log.debug("Queue length is %s" % len(events)) |
| 615 | if events: |
| 616 | self.log.debug("Saving queue") |
| 617 | pickle.dump(events, open(pickle_file, 'wb')) |
| 618 | |
| 619 | def _load_queue(self): |
| 620 | pickle_file = self._get_queue_pickle_file() |
| 621 | if os.path.exists(pickle_file): |
| 622 | self.log.debug("Loading queue") |
| 623 | events = pickle.load(open(pickle_file, 'rb')) |
| 624 | self.log.debug("Queue length is %s" % len(events)) |
| 625 | for event in events: |
| 626 | self.trigger_event_queue.put(event) |
| 627 | else: |
| 628 | self.log.debug("No queue file found") |
| 629 | |
| 630 | def _delete_queue(self): |
| 631 | pickle_file = self._get_queue_pickle_file() |
| 632 | if os.path.exists(pickle_file): |
| 633 | self.log.debug("Deleting saved queue") |
| 634 | os.unlink(pickle_file) |
| 635 | |
| 636 | def resume(self): |
| 637 | try: |
| 638 | self._load_queue() |
| 639 | except: |
| 640 | self.log.exception("Unable to load queue") |
| 641 | try: |
| 642 | self._delete_queue() |
| 643 | except: |
| 644 | self.log.exception("Unable to delete saved queue") |
| 645 | self.log.debug("Resuming queue processing") |
| 646 | self.wake_event.set() |
| 647 | |
| 648 | def _doPauseEvent(self): |
| 649 | if self._exit: |
| 650 | self.log.debug("Exiting") |
| 651 | self._save_queue() |
| 652 | os._exit(0) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 653 | |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 654 | def _doReconfigureEvent(self, event): |
| 655 | # This is called in the scheduler loop after another thread submits |
| 656 | # a request |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 657 | self.layout_lock.acquire() |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 658 | self.config = event.config |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 659 | try: |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 660 | self.log.debug("Performing reconfiguration") |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 661 | layout = self._parseConfig( |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 662 | self.config.get('zuul', 'layout_config')) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 663 | for name, new_pipeline in layout.pipelines.items(): |
| 664 | old_pipeline = self.layout.pipelines.get(name) |
| 665 | if not old_pipeline: |
| 666 | if self.layout.pipelines: |
| 667 | # Don't emit this warning on startup |
| 668 | self.log.warning("No old pipeline matching %s found " |
| 669 | "when reconfiguring" % name) |
| 670 | continue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 671 | self.log.debug("Re-enqueueing changes for pipeline %s" % name) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 672 | items_to_remove = [] |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 673 | builds_to_remove = [] |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 674 | for shared_queue in old_pipeline.queues: |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 675 | for item in shared_queue.queue: |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 676 | item.item_ahead = None |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 677 | item.items_behind = [] |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 678 | item.pipeline = None |
| 679 | project = layout.projects.get(item.change.project.name) |
| 680 | if not project: |
| 681 | self.log.warning("Unable to find project for " |
| 682 | "change %s while reenqueueing" % |
| 683 | item.change) |
| 684 | item.change.project = None |
| 685 | items_to_remove.append(item) |
| 686 | continue |
| 687 | item.change.project = project |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 688 | for build in item.current_build_set.getBuilds(): |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 689 | job = layout.jobs.get(build.job.name) |
| 690 | if job: |
| 691 | build.job = job |
| 692 | else: |
| 693 | builds_to_remove.append(build) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 694 | if not new_pipeline.manager.reEnqueueItem(item): |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 695 | items_to_remove.append(item) |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 696 | for item in items_to_remove: |
| 697 | for build in item.current_build_set.getBuilds(): |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 698 | builds_to_remove.append(build) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 699 | for build in builds_to_remove: |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 700 | self.log.warning( |
| 701 | "Canceling build %s during reconfiguration" % (build,)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 702 | try: |
| 703 | self.launcher.cancel(build) |
| 704 | except Exception: |
| 705 | self.log.exception( |
| 706 | "Exception while canceling build %s " |
| 707 | "for change %s" % (build, item.change)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 708 | self.layout = layout |
James E. Blair | c0acb55 | 2014-08-16 08:17:02 -0700 | [diff] [blame] | 709 | self.maintainTriggerCache() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 710 | for trigger in self.triggers.values(): |
| 711 | trigger.postConfig() |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 712 | if statsd: |
| 713 | try: |
| 714 | for pipeline in self.layout.pipelines.values(): |
| 715 | items = len(pipeline.getAllItems()) |
| 716 | # stats.gauges.zuul.pipeline.NAME.current_changes |
| 717 | key = 'zuul.pipeline.%s' % pipeline.name |
| 718 | statsd.gauge(key + '.current_changes', items) |
| 719 | except Exception: |
| 720 | self.log.exception("Exception reporting initial " |
| 721 | "pipeline stats:") |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 722 | finally: |
| 723 | self.layout_lock.release() |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 724 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 725 | def _doPromoteEvent(self, event): |
| 726 | pipeline = self.layout.pipelines[event.pipeline_name] |
| 727 | change_ids = [c.split(',') for c in event.change_ids] |
| 728 | items_to_enqueue = [] |
| 729 | change_queue = None |
| 730 | for shared_queue in pipeline.queues: |
| 731 | if change_queue: |
| 732 | break |
| 733 | for item in shared_queue.queue: |
| 734 | if (item.change.number == change_ids[0][0] and |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 735 | item.change.patchset == change_ids[0][1]): |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 736 | change_queue = shared_queue |
| 737 | break |
| 738 | if not change_queue: |
| 739 | raise Exception("Unable to find shared change queue for %s" % |
| 740 | event.change_ids[0]) |
| 741 | for number, patchset in change_ids: |
| 742 | found = False |
| 743 | for item in change_queue.queue: |
| 744 | if (item.change.number == number and |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 745 | item.change.patchset == patchset): |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 746 | found = True |
| 747 | items_to_enqueue.append(item) |
| 748 | break |
| 749 | if not found: |
| 750 | raise Exception("Unable to find %s,%s in queue %s" % |
| 751 | (number, patchset, change_queue)) |
| 752 | for item in change_queue.queue[:]: |
| 753 | if item not in items_to_enqueue: |
| 754 | items_to_enqueue.append(item) |
| 755 | pipeline.manager.cancelJobs(item) |
| 756 | pipeline.manager.dequeueItem(item) |
| 757 | for item in items_to_enqueue: |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 758 | pipeline.manager.addChange( |
| 759 | item.change, |
| 760 | enqueue_time=item.enqueue_time, |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 761 | quiet=True, |
| 762 | ignore_requirements=True) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 763 | |
James E. Blair | d27a96d | 2014-07-10 13:25:13 -0700 | [diff] [blame] | 764 | def _doEnqueueEvent(self, event): |
| 765 | project = self.layout.projects.get(event.project_name) |
| 766 | pipeline = self.layout.pipelines[event.forced_pipeline] |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 767 | change = pipeline.source.getChange(event, project) |
James E. Blair | d27a96d | 2014-07-10 13:25:13 -0700 | [diff] [blame] | 768 | self.log.debug("Event %s for change %s was directly assigned " |
| 769 | "to pipeline %s" % (event, change, self)) |
| 770 | self.log.info("Adding %s, %s to %s" % |
| 771 | (project, change, pipeline)) |
| 772 | pipeline.manager.addChange(change, ignore_requirements=True) |
| 773 | |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 774 | def _areAllBuildsComplete(self): |
| 775 | self.log.debug("Checking if all builds are complete") |
| 776 | waiting = False |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 777 | if self.merger.areMergesOutstanding(): |
| 778 | waiting = True |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 779 | for pipeline in self.layout.pipelines.values(): |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 780 | for item in pipeline.getAllItems(): |
| 781 | for build in item.current_build_set.getBuilds(): |
| 782 | if build.result is None: |
| 783 | self.log.debug("%s waiting on %s" % |
| 784 | (pipeline.manager, build)) |
| 785 | waiting = True |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 786 | if not waiting: |
| 787 | self.log.debug("All builds are complete") |
| 788 | return True |
| 789 | self.log.debug("All builds are not complete") |
| 790 | return False |
| 791 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 792 | def run(self): |
James E. Blair | 71e9412 | 2012-12-24 17:53:08 -0800 | [diff] [blame] | 793 | if statsd: |
| 794 | self.log.debug("Statsd enabled") |
| 795 | else: |
| 796 | self.log.debug("Statsd disabled because python statsd " |
| 797 | "package not found") |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 798 | while True: |
| 799 | self.log.debug("Run handler sleeping") |
| 800 | self.wake_event.wait() |
| 801 | self.wake_event.clear() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 802 | if self._stopped: |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 803 | self.log.debug("Run handler stopping") |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 804 | return |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 805 | self.log.debug("Run handler awake") |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 806 | self.run_handler_lock.acquire() |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 807 | try: |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 808 | while not self.management_event_queue.empty(): |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 809 | self.process_management_queue() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 810 | |
James E. Blair | 263fba9 | 2013-02-27 13:07:19 -0800 | [diff] [blame] | 811 | # Give result events priority -- they let us stop builds, |
| 812 | # whereas trigger evensts cause us to launch builds. |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 813 | while not self.result_event_queue.empty(): |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 814 | self.process_result_queue() |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 815 | |
| 816 | if not self._pause: |
| 817 | while not self.trigger_event_queue.empty(): |
James E. Blair | 263fba9 | 2013-02-27 13:07:19 -0800 | [diff] [blame] | 818 | self.process_event_queue() |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 819 | |
James E. Blair | 5d5bc2b | 2012-07-06 10:24:01 -0700 | [diff] [blame] | 820 | if self._pause and self._areAllBuildsComplete(): |
| 821 | self._doPauseEvent() |
James E. Blair | e9d45c3 | 2012-05-31 09:56:45 -0700 | [diff] [blame] | 822 | |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 823 | for pipeline in self.layout.pipelines.values(): |
| 824 | while pipeline.manager.processQueue(): |
| 825 | pass |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 826 | |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 827 | except Exception: |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 828 | self.log.exception("Exception in run handler:") |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 829 | # There may still be more events to process |
| 830 | self.wake_event.set() |
| 831 | finally: |
| 832 | self.run_handler_lock.release() |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 833 | |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 834 | def maintainTriggerCache(self): |
| 835 | relevant = set() |
| 836 | for pipeline in self.layout.pipelines.values(): |
James E. Blair | fadc6e1 | 2013-08-21 18:23:15 -0700 | [diff] [blame] | 837 | self.log.debug("Start maintain trigger cache for: %s" % pipeline) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 838 | for item in pipeline.getAllItems(): |
| 839 | relevant.add(item.change) |
| 840 | relevant.update(item.change.getRelatedChanges()) |
James E. Blair | fadc6e1 | 2013-08-21 18:23:15 -0700 | [diff] [blame] | 841 | self.log.debug("End maintain trigger cache for: %s" % pipeline) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 842 | self.log.debug("Trigger cache size: %s" % len(relevant)) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 843 | for trigger in self.triggers.values(): |
| 844 | trigger.maintainCache(relevant) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 845 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 846 | def process_event_queue(self): |
| 847 | self.log.debug("Fetching trigger event") |
| 848 | event = self.trigger_event_queue.get() |
| 849 | self.log.debug("Processing trigger event %s" % event) |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 850 | try: |
| 851 | project = self.layout.projects.get(event.project_name) |
| 852 | if not project: |
Jukka Lehtniemi | bec3ed0 | 2014-10-31 13:45:17 +0100 | [diff] [blame] | 853 | self.log.debug("Project %s not found" % event.project_name) |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 854 | return |
| 855 | |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 856 | for pipeline in self.layout.pipelines.values(): |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 857 | change = pipeline.source.getChange(event, project) |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 858 | if event.type == 'patchset-created': |
| 859 | pipeline.manager.removeOldVersionsOfChange(change) |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 860 | elif event.type == 'change-abandoned': |
| 861 | pipeline.manager.removeAbandonedChange(change) |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 862 | if pipeline.manager.eventMatches(event, change): |
| 863 | self.log.info("Adding %s, %s to %s" % |
| 864 | (project, change, pipeline)) |
| 865 | pipeline.manager.addChange(change) |
| 866 | finally: |
James E. Blair | ff79197 | 2013-01-09 11:45:43 -0800 | [diff] [blame] | 867 | self.trigger_event_queue.task_done() |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 868 | |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 869 | def process_management_queue(self): |
| 870 | self.log.debug("Fetching management event") |
| 871 | event = self.management_event_queue.get() |
| 872 | self.log.debug("Processing management event %s" % event) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 873 | try: |
| 874 | if isinstance(event, ReconfigureEvent): |
| 875 | self._doReconfigureEvent(event) |
| 876 | elif isinstance(event, PromoteEvent): |
| 877 | self._doPromoteEvent(event) |
James E. Blair | d27a96d | 2014-07-10 13:25:13 -0700 | [diff] [blame] | 878 | elif isinstance(event, EnqueueEvent): |
| 879 | self._doEnqueueEvent(event.trigger_event) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 880 | else: |
| 881 | self.log.error("Unable to handle event %s" % event) |
| 882 | event.done() |
| 883 | except Exception as e: |
| 884 | event.exception(e, sys.exc_info()[2]) |
James E. Blair | 468c851 | 2013-12-06 13:27:19 -0800 | [diff] [blame] | 885 | self.management_event_queue.task_done() |
| 886 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 887 | def process_result_queue(self): |
| 888 | self.log.debug("Fetching result event") |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 889 | event = self.result_event_queue.get() |
| 890 | self.log.debug("Processing result event %s" % event) |
| 891 | try: |
| 892 | if isinstance(event, BuildStartedEvent): |
| 893 | self._doBuildStartedEvent(event) |
| 894 | elif isinstance(event, BuildCompletedEvent): |
| 895 | self._doBuildCompletedEvent(event) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 896 | elif isinstance(event, MergeCompletedEvent): |
| 897 | self._doMergeCompletedEvent(event) |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 898 | else: |
| 899 | self.log.error("Unable to handle event %s" % event) |
| 900 | finally: |
| 901 | self.result_event_queue.task_done() |
| 902 | |
| 903 | def _doBuildStartedEvent(self, event): |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 904 | build = event.build |
| 905 | if build.build_set is not build.build_set.item.current_build_set: |
| 906 | self.log.warning("Build %s is not in the current build set" % |
| 907 | (build,)) |
| 908 | return |
| 909 | pipeline = build.build_set.item.pipeline |
| 910 | if not pipeline: |
| 911 | self.log.warning("Build %s is not associated with a pipeline" % |
| 912 | (build,)) |
| 913 | return |
| 914 | pipeline.manager.onBuildStarted(event.build) |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 915 | |
| 916 | def _doBuildCompletedEvent(self, event): |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 917 | build = event.build |
| 918 | if build.build_set is not build.build_set.item.current_build_set: |
| 919 | self.log.warning("Build %s is not in the current build set" % |
| 920 | (build,)) |
| 921 | return |
| 922 | pipeline = build.build_set.item.pipeline |
| 923 | if not pipeline: |
| 924 | self.log.warning("Build %s is not associated with a pipeline" % |
| 925 | (build,)) |
| 926 | return |
| 927 | pipeline.manager.onBuildCompleted(event.build) |
| 928 | |
| 929 | def _doMergeCompletedEvent(self, event): |
| 930 | build_set = event.build_set |
| 931 | if build_set is not build_set.item.current_build_set: |
| 932 | self.log.warning("Build set %s is not current" % (build_set,)) |
| 933 | return |
| 934 | pipeline = build_set.item.pipeline |
| 935 | if not pipeline: |
| 936 | self.log.warning("Build set %s is not associated with a pipeline" % |
| 937 | (build_set,)) |
| 938 | return |
| 939 | pipeline.manager.onMergeCompleted(event) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 940 | |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 941 | def formatStatusJSON(self): |
| 942 | data = {} |
Sergey Lukjanov | 5ba961b | 2013-12-27 01:21:04 +0400 | [diff] [blame] | 943 | |
| 944 | data['zuul_version'] = self.zuul_version |
| 945 | |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 946 | if self._pause: |
| 947 | ret = '<p><b>Queue only mode:</b> preparing to ' |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 948 | if self._exit: |
| 949 | ret += 'exit' |
| 950 | ret += ', queue length: %s' % self.trigger_event_queue.qsize() |
| 951 | ret += '</p>' |
| 952 | data['message'] = ret |
| 953 | |
James E. Blair | fb682cc | 2013-02-26 15:23:27 -0800 | [diff] [blame] | 954 | data['trigger_event_queue'] = {} |
| 955 | data['trigger_event_queue']['length'] = \ |
| 956 | self.trigger_event_queue.qsize() |
| 957 | data['result_event_queue'] = {} |
| 958 | data['result_event_queue']['length'] = \ |
| 959 | self.result_event_queue.qsize() |
| 960 | |
Sergey Lukjanov | 5d0438d | 2013-12-24 03:36:39 +0400 | [diff] [blame] | 961 | if self.last_reconfigured: |
| 962 | data['last_reconfigured'] = self.last_reconfigured * 1000 |
| 963 | |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 964 | pipelines = [] |
| 965 | data['pipelines'] = pipelines |
Alex Gaynor | fda4c35 | 2014-06-04 11:15:26 -0700 | [diff] [blame] | 966 | for pipeline in self.layout.pipelines.values(): |
James E. Blair | 8dbd56a | 2012-12-22 10:55:10 -0800 | [diff] [blame] | 967 | pipelines.append(pipeline.formatStatusJSON()) |
| 968 | return json.dumps(data) |
| 969 | |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 970 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 971 | class BasePipelineManager(object): |
| 972 | log = logging.getLogger("zuul.BasePipelineManager") |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 973 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 974 | def __init__(self, sched, pipeline): |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 975 | self.sched = sched |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 976 | self.pipeline = pipeline |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 977 | self.event_filters = [] |
James E. Blair | 11041d2 | 2014-05-02 14:49:53 -0700 | [diff] [blame] | 978 | self.changeish_filters = [] |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 979 | if self.sched.config and self.sched.config.has_option( |
| 980 | 'zuul', 'report_times'): |
James E. Blair | 0ac6c01 | 2013-04-26 09:04:23 -0700 | [diff] [blame] | 981 | self.report_times = self.sched.config.getboolean( |
| 982 | 'zuul', 'report_times') |
| 983 | else: |
| 984 | self.report_times = True |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 985 | |
| 986 | def __str__(self): |
James E. Blair | 93cc8d4 | 2012-08-07 10:46:51 -0700 | [diff] [blame] | 987 | return "<%s %s>" % (self.__class__.__name__, self.pipeline.name) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 988 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 989 | def _postConfig(self, layout): |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 990 | self.log.info("Configured Pipeline Manager %s" % self.pipeline.name) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 991 | self.log.info(" Source: %s" % self.pipeline.source) |
James E. Blair | 11041d2 | 2014-05-02 14:49:53 -0700 | [diff] [blame] | 992 | self.log.info(" Requirements:") |
| 993 | for f in self.changeish_filters: |
| 994 | self.log.info(" %s" % f) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 995 | self.log.info(" Events:") |
| 996 | for e in self.event_filters: |
| 997 | self.log.info(" %s" % e) |
| 998 | self.log.info(" Projects:") |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 999 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1000 | def log_jobs(tree, indent=0): |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 1001 | istr = ' ' + ' ' * indent |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1002 | if tree.job: |
| 1003 | efilters = '' |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1004 | for b in tree.job._branches: |
| 1005 | efilters += str(b) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1006 | for f in tree.job._files: |
| 1007 | efilters += str(f) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame^] | 1008 | if tree.job.skip_if_matcher: |
| 1009 | efilters += str(tree.job.skip_if_matcher) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1010 | if efilters: |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 1011 | efilters = ' ' + efilters |
James E. Blair | 222d498 | 2012-07-16 09:31:19 -0700 | [diff] [blame] | 1012 | hold = '' |
| 1013 | if tree.job.hold_following_changes: |
| 1014 | hold = ' [hold]' |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1015 | voting = '' |
| 1016 | if not tree.job.voting: |
| 1017 | voting = ' [nonvoting]' |
| 1018 | self.log.info("%s%s%s%s%s" % (istr, repr(tree.job), |
| 1019 | efilters, hold, voting)) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1020 | for x in tree.job_trees: |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 1021 | log_jobs(x, indent + 2) |
| 1022 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1023 | for p in layout.projects.values(): |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1024 | tree = self.pipeline.getJobTree(p) |
| 1025 | if tree: |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1026 | self.log.info(" %s" % p) |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1027 | log_jobs(tree) |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1028 | self.log.info(" On start:") |
| 1029 | self.log.info(" %s" % self.pipeline.start_actions) |
| 1030 | self.log.info(" On success:") |
| 1031 | self.log.info(" %s" % self.pipeline.success_actions) |
| 1032 | self.log.info(" On failure:") |
| 1033 | self.log.info(" %s" % self.pipeline.failure_actions) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1034 | self.log.info(" On merge-failure:") |
| 1035 | self.log.info(" %s" % self.pipeline.merge_failure_actions) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1036 | |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1037 | def getSubmitAllowNeeds(self): |
| 1038 | # Get a list of code review labels that are allowed to be |
| 1039 | # "needed" in the submit records for a change, with respect |
| 1040 | # to this queue. In other words, the list of review labels |
| 1041 | # this queue itself is likely to set before submitting. |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1042 | allow_needs = set() |
| 1043 | for action_reporter in self.pipeline.success_actions: |
| 1044 | allow_needs.update(action_reporter.getSubmitAllowNeeds()) |
| 1045 | return allow_needs |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1046 | |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 1047 | def eventMatches(self, event, change): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 1048 | if event.forced_pipeline: |
| 1049 | if event.forced_pipeline == self.pipeline.name: |
James E. Blair | 1b26531 | 2014-06-24 09:35:21 -0700 | [diff] [blame] | 1050 | self.log.debug("Event %s for change %s was directly assigned " |
| 1051 | "to pipeline %s" % (event, change, self)) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 1052 | return True |
| 1053 | else: |
| 1054 | return False |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1055 | for ef in self.event_filters: |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 1056 | if ef.matches(event, change): |
James E. Blair | 1b26531 | 2014-06-24 09:35:21 -0700 | [diff] [blame] | 1057 | self.log.debug("Event %s for change %s matched %s " |
| 1058 | "in pipeline %s" % (event, change, ef, self)) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1059 | return True |
| 1060 | return False |
| 1061 | |
James E. Blair | 0dc8ba9 | 2012-07-16 14:23:52 -0700 | [diff] [blame] | 1062 | def isChangeAlreadyInQueue(self, change): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1063 | for c in self.pipeline.getChangesInQueue(): |
James E. Blair | 0dc8ba9 | 2012-07-16 14:23:52 -0700 | [diff] [blame] | 1064 | if change.equals(c): |
| 1065 | return True |
| 1066 | return False |
| 1067 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1068 | def reportStart(self, change): |
| 1069 | try: |
| 1070 | self.log.info("Reporting start, action %s change %s" % |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1071 | (self.pipeline.start_actions, change)) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1072 | msg = "Starting %s jobs." % self.pipeline.name |
Clark Boylan | 9b67090 | 2012-09-28 13:47:56 -0700 | [diff] [blame] | 1073 | if self.sched.config.has_option('zuul', 'status_url'): |
| 1074 | msg += "\n" + self.sched.config.get('zuul', 'status_url') |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1075 | ret = self.sendReport(self.pipeline.start_actions, |
| 1076 | change, msg) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1077 | if ret: |
| 1078 | self.log.error("Reporting change start %s received: %s" % |
| 1079 | (change, ret)) |
| 1080 | except: |
| 1081 | self.log.exception("Exception while reporting start:") |
| 1082 | |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1083 | def sendReport(self, action_reporters, change, message): |
| 1084 | """Sends the built message off to configured reporters. |
| 1085 | |
| 1086 | Takes the action_reporters, change, message and extra options and |
| 1087 | sends them to the pluggable reporters. |
| 1088 | """ |
| 1089 | report_errors = [] |
| 1090 | if len(action_reporters) > 0: |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1091 | for action_reporter in action_reporters: |
| 1092 | ret = action_reporter.report(change, message) |
| 1093 | if ret: |
| 1094 | report_errors.append(ret) |
| 1095 | if len(report_errors) == 0: |
| 1096 | return |
| 1097 | return report_errors |
| 1098 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1099 | def isChangeReadyToBeEnqueued(self, change): |
| 1100 | return True |
| 1101 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1102 | def enqueueChangesAhead(self, change, quiet, ignore_requirements): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1103 | return True |
| 1104 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1105 | def enqueueChangesBehind(self, change, quiet, ignore_requirements): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1106 | return True |
| 1107 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1108 | def checkForChangesNeededBy(self, change): |
| 1109 | return True |
| 1110 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1111 | def getFailingDependentItem(self, item): |
| 1112 | return None |
| 1113 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1114 | def getDependentItems(self, item): |
| 1115 | orig_item = item |
| 1116 | items = [] |
| 1117 | while item.item_ahead: |
| 1118 | items.append(item.item_ahead) |
| 1119 | item = item.item_ahead |
| 1120 | self.log.info("Change %s depends on changes %s" % |
| 1121 | (orig_item.change, |
| 1122 | [x.change for x in items])) |
| 1123 | return items |
| 1124 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1125 | def getItemForChange(self, change): |
| 1126 | for item in self.pipeline.getAllItems(): |
| 1127 | if item.change.equals(change): |
| 1128 | return item |
| 1129 | return None |
| 1130 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1131 | def findOldVersionOfChangeAlreadyInQueue(self, change): |
| 1132 | for c in self.pipeline.getChangesInQueue(): |
| 1133 | if change.isUpdateOf(c): |
| 1134 | return c |
| 1135 | return None |
| 1136 | |
| 1137 | def removeOldVersionsOfChange(self, change): |
| 1138 | if not self.pipeline.dequeue_on_new_patchset: |
| 1139 | return |
| 1140 | old_change = self.findOldVersionOfChangeAlreadyInQueue(change) |
| 1141 | if old_change: |
| 1142 | self.log.debug("Change %s is a new version of %s, removing %s" % |
| 1143 | (change, old_change, old_change)) |
| 1144 | self.removeChange(old_change) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1145 | |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1146 | def removeAbandonedChange(self, change): |
| 1147 | self.log.debug("Change %s abandoned, removing." % change) |
| 1148 | self.removeChange(change) |
| 1149 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1150 | def reEnqueueItem(self, item): |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 1151 | change_queue = self.pipeline.getQueue(item.change.project) |
| 1152 | if change_queue: |
| 1153 | self.log.debug("Re-enqueing change %s in queue %s" % |
| 1154 | (item.change, change_queue)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1155 | change_queue.enqueueItem(item) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 1156 | self.reportStats(item) |
| 1157 | return True |
| 1158 | else: |
| 1159 | self.log.error("Unable to find change queue for project %s" % |
| 1160 | item.change.project) |
| 1161 | return False |
| 1162 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1163 | def addChange(self, change, quiet=False, enqueue_time=None, |
| 1164 | ignore_requirements=False): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1165 | self.log.debug("Considering adding change %s" % change) |
James E. Blair | 0dc8ba9 | 2012-07-16 14:23:52 -0700 | [diff] [blame] | 1166 | if self.isChangeAlreadyInQueue(change): |
| 1167 | self.log.debug("Change %s is already in queue, ignoring" % change) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1168 | return True |
James E. Blair | 692c6b3 | 2012-07-17 11:16:35 -0700 | [diff] [blame] | 1169 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1170 | if not self.isChangeReadyToBeEnqueued(change): |
| 1171 | self.log.debug("Change %s is not ready to be enqueued, ignoring" % |
| 1172 | change) |
| 1173 | return False |
| 1174 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1175 | if not ignore_requirements: |
| 1176 | for f in self.changeish_filters: |
| 1177 | if not f.matches(change): |
| 1178 | self.log.debug("Change %s does not match pipeline " |
| 1179 | "requirement %s" % (change, f)) |
| 1180 | return False |
James E. Blair | 11041d2 | 2014-05-02 14:49:53 -0700 | [diff] [blame] | 1181 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1182 | if not self.enqueueChangesAhead(change, quiet, ignore_requirements): |
James E. Blair | 1490eba | 2013-03-06 19:14:00 -0800 | [diff] [blame] | 1183 | self.log.debug("Failed to enqueue changes ahead of %s" % change) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1184 | return False |
| 1185 | |
| 1186 | if self.isChangeAlreadyInQueue(change): |
| 1187 | self.log.debug("Change %s is already in queue, ignoring" % change) |
| 1188 | return True |
| 1189 | |
| 1190 | change_queue = self.pipeline.getQueue(change.project) |
| 1191 | if change_queue: |
| 1192 | self.log.debug("Adding change %s to queue %s" % |
| 1193 | (change, change_queue)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 1194 | if not quiet: |
| 1195 | if len(self.pipeline.start_actions) > 0: |
| 1196 | self.reportStart(change) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1197 | item = change_queue.enqueueChange(change) |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 1198 | if enqueue_time: |
| 1199 | item.enqueue_time = enqueue_time |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1200 | self.reportStats(item) |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1201 | self.enqueueChangesBehind(change, quiet, ignore_requirements) |
Joshua Hesketh | 29d99b7 | 2014-08-19 16:27:42 +1000 | [diff] [blame] | 1202 | self.sched.triggers['zuul'].onChangeEnqueued(item.change, |
| 1203 | self.pipeline) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1204 | else: |
| 1205 | self.log.error("Unable to find change queue for project %s" % |
| 1206 | change.project) |
| 1207 | return False |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1208 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1209 | def dequeueItem(self, item): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1210 | self.log.debug("Removing change %s from queue" % item.change) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1211 | change_queue = self.pipeline.getQueue(item.change.project) |
| 1212 | change_queue.dequeueItem(item) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1213 | |
| 1214 | def removeChange(self, change): |
| 1215 | # Remove a change from the queue, probably because it has been |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1216 | # superseded by another change. |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1217 | for item in self.pipeline.getAllItems(): |
| 1218 | if item.change == change: |
| 1219 | self.log.debug("Canceling builds behind change: %s " |
| 1220 | "because it is being removed." % item.change) |
| 1221 | self.cancelJobs(item) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1222 | self.dequeueItem(item) |
James E. Blair | 9423556 | 2013-08-26 18:12:31 -0700 | [diff] [blame] | 1223 | self.reportStats(item) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1224 | |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1225 | def _makeMergerItem(self, item): |
| 1226 | # Create a dictionary with all info about the item needed by |
| 1227 | # the merger. |
Clark Boylan | 4c6566b | 2014-03-10 11:02:01 -0700 | [diff] [blame] | 1228 | number = None |
| 1229 | patchset = None |
| 1230 | oldrev = None |
| 1231 | newrev = None |
| 1232 | if hasattr(item.change, 'number'): |
| 1233 | number = item.change.number |
| 1234 | patchset = item.change.patchset |
| 1235 | elif hasattr(item.change, 'newrev'): |
| 1236 | oldrev = item.change.oldrev |
| 1237 | newrev = item.change.newrev |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1238 | return dict(project=item.change.project.name, |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1239 | url=self.pipeline.source.getGitUrl( |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1240 | item.change.project), |
| 1241 | merge_mode=item.change.project.merge_mode, |
| 1242 | refspec=item.change.refspec, |
| 1243 | branch=item.change.branch, |
| 1244 | ref=item.current_build_set.ref, |
Clark Boylan | 4c6566b | 2014-03-10 11:02:01 -0700 | [diff] [blame] | 1245 | number=number, |
| 1246 | patchset=patchset, |
| 1247 | oldrev=oldrev, |
| 1248 | newrev=newrev, |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1249 | ) |
| 1250 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1251 | def prepareRef(self, item): |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1252 | # Returns True if the ref is ready, false otherwise |
| 1253 | build_set = item.current_build_set |
| 1254 | if build_set.merge_state == build_set.COMPLETE: |
| 1255 | return True |
| 1256 | if build_set.merge_state == build_set.PENDING: |
| 1257 | return False |
| 1258 | build_set.merge_state = build_set.PENDING |
| 1259 | ref = build_set.ref |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1260 | if hasattr(item.change, 'refspec') and not ref: |
| 1261 | self.log.debug("Preparing ref for: %s" % item.change) |
| 1262 | item.current_build_set.setConfiguration() |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1263 | dependent_items = self.getDependentItems(item) |
| 1264 | dependent_items.reverse() |
| 1265 | all_items = dependent_items + [item] |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1266 | merger_items = map(self._makeMergerItem, all_items) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1267 | self.sched.merger.mergeChanges(merger_items, |
James E. Blair | e9a8184 | 2014-09-24 13:37:45 -0700 | [diff] [blame] | 1268 | item.current_build_set, |
| 1269 | self.pipeline.precedence) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1270 | else: |
| 1271 | self.log.debug("Preparing update repo for: %s" % item.change) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1272 | url = self.pipeline.source.getGitUrl(item.change.project) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1273 | self.sched.merger.updateRepo(item.change.project.name, |
James E. Blair | e9a8184 | 2014-09-24 13:37:45 -0700 | [diff] [blame] | 1274 | url, build_set, |
| 1275 | self.pipeline.precedence) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1276 | return False |
| 1277 | |
| 1278 | def _launchJobs(self, item, jobs): |
| 1279 | self.log.debug("Launching jobs for change %s" % item.change) |
| 1280 | dependent_items = self.getDependentItems(item) |
| 1281 | for job in jobs: |
| 1282 | self.log.debug("Found job %s for change %s" % (job, item.change)) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1283 | try: |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1284 | build = self.sched.launcher.launch(job, item, |
| 1285 | self.pipeline, |
| 1286 | dependent_items) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1287 | self.log.debug("Adding build %s of job %s to item %s" % |
| 1288 | (build, job, item)) |
| 1289 | item.addBuild(build) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1290 | except: |
Zhongyue Luo | 1c860d7 | 2012-07-19 11:03:56 +0800 | [diff] [blame] | 1291 | self.log.exception("Exception while launching job %s " |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1292 | "for change %s:" % (job, item.change)) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1293 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1294 | def launchJobs(self, item): |
| 1295 | jobs = self.pipeline.findJobsToRun(item) |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1296 | if jobs: |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1297 | self._launchJobs(item, jobs) |
| 1298 | |
| 1299 | def cancelJobs(self, item, prime=True): |
| 1300 | self.log.debug("Cancel jobs for change %s" % item.change) |
| 1301 | canceled = False |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 1302 | old_build_set = item.current_build_set |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 1303 | if prime and item.current_build_set.ref: |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1304 | item.resetAllBuilds() |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 1305 | for build in old_build_set.getBuilds(): |
| 1306 | try: |
| 1307 | self.sched.launcher.cancel(build) |
| 1308 | except: |
| 1309 | self.log.exception("Exception while canceling build %s " |
| 1310 | "for change %s" % (build, item.change)) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1311 | build.result = 'CANCELED' |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 1312 | canceled = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1313 | for item_behind in item.items_behind: |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1314 | self.log.debug("Canceling jobs for change %s, behind change %s" % |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1315 | (item_behind.change, item.change)) |
| 1316 | if self.cancelJobs(item_behind, prime=prime): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1317 | canceled = True |
| 1318 | return canceled |
| 1319 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1320 | def _processOneItem(self, item, nnfi, ready_ahead): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1321 | changed = False |
| 1322 | item_ahead = item.item_ahead |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1323 | change_queue = self.pipeline.getQueue(item.change.project) |
| 1324 | failing_reasons = [] # Reasons this item is failing |
| 1325 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1326 | if self.checkForChangesNeededBy(item.change) is not True: |
| 1327 | # It's not okay to enqueue this change, we should remove it. |
| 1328 | self.log.info("Dequeuing change %s because " |
| 1329 | "it can no longer merge" % item.change) |
| 1330 | self.cancelJobs(item) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1331 | self.dequeueItem(item) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1332 | self.pipeline.setDequeuedNeedingChange(item) |
| 1333 | try: |
| 1334 | self.reportItem(item) |
| 1335 | except MergeFailure: |
| 1336 | pass |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1337 | return (True, nnfi, ready_ahead) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1338 | dep_item = self.getFailingDependentItem(item) |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 1339 | actionable = change_queue.isActionable(item) |
| 1340 | item.active = actionable |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1341 | ready = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1342 | if dep_item: |
| 1343 | failing_reasons.append('a needed change is failing') |
| 1344 | self.cancelJobs(item, prime=False) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1345 | else: |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 1346 | item_ahead_merged = False |
| 1347 | if ((item_ahead and item_ahead.change.is_merged) or |
| 1348 | not change_queue.dependent): |
| 1349 | item_ahead_merged = True |
| 1350 | if (item_ahead != nnfi and not item_ahead_merged): |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1351 | # Our current base is different than what we expected, |
| 1352 | # and it's not because our current base merged. Something |
| 1353 | # ahead must have failed. |
| 1354 | self.log.info("Resetting builds for change %s because the " |
| 1355 | "item ahead, %s, is not the nearest non-failing " |
| 1356 | "item, %s" % (item.change, item_ahead, nnfi)) |
| 1357 | change_queue.moveItem(item, nnfi) |
| 1358 | changed = True |
| 1359 | self.cancelJobs(item) |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 1360 | if actionable: |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1361 | ready = self.prepareRef(item) |
Clark Boylan | 3d2f7a7 | 2014-01-23 11:07:42 -0800 | [diff] [blame] | 1362 | if item.current_build_set.unable_to_merge: |
| 1363 | failing_reasons.append("it has a merge conflict") |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1364 | ready = False |
| 1365 | if not ready: |
| 1366 | ready_ahead = False |
| 1367 | if actionable and ready_ahead and self.launchJobs(item): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1368 | changed = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1369 | if self.pipeline.didAnyJobFail(item): |
| 1370 | failing_reasons.append("at least one job failed") |
| 1371 | if (not item_ahead) and self.pipeline.areAllJobsComplete(item): |
| 1372 | try: |
| 1373 | self.reportItem(item) |
| 1374 | except MergeFailure: |
James E. Blair | 062c4fb | 2013-09-26 07:46:00 -0700 | [diff] [blame] | 1375 | failing_reasons.append("it did not merge") |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1376 | for item_behind in item.items_behind: |
| 1377 | self.log.info("Resetting builds for change %s because the " |
| 1378 | "item ahead, %s, failed to merge" % |
| 1379 | (item_behind.change, item)) |
| 1380 | self.cancelJobs(item_behind) |
| 1381 | self.dequeueItem(item) |
| 1382 | changed = True |
| 1383 | elif not failing_reasons: |
| 1384 | nnfi = item |
| 1385 | item.current_build_set.failing_reasons = failing_reasons |
| 1386 | if failing_reasons: |
| 1387 | self.log.debug("%s is a failing item because %s" % |
| 1388 | (item, failing_reasons)) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1389 | return (changed, nnfi, ready_ahead) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1390 | |
| 1391 | def processQueue(self): |
| 1392 | # Do whatever needs to be done for each change in the queue |
| 1393 | self.log.debug("Starting queue processor: %s" % self.pipeline.name) |
| 1394 | changed = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1395 | for queue in self.pipeline.queues: |
| 1396 | queue_changed = False |
| 1397 | nnfi = None # Nearest non-failing item |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1398 | ready_ahead = True # All build sets ahead are ready |
Clark Boylan | 3d2f7a7 | 2014-01-23 11:07:42 -0800 | [diff] [blame] | 1399 | for item in queue.queue[:]: |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1400 | item_changed, nnfi, ready_ahhead = self._processOneItem( |
| 1401 | item, nnfi, ready_ahead) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1402 | if item_changed: |
| 1403 | queue_changed = True |
| 1404 | self.reportStats(item) |
| 1405 | if queue_changed: |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1406 | changed = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1407 | status = '' |
| 1408 | for item in queue.queue: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 1409 | status += item.formatStatus() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1410 | if status: |
| 1411 | self.log.debug("Queue %s status is now:\n %s" % |
| 1412 | (queue.name, status)) |
James E. Blair | fadc6e1 | 2013-08-21 18:23:15 -0700 | [diff] [blame] | 1413 | self.log.debug("Finished queue processor: %s (changed: %s)" % |
| 1414 | (self.pipeline.name, changed)) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1415 | return changed |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1416 | |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 1417 | def updateBuildDescriptions(self, build_set): |
| 1418 | for build in build_set.getBuilds(): |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1419 | desc = self.formatDescription(build) |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 1420 | self.sched.launcher.setBuildDescription(build, desc) |
| 1421 | |
| 1422 | if build_set.previous_build_set: |
| 1423 | for build in build_set.previous_build_set.getBuilds(): |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1424 | desc = self.formatDescription(build) |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 1425 | self.sched.launcher.setBuildDescription(build, desc) |
| 1426 | |
| 1427 | def onBuildStarted(self, build): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1428 | self.log.debug("Build %s started" % build) |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 1429 | self.updateBuildDescriptions(build.build_set) |
| 1430 | return True |
| 1431 | |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1432 | def onBuildCompleted(self, build): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1433 | self.log.debug("Build %s completed" % build) |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 1434 | item = build.build_set.item |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1435 | |
James E. Blair | 6b07794 | 2014-02-07 17:45:55 -0800 | [diff] [blame] | 1436 | self.pipeline.setResult(item, build) |
| 1437 | self.log.debug("Item %s status is now:\n %s" % |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 1438 | (item, item.formatStatus())) |
James E. Blair | 11700c3 | 2012-07-05 17:50:05 -0700 | [diff] [blame] | 1439 | self.updateBuildDescriptions(build.build_set) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1440 | return True |
| 1441 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1442 | def onMergeCompleted(self, event): |
| 1443 | build_set = event.build_set |
| 1444 | item = build_set.item |
| 1445 | build_set.merge_state = build_set.COMPLETE |
| 1446 | build_set.zuul_url = event.zuul_url |
| 1447 | if event.merged: |
| 1448 | build_set.commit = event.commit |
| 1449 | elif event.updated: |
| 1450 | build_set.commit = item.change.newrev |
| 1451 | if not build_set.commit: |
| 1452 | self.log.info("Unable to merge change %s" % item.change) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1453 | self.pipeline.setUnableToMerge(item) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1454 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1455 | def reportItem(self, item): |
Clark Boylan | f7dc4da | 2014-07-28 10:12:25 -0700 | [diff] [blame] | 1456 | if not item.reported: |
| 1457 | # _reportItem() returns True if it failed to report. |
| 1458 | item.reported = not self._reportItem(item) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1459 | if self.changes_merge: |
| 1460 | succeeded = self.pipeline.didAllJobsSucceed(item) |
Clark Boylan | f7dc4da | 2014-07-28 10:12:25 -0700 | [diff] [blame] | 1461 | merged = item.reported |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1462 | if merged: |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1463 | merged = self.pipeline.source.isMerged(item.change, |
| 1464 | item.change.branch) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1465 | self.log.info("Reported change %s status: all-succeeded: %s, " |
| 1466 | "merged: %s" % (item.change, succeeded, merged)) |
James E. Blair | 4a035d9 | 2014-01-23 13:10:48 -0800 | [diff] [blame] | 1467 | change_queue = self.pipeline.getQueue(item.change.project) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1468 | if not (succeeded and merged): |
| 1469 | self.log.debug("Reported change %s failed tests or failed " |
| 1470 | "to merge" % (item.change)) |
James E. Blair | 4a035d9 | 2014-01-23 13:10:48 -0800 | [diff] [blame] | 1471 | change_queue.decreaseWindowSize() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 1472 | self.log.debug("%s window size decreased to %s" % |
James E. Blair | 4a035d9 | 2014-01-23 13:10:48 -0800 | [diff] [blame] | 1473 | (change_queue, change_queue.window)) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1474 | raise MergeFailure("Change %s failed to merge" % item.change) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 1475 | else: |
James E. Blair | 4a035d9 | 2014-01-23 13:10:48 -0800 | [diff] [blame] | 1476 | change_queue.increaseWindowSize() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 1477 | self.log.debug("%s window size increased to %s" % |
James E. Blair | 4a035d9 | 2014-01-23 13:10:48 -0800 | [diff] [blame] | 1478 | (change_queue, change_queue.window)) |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 1479 | self.sched.triggers['zuul'].onChangeMerged(item.change) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1480 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1481 | def _reportItem(self, item): |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1482 | self.log.debug("Reporting change %s" % item.change) |
James E. Blair | b98fcdb | 2013-08-26 18:23:09 -0700 | [diff] [blame] | 1483 | ret = True # Means error as returned by trigger.report |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1484 | if self.pipeline.didAllJobsSucceed(item): |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1485 | self.log.debug("success %s" % (self.pipeline.success_actions)) |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1486 | actions = self.pipeline.success_actions |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1487 | item.setReportedResult('SUCCESS') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1488 | elif not self.pipeline.didMergerSucceed(item): |
| 1489 | actions = self.pipeline.merge_failure_actions |
| 1490 | item.setReportedResult('MERGER_FAILURE') |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1491 | else: |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 1492 | actions = self.pipeline.failure_actions |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1493 | item.setReportedResult('FAILURE') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 1494 | if actions: |
| 1495 | report = self.formatReport(item) |
| 1496 | try: |
| 1497 | self.log.info("Reporting change %s, actions: %s" % |
| 1498 | (item.change, actions)) |
| 1499 | ret = self.sendReport(actions, item.change, report) |
| 1500 | if ret: |
| 1501 | self.log.error("Reporting change %s received: %s" % |
| 1502 | (item.change, ret)) |
| 1503 | except: |
| 1504 | self.log.exception("Exception while reporting:") |
| 1505 | item.setReportedResult('ERROR') |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1506 | self.updateBuildDescriptions(item.current_build_set) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1507 | return ret |
| 1508 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1509 | def formatReport(self, item): |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1510 | ret = '' |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1511 | |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1512 | if item.dequeued_needing_change: |
| 1513 | ret += 'This change depends on a change that failed to merge.\n' |
| 1514 | elif not self.pipeline.didMergerSucceed(item): |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1515 | ret += self.pipeline.merge_failure_message |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1516 | else: |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1517 | if self.pipeline.didAllJobsSucceed(item): |
| 1518 | ret += self.pipeline.success_message + '\n\n' |
| 1519 | else: |
| 1520 | ret += self.pipeline.failure_message + '\n\n' |
| 1521 | ret += self._formatReportJobs(item) |
| 1522 | |
| 1523 | if self.pipeline.footer_message: |
| 1524 | ret += '\n' + self.pipeline.footer_message |
| 1525 | |
| 1526 | return ret |
| 1527 | |
| 1528 | def _formatReportJobs(self, item): |
| 1529 | # Return the list of jobs portion of the report |
| 1530 | ret = '' |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1531 | |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1532 | if self.sched.config.has_option('zuul', 'url_pattern'): |
| 1533 | url_pattern = self.sched.config.get('zuul', 'url_pattern') |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1534 | else: |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1535 | url_pattern = None |
| 1536 | |
| 1537 | for job in self.pipeline.getJobs(item.change): |
| 1538 | build = item.current_build_set.getBuild(job.name) |
| 1539 | result = build.result |
| 1540 | pattern = url_pattern |
| 1541 | if result == 'SUCCESS': |
| 1542 | if job.success_message: |
| 1543 | result = job.success_message |
| 1544 | if job.success_pattern: |
| 1545 | pattern = job.success_pattern |
| 1546 | elif result == 'FAILURE': |
| 1547 | if job.failure_message: |
| 1548 | result = job.failure_message |
| 1549 | if job.failure_pattern: |
| 1550 | pattern = job.failure_pattern |
| 1551 | if pattern: |
Jeremy Stanley | c6d4bc8 | 2014-08-01 19:11:29 +0000 | [diff] [blame] | 1552 | url = pattern.format(change=item.change, |
| 1553 | pipeline=self.pipeline, |
| 1554 | job=job, |
| 1555 | build=build) |
James E. Blair | a35fcce | 2012-08-24 10:46:01 -0700 | [diff] [blame] | 1556 | else: |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1557 | url = build.url or job.name |
| 1558 | if not job.voting: |
| 1559 | voting = ' (non-voting)' |
| 1560 | else: |
| 1561 | voting = '' |
| 1562 | if self.report_times and build.end_time and build.start_time: |
| 1563 | dt = int(build.end_time - build.start_time) |
| 1564 | m, s = divmod(dt, 60) |
| 1565 | h, m = divmod(m, 60) |
| 1566 | if h: |
| 1567 | elapsed = ' in %dh %02dm %02ds' % (h, m, s) |
| 1568 | elif m: |
| 1569 | elapsed = ' in %dm %02ds' % (m, s) |
Ori Livneh | 7191ee8 | 2013-05-02 19:13:53 -0700 | [diff] [blame] | 1570 | else: |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 1571 | elapsed = ' in %ds' % (s) |
| 1572 | else: |
| 1573 | elapsed = '' |
| 1574 | name = '' |
| 1575 | if self.sched.config.has_option('zuul', 'job_name_in_report'): |
| 1576 | if self.sched.config.getboolean('zuul', |
| 1577 | 'job_name_in_report'): |
| 1578 | name = job.name + ' ' |
| 1579 | ret += '- %s%s : %s%s%s\n' % (name, url, result, elapsed, |
| 1580 | voting) |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1581 | return ret |
| 1582 | |
| 1583 | def formatDescription(self, build): |
| 1584 | concurrent_changes = '' |
| 1585 | concurrent_builds = '' |
| 1586 | other_builds = '' |
| 1587 | |
| 1588 | for change in build.build_set.other_changes: |
| 1589 | concurrent_changes += '<li><a href="{change.url}">\ |
| 1590 | {change.number},{change.patchset}</a></li>'.format( |
| 1591 | change=change) |
| 1592 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1593 | change = build.build_set.item.change |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1594 | |
| 1595 | for build in build.build_set.getBuilds(): |
Ori Livneh | 7191ee8 | 2013-05-02 19:13:53 -0700 | [diff] [blame] | 1596 | if build.url: |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1597 | concurrent_builds += """\ |
| 1598 | <li> |
Ori Livneh | 7191ee8 | 2013-05-02 19:13:53 -0700 | [diff] [blame] | 1599 | <a href="{build.url}"> |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1600 | {build.job.name} #{build.number}</a>: {build.result} |
| 1601 | </li> |
| 1602 | """.format(build=build) |
| 1603 | else: |
| 1604 | concurrent_builds += """\ |
| 1605 | <li> |
| 1606 | {build.job.name}: {build.result} |
| 1607 | </li>""".format(build=build) |
| 1608 | |
| 1609 | if build.build_set.previous_build_set: |
| 1610 | other_build = build.build_set.previous_build_set.getBuild( |
| 1611 | build.job.name) |
| 1612 | if other_build: |
| 1613 | other_builds += """\ |
| 1614 | <li> |
Ori Livneh | 7191ee8 | 2013-05-02 19:13:53 -0700 | [diff] [blame] | 1615 | Preceded by: <a href="{build.url}"> |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1616 | {build.job.name} #{build.number}</a> |
| 1617 | </li> |
| 1618 | """.format(build=other_build) |
| 1619 | |
| 1620 | if build.build_set.next_build_set: |
| 1621 | other_build = build.build_set.next_build_set.getBuild( |
| 1622 | build.job.name) |
| 1623 | if other_build: |
| 1624 | other_builds += """\ |
| 1625 | <li> |
Ori Livneh | 7191ee8 | 2013-05-02 19:13:53 -0700 | [diff] [blame] | 1626 | Succeeded by: <a href="{build.url}"> |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1627 | {build.job.name} #{build.number}</a> |
| 1628 | </li> |
| 1629 | """.format(build=other_build) |
| 1630 | |
| 1631 | result = build.build_set.result |
| 1632 | |
| 1633 | if hasattr(change, 'number'): |
| 1634 | ret = """\ |
| 1635 | <p> |
| 1636 | Triggered by change: |
| 1637 | <a href="{change.url}">{change.number},{change.patchset}</a><br/> |
| 1638 | Branch: <b>{change.branch}</b><br/> |
| 1639 | Pipeline: <b>{self.pipeline.name}</b> |
| 1640 | </p>""" |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 1641 | elif hasattr(change, 'ref'): |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1642 | ret = """\ |
| 1643 | <p> |
| 1644 | Triggered by reference: |
| 1645 | {change.ref}</a><br/> |
| 1646 | Old revision: <b>{change.oldrev}</b><br/> |
| 1647 | New revision: <b>{change.newrev}</b><br/> |
| 1648 | Pipeline: <b>{self.pipeline.name}</b> |
| 1649 | </p>""" |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 1650 | else: |
| 1651 | ret = "" |
James E. Blair | 8b0d4c4 | 2012-08-23 16:03:05 -0700 | [diff] [blame] | 1652 | |
| 1653 | if concurrent_changes: |
| 1654 | ret += """\ |
| 1655 | <p> |
| 1656 | Other changes tested concurrently with this change: |
| 1657 | <ul>{concurrent_changes}</ul> |
| 1658 | </p> |
| 1659 | """ |
| 1660 | if concurrent_builds: |
| 1661 | ret += """\ |
| 1662 | <p> |
| 1663 | All builds for this change set: |
| 1664 | <ul>{concurrent_builds}</ul> |
| 1665 | </p> |
| 1666 | """ |
| 1667 | |
| 1668 | if other_builds: |
| 1669 | ret += """\ |
| 1670 | <p> |
| 1671 | Other build sets for this change: |
| 1672 | <ul>{other_builds}</ul> |
| 1673 | </p> |
| 1674 | """ |
| 1675 | if result: |
| 1676 | ret += """\ |
| 1677 | <p> |
| 1678 | Reported result: <b>{result}</b> |
| 1679 | </p> |
| 1680 | """ |
| 1681 | |
| 1682 | ret = ret.format(**locals()) |
James E. Blair | 268d934 | 2012-06-13 18:24:29 -0700 | [diff] [blame] | 1683 | return ret |
| 1684 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1685 | def reportStats(self, item): |
James E. Blair | 8fa1697 | 2013-01-15 16:57:20 -0800 | [diff] [blame] | 1686 | if not statsd: |
| 1687 | return |
| 1688 | try: |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1689 | # Update the gauge on enqueue and dequeue, but timers only |
James E. Blair | 8fa1697 | 2013-01-15 16:57:20 -0800 | [diff] [blame] | 1690 | # when dequeing. |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1691 | if item.dequeue_time: |
| 1692 | dt = int((item.dequeue_time - item.enqueue_time) * 1000) |
James E. Blair | 8fa1697 | 2013-01-15 16:57:20 -0800 | [diff] [blame] | 1693 | else: |
| 1694 | dt = None |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1695 | items = len(self.pipeline.getAllItems()) |
James E. Blair | 8fa1697 | 2013-01-15 16:57:20 -0800 | [diff] [blame] | 1696 | |
| 1697 | # stats.timers.zuul.pipeline.NAME.resident_time |
| 1698 | # stats_counts.zuul.pipeline.NAME.total_changes |
| 1699 | # stats.gauges.zuul.pipeline.NAME.current_changes |
| 1700 | key = 'zuul.pipeline.%s' % self.pipeline.name |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1701 | statsd.gauge(key + '.current_changes', items) |
James E. Blair | 8fa1697 | 2013-01-15 16:57:20 -0800 | [diff] [blame] | 1702 | if dt: |
| 1703 | statsd.timing(key + '.resident_time', dt) |
| 1704 | statsd.incr(key + '.total_changes') |
| 1705 | |
| 1706 | # stats.timers.zuul.pipeline.NAME.ORG.PROJECT.resident_time |
| 1707 | # stats_counts.zuul.pipeline.NAME.ORG.PROJECT.total_changes |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 1708 | project_name = item.change.project.name.replace('/', '.') |
James E. Blair | 8fa1697 | 2013-01-15 16:57:20 -0800 | [diff] [blame] | 1709 | key += '.%s' % project_name |
| 1710 | if dt: |
| 1711 | statsd.timing(key + '.resident_time', dt) |
| 1712 | statsd.incr(key + '.total_changes') |
| 1713 | except: |
| 1714 | self.log.exception("Exception reporting pipeline stats") |
| 1715 | |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 1716 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1717 | class IndependentPipelineManager(BasePipelineManager): |
| 1718 | log = logging.getLogger("zuul.IndependentPipelineManager") |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1719 | changes_merge = False |
| 1720 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1721 | def _postConfig(self, layout): |
| 1722 | super(IndependentPipelineManager, self)._postConfig(layout) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1723 | |
| 1724 | change_queue = ChangeQueue(self.pipeline, dependent=False) |
| 1725 | for project in self.pipeline.getProjects(): |
| 1726 | change_queue.addProject(project) |
| 1727 | |
| 1728 | self.pipeline.addQueue(change_queue) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1729 | |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 1730 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1731 | class DependentPipelineManager(BasePipelineManager): |
| 1732 | log = logging.getLogger("zuul.DependentPipelineManager") |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1733 | changes_merge = True |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1734 | |
| 1735 | def __init__(self, *args, **kwargs): |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1736 | super(DependentPipelineManager, self).__init__(*args, **kwargs) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1737 | |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1738 | def _postConfig(self, layout): |
| 1739 | super(DependentPipelineManager, self)._postConfig(layout) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1740 | self.buildChangeQueues() |
| 1741 | |
| 1742 | def buildChangeQueues(self): |
| 1743 | self.log.debug("Building shared change queues") |
| 1744 | change_queues = [] |
| 1745 | |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1746 | for project in self.pipeline.getProjects(): |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 1747 | change_queue = ChangeQueue( |
| 1748 | self.pipeline, |
| 1749 | window=self.pipeline.window, |
| 1750 | window_floor=self.pipeline.window_floor, |
| 1751 | window_increase_type=self.pipeline.window_increase_type, |
| 1752 | window_increase_factor=self.pipeline.window_increase_factor, |
| 1753 | window_decrease_type=self.pipeline.window_decrease_type, |
| 1754 | window_decrease_factor=self.pipeline.window_decrease_factor) |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1755 | change_queue.addProject(project) |
| 1756 | change_queues.append(change_queue) |
| 1757 | self.log.debug("Created queue: %s" % change_queue) |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1758 | |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 1759 | # Iterate over all queues trying to combine them, and keep doing |
| 1760 | # so until they can not be combined further. |
| 1761 | last_change_queues = change_queues |
| 1762 | while True: |
| 1763 | new_change_queues = self.combineChangeQueues(last_change_queues) |
| 1764 | if len(last_change_queues) == len(new_change_queues): |
| 1765 | break |
| 1766 | last_change_queues = new_change_queues |
| 1767 | |
| 1768 | self.log.info(" Shared change queues:") |
| 1769 | for queue in new_change_queues: |
| 1770 | self.pipeline.addQueue(queue) |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 1771 | self.log.info(" %s containing %s" % ( |
| 1772 | queue, queue.generated_name)) |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 1773 | |
| 1774 | def combineChangeQueues(self, change_queues): |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1775 | self.log.debug("Combining shared queues") |
| 1776 | new_change_queues = [] |
| 1777 | for a in change_queues: |
| 1778 | merged_a = False |
| 1779 | for b in new_change_queues: |
| 1780 | if not a.getJobs().isdisjoint(b.getJobs()): |
| 1781 | self.log.debug("Merging queue %s into %s" % (a, b)) |
| 1782 | b.mergeChangeQueue(a) |
| 1783 | merged_a = True |
| 1784 | break # this breaks out of 'for b' and continues 'for a' |
| 1785 | if not merged_a: |
| 1786 | self.log.debug("Keeping queue %s" % (a)) |
| 1787 | new_change_queues.append(a) |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 1788 | return new_change_queues |
James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1789 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1790 | def isChangeReadyToBeEnqueued(self, change): |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1791 | if not self.pipeline.source.canMerge(change, |
| 1792 | self.getSubmitAllowNeeds()): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1793 | self.log.debug("Change %s can not merge, ignoring" % change) |
| 1794 | return False |
| 1795 | return True |
James E. Blair | 1e8dd89 | 2012-05-30 09:15:05 -0700 | [diff] [blame] | 1796 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1797 | def enqueueChangesBehind(self, change, quiet, ignore_requirements): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1798 | to_enqueue = [] |
| 1799 | self.log.debug("Checking for changes needing %s:" % change) |
| 1800 | if not hasattr(change, 'needed_by_changes'): |
| 1801 | self.log.debug(" Changeish does not support dependencies") |
| 1802 | return |
| 1803 | for needs in change.needed_by_changes: |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1804 | if self.pipeline.source.canMerge(needs, |
| 1805 | self.getSubmitAllowNeeds()): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1806 | self.log.debug(" Change %s needs %s and is ready to merge" % |
| 1807 | (needs, change)) |
| 1808 | to_enqueue.append(needs) |
| 1809 | if not to_enqueue: |
| 1810 | self.log.debug(" No changes need %s" % change) |
| 1811 | |
| 1812 | for other_change in to_enqueue: |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1813 | self.addChange(other_change, quiet=quiet, |
| 1814 | ignore_requirements=ignore_requirements) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1815 | |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1816 | def enqueueChangesAhead(self, change, quiet, ignore_requirements): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1817 | ret = self.checkForChangesNeededBy(change) |
| 1818 | if ret in [True, False]: |
| 1819 | return ret |
| 1820 | self.log.debug(" Change %s must be merged ahead of %s" % |
| 1821 | (ret, change)) |
James E. Blair | f9ab884 | 2014-07-10 13:12:07 -0700 | [diff] [blame] | 1822 | return self.addChange(ret, quiet=quiet, |
| 1823 | ignore_requirements=ignore_requirements) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1824 | |
| 1825 | def checkForChangesNeededBy(self, change): |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1826 | self.log.debug("Checking for changes needed by %s:" % change) |
| 1827 | # Return true if okay to proceed enqueing this change, |
| 1828 | # false if the change should not be enqueued. |
James E. Blair | 4aea70c | 2012-07-26 14:23:24 -0700 | [diff] [blame] | 1829 | if not hasattr(change, 'needs_change'): |
| 1830 | self.log.debug(" Changeish does not support dependencies") |
| 1831 | return True |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1832 | if not change.needs_change: |
| 1833 | self.log.debug(" No changes needed") |
| 1834 | return True |
| 1835 | if change.needs_change.is_merged: |
| 1836 | self.log.debug(" Needed change is merged") |
| 1837 | return True |
| 1838 | if not change.needs_change.is_current_patchset: |
| 1839 | self.log.debug(" Needed change is not the current patchset") |
| 1840 | return False |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1841 | if self.isChangeAlreadyInQueue(change.needs_change): |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1842 | self.log.debug(" Needed change is already ahead in the queue") |
| 1843 | return True |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1844 | if self.pipeline.source.canMerge(change.needs_change, |
| 1845 | self.getSubmitAllowNeeds()): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1846 | self.log.debug(" Change %s is needed" % |
| 1847 | change.needs_change) |
| 1848 | return change.needs_change |
James E. Blair | e421a23 | 2012-07-25 16:59:21 -0700 | [diff] [blame] | 1849 | # The needed change can't be merged. |
| 1850 | self.log.debug(" Change %s is needed but can not be merged" % |
| 1851 | change.needs_change) |
| 1852 | return False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1853 | |
| 1854 | def getFailingDependentItem(self, item): |
| 1855 | if not hasattr(item.change, 'needs_change'): |
| 1856 | return None |
| 1857 | if not item.change.needs_change: |
| 1858 | return None |
| 1859 | needs_item = self.getItemForChange(item.change.needs_change) |
| 1860 | if not needs_item: |
| 1861 | return None |
| 1862 | if needs_item.current_build_set.failing_reasons: |
| 1863 | return needs_item |
| 1864 | return None |