James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 17 | import ConfigParser |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 18 | from cStringIO import StringIO |
Clark Boylan | 4ba48d9 | 2013-11-11 18:03:53 -0800 | [diff] [blame] | 19 | import gc |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 20 | import gzip |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 21 | import hashlib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import json |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 23 | import logging |
| 24 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 25 | import pprint |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | import Queue |
| 27 | import random |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 28 | import re |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 29 | import select |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 30 | import shutil |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 31 | import socket |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 32 | import string |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 33 | import subprocess |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 34 | import swiftclient |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 35 | import threading |
| 36 | import time |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 37 | import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 38 | import urllib2 |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 39 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 40 | import git |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 41 | import gear |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 42 | import fixtures |
tanlin | e621a41 | 2014-02-12 11:16:36 +0800 | [diff] [blame] | 43 | import six.moves.urllib.parse as urlparse |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 44 | import statsd |
| 45 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 46 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 47 | import zuul.scheduler |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 48 | import zuul.webapp |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 49 | import zuul.rpclistener |
| 50 | import zuul.rpcclient |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 51 | import zuul.launcher.gearman |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 52 | import zuul.lib.swift |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 53 | import zuul.merger.server |
| 54 | import zuul.merger.client |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 55 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 56 | import zuul.reporter.smtp |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 57 | import zuul.trigger.gerrit |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 58 | import zuul.trigger.timer |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 59 | |
| 60 | FIXTURE_DIR = os.path.join(os.path.dirname(__file__), |
| 61 | 'fixtures') |
| 62 | CONFIG = ConfigParser.ConfigParser() |
| 63 | CONFIG.read(os.path.join(FIXTURE_DIR, "zuul.conf")) |
| 64 | |
| 65 | CONFIG.set('zuul', 'layout_config', |
| 66 | os.path.join(FIXTURE_DIR, "layout.yaml")) |
| 67 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 68 | logging.basicConfig(level=logging.DEBUG, |
| 69 | format='%(asctime)s %(name)-32s ' |
| 70 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 71 | |
| 72 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 73 | def repack_repo(path): |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 74 | cmd = ['git', '--git-dir=%s/.git' % path, 'repack', '-afd'] |
| 75 | output = subprocess.Popen(cmd, close_fds=True, |
| 76 | stdout=subprocess.PIPE, |
| 77 | stderr=subprocess.PIPE) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 78 | out = output.communicate() |
| 79 | if output.returncode: |
| 80 | raise Exception("git repack returned %d" % output.returncode) |
| 81 | return out |
| 82 | |
| 83 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 84 | def random_sha1(): |
| 85 | return hashlib.sha1(str(random.random())).hexdigest() |
| 86 | |
| 87 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 88 | class ChangeReference(git.Reference): |
| 89 | _common_path_default = "refs/changes" |
| 90 | _points_to_commits_only = True |
| 91 | |
| 92 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 93 | class FakeChange(object): |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 94 | categories = {'APRV': ('Approved', -1, 1), |
| 95 | 'CRVW': ('Code-Review', -2, 2), |
| 96 | 'VRFY': ('Verified', -2, 2)} |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 97 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 98 | def __init__(self, gerrit, number, project, branch, subject, |
| 99 | status='NEW', upstream_root=None): |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 100 | self.gerrit = gerrit |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 101 | self.reported = 0 |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 102 | self.queried = 0 |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 103 | self.patchsets = [] |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 104 | self.number = number |
| 105 | self.project = project |
| 106 | self.branch = branch |
| 107 | self.subject = subject |
| 108 | self.latest_patchset = 0 |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 109 | self.depends_on_change = None |
| 110 | self.needed_by_changes = [] |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 111 | self.fail_merge = False |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 112 | self.messages = [] |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 113 | self.data = { |
| 114 | 'branch': branch, |
| 115 | 'comments': [], |
| 116 | 'commitMessage': subject, |
| 117 | 'createdOn': time.time(), |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 118 | 'id': 'I' + random_sha1(), |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 119 | 'lastUpdated': time.time(), |
| 120 | 'number': str(number), |
| 121 | 'open': True, |
| 122 | 'owner': {'email': 'user@example.com', |
| 123 | 'name': 'User Name', |
| 124 | 'username': 'username'}, |
| 125 | 'patchSets': self.patchsets, |
| 126 | 'project': project, |
| 127 | 'status': status, |
| 128 | 'subject': subject, |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 129 | 'submitRecords': [], |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 130 | 'url': 'https://hostname/%s' % number} |
| 131 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 132 | self.upstream_root = upstream_root |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 133 | self.addPatchset() |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 134 | self.data['submitRecords'] = self.getSubmitRecords() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 135 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 136 | def add_fake_change_to_repo(self, msg, fn, large): |
| 137 | path = os.path.join(self.upstream_root, self.project) |
| 138 | repo = git.Repo(path) |
| 139 | ref = ChangeReference.create(repo, '1/%s/%s' % (self.number, |
| 140 | self.latest_patchset), |
| 141 | 'refs/tags/init') |
| 142 | repo.head.reference = ref |
| 143 | repo.head.reset(index=True, working_tree=True) |
| 144 | repo.git.clean('-x', '-f', '-d') |
| 145 | |
| 146 | path = os.path.join(self.upstream_root, self.project) |
| 147 | if not large: |
| 148 | fn = os.path.join(path, fn) |
| 149 | f = open(fn, 'w') |
| 150 | f.write("test %s %s %s\n" % |
| 151 | (self.branch, self.number, self.latest_patchset)) |
| 152 | f.close() |
| 153 | repo.index.add([fn]) |
| 154 | else: |
| 155 | for fni in range(100): |
| 156 | fn = os.path.join(path, str(fni)) |
| 157 | f = open(fn, 'w') |
| 158 | for ci in range(4096): |
| 159 | f.write(random.choice(string.printable)) |
| 160 | f.close() |
| 161 | repo.index.add([fn]) |
| 162 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 163 | r = repo.index.commit(msg) |
| 164 | repo.head.reference = 'master' |
| 165 | repo.head.reset(index=True, working_tree=True) |
| 166 | repo.git.clean('-x', '-f', '-d') |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 167 | repo.heads['master'].checkout() |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 168 | return r |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 169 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 170 | def addPatchset(self, files=[], large=False): |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 171 | self.latest_patchset += 1 |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 172 | if files: |
| 173 | fn = files[0] |
| 174 | else: |
| 175 | fn = '%s-%s' % (self.branch, self.number) |
| 176 | msg = self.subject + '-' + str(self.latest_patchset) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 177 | c = self.add_fake_change_to_repo(msg, fn, large) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 178 | ps_files = [{'file': '/COMMIT_MSG', |
| 179 | 'type': 'ADDED'}, |
| 180 | {'file': 'README', |
| 181 | 'type': 'MODIFIED'}] |
| 182 | for f in files: |
| 183 | ps_files.append({'file': f, 'type': 'ADDED'}) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 184 | d = {'approvals': [], |
| 185 | 'createdOn': time.time(), |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 186 | 'files': ps_files, |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 187 | 'number': str(self.latest_patchset), |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 188 | 'ref': 'refs/changes/1/%s/%s' % (self.number, |
| 189 | self.latest_patchset), |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 190 | 'revision': c.hexsha, |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 191 | 'uploader': {'email': 'user@example.com', |
| 192 | 'name': 'User name', |
| 193 | 'username': 'user'}} |
| 194 | self.data['currentPatchSet'] = d |
| 195 | self.patchsets.append(d) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 196 | self.data['submitRecords'] = self.getSubmitRecords() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 197 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 198 | def getPatchsetCreatedEvent(self, patchset): |
| 199 | event = {"type": "patchset-created", |
| 200 | "change": {"project": self.project, |
Zhongyue Luo | aa85ebf | 2012-09-21 16:38:33 +0800 | [diff] [blame] | 201 | "branch": self.branch, |
| 202 | "id": "I5459869c07352a31bfb1e7a8cac379cabfcb25af", |
| 203 | "number": str(self.number), |
| 204 | "subject": self.subject, |
| 205 | "owner": {"name": "User Name"}, |
| 206 | "url": "https://hostname/3"}, |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 207 | "patchSet": self.patchsets[patchset - 1], |
| 208 | "uploader": {"name": "User Name"}} |
| 209 | return event |
| 210 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 211 | def getChangeRestoredEvent(self): |
| 212 | event = {"type": "change-restored", |
| 213 | "change": {"project": self.project, |
| 214 | "branch": self.branch, |
| 215 | "id": "I5459869c07352a31bfb1e7a8cac379cabfcb25af", |
| 216 | "number": str(self.number), |
| 217 | "subject": self.subject, |
| 218 | "owner": {"name": "User Name"}, |
| 219 | "url": "https://hostname/3"}, |
| 220 | "restorer": {"name": "User Name"}, |
| 221 | "reason": ""} |
| 222 | return event |
| 223 | |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 224 | def addApproval(self, category, value, username='jenkins', |
| 225 | granted_on=None): |
| 226 | if not granted_on: |
| 227 | granted_on = time.time() |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 228 | approval = {'description': self.categories[category][0], |
| 229 | 'type': category, |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 230 | 'value': str(value), |
James E. Blair | 64ff4ef | 2014-01-24 13:50:23 -0800 | [diff] [blame] | 231 | 'by': { |
| 232 | 'username': username, |
| 233 | 'email': username + '@example.com', |
| 234 | }, |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 235 | 'grantedOn': int(granted_on)} |
| 236 | for i, x in enumerate(self.patchsets[-1]['approvals'][:]): |
James E. Blair | 64ff4ef | 2014-01-24 13:50:23 -0800 | [diff] [blame] | 237 | if x['by']['username'] == username and x['type'] == category: |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 238 | del self.patchsets[-1]['approvals'][i] |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 239 | self.patchsets[-1]['approvals'].append(approval) |
| 240 | event = {'approvals': [approval], |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 241 | 'author': {'email': 'user@example.com', |
| 242 | 'name': 'User Name', |
| 243 | 'username': 'username'}, |
| 244 | 'change': {'branch': self.branch, |
| 245 | 'id': 'Iaa69c46accf97d0598111724a38250ae76a22c87', |
| 246 | 'number': str(self.number), |
| 247 | 'owner': {'email': 'user@example.com', |
| 248 | 'name': 'User Name', |
| 249 | 'username': 'username'}, |
| 250 | 'project': self.project, |
| 251 | 'subject': self.subject, |
| 252 | 'topic': 'master', |
| 253 | 'url': 'https://hostname/459'}, |
| 254 | 'comment': '', |
| 255 | 'patchSet': self.patchsets[-1], |
| 256 | 'type': 'comment-added'} |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 257 | self.data['submitRecords'] = self.getSubmitRecords() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 258 | return json.loads(json.dumps(event)) |
| 259 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 260 | def getSubmitRecords(self): |
| 261 | status = {} |
| 262 | for cat in self.categories.keys(): |
| 263 | status[cat] = 0 |
| 264 | |
| 265 | for a in self.patchsets[-1]['approvals']: |
| 266 | cur = status[a['type']] |
| 267 | cat_min, cat_max = self.categories[a['type']][1:] |
| 268 | new = int(a['value']) |
| 269 | if new == cat_min: |
| 270 | cur = new |
| 271 | elif abs(new) > abs(cur): |
| 272 | cur = new |
| 273 | status[a['type']] = cur |
| 274 | |
| 275 | labels = [] |
| 276 | ok = True |
| 277 | for typ, cat in self.categories.items(): |
| 278 | cur = status[typ] |
| 279 | cat_min, cat_max = cat[1:] |
| 280 | if cur == cat_min: |
| 281 | value = 'REJECT' |
| 282 | ok = False |
| 283 | elif cur == cat_max: |
| 284 | value = 'OK' |
| 285 | else: |
| 286 | value = 'NEED' |
| 287 | ok = False |
| 288 | labels.append({'label': cat[0], 'status': value}) |
| 289 | if ok: |
| 290 | return [{'status': 'OK'}] |
| 291 | return [{'status': 'NOT_READY', |
| 292 | 'labels': labels}] |
| 293 | |
| 294 | def setDependsOn(self, other, patchset): |
| 295 | self.depends_on_change = other |
| 296 | d = {'id': other.data['id'], |
| 297 | 'number': other.data['number'], |
| 298 | 'ref': other.patchsets[patchset - 1]['ref'] |
| 299 | } |
| 300 | self.data['dependsOn'] = [d] |
| 301 | |
| 302 | other.needed_by_changes.append(self) |
| 303 | needed = other.data.get('neededBy', []) |
| 304 | d = {'id': self.data['id'], |
| 305 | 'number': self.data['number'], |
| 306 | 'ref': self.patchsets[patchset - 1]['ref'], |
| 307 | 'revision': self.patchsets[patchset - 1]['revision'] |
| 308 | } |
| 309 | needed.append(d) |
| 310 | other.data['neededBy'] = needed |
| 311 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 312 | def query(self): |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 313 | self.queried += 1 |
| 314 | d = self.data.get('dependsOn') |
| 315 | if d: |
| 316 | d = d[0] |
| 317 | if (self.depends_on_change.patchsets[-1]['ref'] == d['ref']): |
| 318 | d['isCurrentPatchSet'] = True |
| 319 | else: |
| 320 | d['isCurrentPatchSet'] = False |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 321 | return json.loads(json.dumps(self.data)) |
| 322 | |
| 323 | def setMerged(self): |
Zhongyue Luo | aa85ebf | 2012-09-21 16:38:33 +0800 | [diff] [blame] | 324 | if (self.depends_on_change and |
| 325 | self.depends_on_change.data['status'] != 'MERGED'): |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 326 | return |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 327 | if self.fail_merge: |
| 328 | return |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 329 | self.data['status'] = 'MERGED' |
| 330 | self.open = False |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 331 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 332 | path = os.path.join(self.upstream_root, self.project) |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 333 | repo = git.Repo(path) |
| 334 | repo.heads[self.branch].commit = \ |
| 335 | repo.commit(self.patchsets[-1]['revision']) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 336 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | def setReported(self): |
| 338 | self.reported += 1 |
| 339 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 340 | |
| 341 | class FakeGerrit(object): |
| 342 | def __init__(self, *args, **kw): |
| 343 | self.event_queue = Queue.Queue() |
| 344 | self.fixture_dir = os.path.join(FIXTURE_DIR, 'gerrit') |
| 345 | self.change_number = 0 |
| 346 | self.changes = {} |
| 347 | |
| 348 | def addFakeChange(self, project, branch, subject): |
| 349 | self.change_number += 1 |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 350 | c = FakeChange(self, self.change_number, project, branch, subject, |
| 351 | upstream_root=self.upstream_root) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 352 | self.changes[self.change_number] = c |
| 353 | return c |
| 354 | |
| 355 | def addEvent(self, data): |
| 356 | return self.event_queue.put(data) |
| 357 | |
| 358 | def getEvent(self): |
| 359 | return self.event_queue.get() |
| 360 | |
| 361 | def eventDone(self): |
| 362 | self.event_queue.task_done() |
| 363 | |
| 364 | def review(self, project, changeid, message, action): |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 365 | number, ps = changeid.split(',') |
| 366 | change = self.changes[int(number)] |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 367 | change.messages.append(message) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 368 | if 'submit' in action: |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 369 | change.setMerged() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 370 | if message: |
| 371 | change.setReported() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 372 | |
| 373 | def query(self, number): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 374 | change = self.changes.get(int(number)) |
| 375 | if change: |
| 376 | return change.query() |
| 377 | return {} |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 378 | |
| 379 | def startWatching(self, *args, **kw): |
| 380 | pass |
| 381 | |
| 382 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 383 | class BuildHistory(object): |
| 384 | def __init__(self, **kw): |
| 385 | self.__dict__.update(kw) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 386 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 387 | def __repr__(self): |
| 388 | return ("<Completed build, result: %s name: %s #%s changes: %s>" % |
| 389 | (self.result, self.name, self.number, self.changes)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 390 | |
| 391 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 392 | class FakeURLOpener(object): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 393 | def __init__(self, upstream_root, fake_gerrit, url): |
| 394 | self.upstream_root = upstream_root |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 395 | self.fake_gerrit = fake_gerrit |
| 396 | self.url = url |
| 397 | |
| 398 | def read(self): |
| 399 | res = urlparse.urlparse(self.url) |
| 400 | path = res.path |
| 401 | project = '/'.join(path.split('/')[2:-2]) |
James E. Blair | 35956c5 | 2012-09-17 22:13:36 +0200 | [diff] [blame] | 402 | ret = '001e# service=git-upload-pack\n' |
| 403 | ret += ('000000a31270149696713ba7e06f1beb760f20d359c4abed HEAD\x00' |
| 404 | 'multi_ack thin-pack side-band side-band-64k ofs-delta ' |
| 405 | 'shallow no-progress include-tag multi_ack_detailed no-done\n') |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 406 | path = os.path.join(self.upstream_root, project) |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 407 | repo = git.Repo(path) |
| 408 | for ref in repo.refs: |
James E. Blair | 35956c5 | 2012-09-17 22:13:36 +0200 | [diff] [blame] | 409 | r = ref.object.hexsha + ' ' + ref.path + '\n' |
| 410 | ret += '%04x%s' % (len(r) + 4, r) |
| 411 | ret += '0000' |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 412 | return ret |
| 413 | |
| 414 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 415 | class FakeGerritTrigger(zuul.trigger.gerrit.Gerrit): |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 416 | name = 'gerrit' |
| 417 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 418 | def __init__(self, upstream_root, *args): |
| 419 | super(FakeGerritTrigger, self).__init__(*args) |
| 420 | self.upstream_root = upstream_root |
| 421 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 422 | def getGitUrl(self, project): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 423 | return os.path.join(self.upstream_root, project.name) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 424 | |
| 425 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 426 | class FakeStatsd(threading.Thread): |
| 427 | def __init__(self): |
| 428 | threading.Thread.__init__(self) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 429 | self.daemon = True |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 430 | self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 431 | self.sock.bind(('', 0)) |
| 432 | self.port = self.sock.getsockname()[1] |
| 433 | self.wake_read, self.wake_write = os.pipe() |
| 434 | self.stats = [] |
| 435 | |
| 436 | def run(self): |
| 437 | while True: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 438 | poll = select.poll() |
| 439 | poll.register(self.sock, select.POLLIN) |
| 440 | poll.register(self.wake_read, select.POLLIN) |
| 441 | ret = poll.poll() |
| 442 | for (fd, event) in ret: |
| 443 | if fd == self.sock.fileno(): |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 444 | data = self.sock.recvfrom(1024) |
| 445 | if not data: |
| 446 | return |
| 447 | self.stats.append(data[0]) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 448 | if fd == self.wake_read: |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 449 | return |
| 450 | |
| 451 | def stop(self): |
| 452 | os.write(self.wake_write, '1\n') |
| 453 | |
| 454 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 455 | class FakeBuild(threading.Thread): |
| 456 | log = logging.getLogger("zuul.test") |
| 457 | |
| 458 | def __init__(self, worker, job, number, node): |
| 459 | threading.Thread.__init__(self) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 460 | self.daemon = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 461 | self.worker = worker |
| 462 | self.job = job |
| 463 | self.name = job.name.split(':')[1] |
| 464 | self.number = number |
| 465 | self.node = node |
| 466 | self.parameters = json.loads(job.arguments) |
| 467 | self.unique = self.parameters['ZUUL_UUID'] |
| 468 | self.wait_condition = threading.Condition() |
| 469 | self.waiting = False |
| 470 | self.aborted = False |
| 471 | self.created = time.time() |
| 472 | self.description = '' |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 473 | self.run_error = False |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 474 | |
| 475 | def release(self): |
| 476 | self.wait_condition.acquire() |
| 477 | self.wait_condition.notify() |
| 478 | self.waiting = False |
| 479 | self.log.debug("Build %s released" % self.unique) |
| 480 | self.wait_condition.release() |
| 481 | |
| 482 | def isWaiting(self): |
| 483 | self.wait_condition.acquire() |
| 484 | if self.waiting: |
| 485 | ret = True |
| 486 | else: |
| 487 | ret = False |
| 488 | self.wait_condition.release() |
| 489 | return ret |
| 490 | |
| 491 | def _wait(self): |
| 492 | self.wait_condition.acquire() |
| 493 | self.waiting = True |
| 494 | self.log.debug("Build %s waiting" % self.unique) |
| 495 | self.wait_condition.wait() |
| 496 | self.wait_condition.release() |
| 497 | |
| 498 | def run(self): |
| 499 | data = { |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 500 | 'url': 'https://server/job/%s/%s/' % (self.name, self.number), |
| 501 | 'name': self.name, |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 502 | 'number': self.number, |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 503 | 'manager': self.worker.worker_id, |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 504 | 'worker_name': 'My Worker', |
| 505 | 'worker_hostname': 'localhost', |
| 506 | 'worker_ips': ['127.0.0.1', '192.168.1.1'], |
| 507 | 'worker_fqdn': 'zuul.example.org', |
| 508 | 'worker_program': 'FakeBuilder', |
| 509 | 'worker_version': 'v1.1', |
| 510 | 'worker_extra': {'something': 'else'} |
Paul Belanger | ec49b4c | 2013-07-20 20:32:20 -0400 | [diff] [blame] | 511 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 512 | |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 513 | self.log.debug('Running build %s' % self.unique) |
| 514 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 515 | self.job.sendWorkData(json.dumps(data)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 516 | self.log.debug('Sent WorkData packet with %s' % json.dumps(data)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 517 | self.job.sendWorkStatus(0, 100) |
| 518 | |
| 519 | if self.worker.hold_jobs_in_build: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 520 | self.log.debug('Holding build %s' % self.unique) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 521 | self._wait() |
| 522 | self.log.debug("Build %s continuing" % self.unique) |
| 523 | |
| 524 | self.worker.lock.acquire() |
| 525 | |
| 526 | result = 'SUCCESS' |
| 527 | if (('ZUUL_REF' in self.parameters) and |
| 528 | self.worker.shouldFailTest(self.name, |
| 529 | self.parameters['ZUUL_REF'])): |
| 530 | result = 'FAILURE' |
| 531 | if self.aborted: |
| 532 | result = 'ABORTED' |
| 533 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 534 | if self.run_error: |
| 535 | work_fail = True |
| 536 | result = 'RUN_ERROR' |
| 537 | else: |
| 538 | data['result'] = result |
| 539 | work_fail = False |
| 540 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 541 | changes = None |
| 542 | if 'ZUUL_CHANGE_IDS' in self.parameters: |
| 543 | changes = self.parameters['ZUUL_CHANGE_IDS'] |
| 544 | |
| 545 | self.worker.build_history.append( |
| 546 | BuildHistory(name=self.name, number=self.number, |
| 547 | result=result, changes=changes, node=self.node, |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 548 | uuid=self.unique, description=self.description, |
| 549 | pipeline=self.parameters['ZUUL_PIPELINE']) |
Paul Belanger | ec49b4c | 2013-07-20 20:32:20 -0400 | [diff] [blame] | 550 | ) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 551 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 552 | self.job.sendWorkData(json.dumps(data)) |
| 553 | if work_fail: |
| 554 | self.job.sendWorkFail() |
| 555 | else: |
| 556 | self.job.sendWorkComplete(json.dumps(data)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 557 | del self.worker.gearman_jobs[self.job.unique] |
| 558 | self.worker.running_builds.remove(self) |
| 559 | self.worker.lock.release() |
| 560 | |
| 561 | |
| 562 | class FakeWorker(gear.Worker): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 563 | def __init__(self, worker_id, test): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 564 | super(FakeWorker, self).__init__(worker_id) |
| 565 | self.gearman_jobs = {} |
| 566 | self.build_history = [] |
| 567 | self.running_builds = [] |
| 568 | self.build_counter = 0 |
| 569 | self.fail_tests = {} |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 570 | self.test = test |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 571 | |
| 572 | self.hold_jobs_in_build = False |
| 573 | self.lock = threading.Lock() |
| 574 | self.__work_thread = threading.Thread(target=self.work) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 575 | self.__work_thread.daemon = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 576 | self.__work_thread.start() |
| 577 | |
| 578 | def handleJob(self, job): |
| 579 | parts = job.name.split(":") |
| 580 | cmd = parts[0] |
| 581 | name = parts[1] |
| 582 | if len(parts) > 2: |
| 583 | node = parts[2] |
| 584 | else: |
| 585 | node = None |
| 586 | if cmd == 'build': |
| 587 | self.handleBuild(job, name, node) |
| 588 | elif cmd == 'stop': |
| 589 | self.handleStop(job, name) |
| 590 | elif cmd == 'set_description': |
| 591 | self.handleSetDescription(job, name) |
| 592 | |
| 593 | def handleBuild(self, job, name, node): |
| 594 | build = FakeBuild(self, job, self.build_counter, node) |
| 595 | job.build = build |
| 596 | self.gearman_jobs[job.unique] = job |
| 597 | self.build_counter += 1 |
| 598 | |
| 599 | self.running_builds.append(build) |
| 600 | build.start() |
| 601 | |
| 602 | def handleStop(self, job, name): |
| 603 | self.log.debug("handle stop") |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 604 | parameters = json.loads(job.arguments) |
| 605 | name = parameters['name'] |
| 606 | number = parameters['number'] |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 607 | for build in self.running_builds: |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 608 | if build.name == name and build.number == number: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 609 | build.aborted = True |
| 610 | build.release() |
| 611 | job.sendWorkComplete() |
| 612 | return |
| 613 | job.sendWorkFail() |
| 614 | |
| 615 | def handleSetDescription(self, job, name): |
| 616 | self.log.debug("handle set description") |
| 617 | parameters = json.loads(job.arguments) |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 618 | name = parameters['name'] |
| 619 | number = parameters['number'] |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 620 | descr = parameters['html_description'] |
| 621 | for build in self.running_builds: |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 622 | if build.name == name and build.number == number: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 623 | build.description = descr |
| 624 | job.sendWorkComplete() |
| 625 | return |
| 626 | for build in self.build_history: |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 627 | if build.name == name and build.number == number: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 628 | build.description = descr |
| 629 | job.sendWorkComplete() |
| 630 | return |
| 631 | job.sendWorkFail() |
| 632 | |
| 633 | def work(self): |
| 634 | while self.running: |
| 635 | try: |
| 636 | job = self.getJob() |
| 637 | except gear.InterruptedError: |
| 638 | continue |
| 639 | try: |
| 640 | self.handleJob(job) |
| 641 | except: |
| 642 | self.log.exception("Worker exception:") |
| 643 | |
| 644 | def addFailTest(self, name, change): |
| 645 | l = self.fail_tests.get(name, []) |
| 646 | l.append(change) |
| 647 | self.fail_tests[name] = l |
| 648 | |
| 649 | def shouldFailTest(self, name, ref): |
| 650 | l = self.fail_tests.get(name, []) |
| 651 | for change in l: |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 652 | if self.test.ref_has_change(ref, change): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 653 | return True |
| 654 | return False |
| 655 | |
| 656 | def release(self, regex=None): |
| 657 | builds = self.running_builds[:] |
| 658 | self.log.debug("releasing build %s (%s)" % (regex, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 659 | len(self.running_builds))) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 660 | for build in builds: |
| 661 | if not regex or re.match(regex, build.name): |
| 662 | self.log.debug("releasing build %s" % |
| 663 | (build.parameters['ZUUL_UUID'])) |
| 664 | build.release() |
| 665 | else: |
| 666 | self.log.debug("not releasing build %s" % |
| 667 | (build.parameters['ZUUL_UUID'])) |
| 668 | self.log.debug("done releasing builds %s (%s)" % |
| 669 | (regex, len(self.running_builds))) |
| 670 | |
| 671 | |
| 672 | class FakeGearmanServer(gear.Server): |
| 673 | def __init__(self): |
| 674 | self.hold_jobs_in_queue = False |
| 675 | super(FakeGearmanServer, self).__init__(0) |
| 676 | |
| 677 | def getJobForConnection(self, connection, peek=False): |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 678 | for queue in [self.high_queue, self.normal_queue, self.low_queue]: |
| 679 | for job in queue: |
| 680 | if not hasattr(job, 'waiting'): |
| 681 | if job.name.startswith('build:'): |
| 682 | job.waiting = self.hold_jobs_in_queue |
| 683 | else: |
| 684 | job.waiting = False |
| 685 | if job.waiting: |
| 686 | continue |
| 687 | if job.name in connection.functions: |
| 688 | if not peek: |
| 689 | queue.remove(job) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 690 | connection.related_jobs[job.handle] = job |
| 691 | job.worker_connection = connection |
| 692 | job.running = True |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 693 | return job |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 694 | return None |
| 695 | |
| 696 | def release(self, regex=None): |
| 697 | released = False |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 698 | qlen = (len(self.high_queue) + len(self.normal_queue) + |
| 699 | len(self.low_queue)) |
| 700 | self.log.debug("releasing queued job %s (%s)" % (regex, qlen)) |
James E. Blair | dda6c91 | 2013-07-29 14:12:12 -0700 | [diff] [blame] | 701 | for job in self.getQueue(): |
| 702 | cmd, name = job.name.split(':') |
| 703 | if cmd != 'build': |
| 704 | continue |
| 705 | if not regex or re.match(regex, name): |
| 706 | self.log.debug("releasing queued job %s" % |
| 707 | job.unique) |
| 708 | job.waiting = False |
| 709 | released = True |
| 710 | else: |
| 711 | self.log.debug("not releasing queued job %s" % |
| 712 | job.unique) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 713 | if released: |
| 714 | self.wakeConnections() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 715 | qlen = (len(self.high_queue) + len(self.normal_queue) + |
| 716 | len(self.low_queue)) |
| 717 | self.log.debug("done releasing queued jobs %s (%s)" % (regex, qlen)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 718 | |
| 719 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 720 | class FakeSMTP(object): |
| 721 | log = logging.getLogger('zuul.FakeSMTP') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 722 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 723 | def __init__(self, messages, server, port): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 724 | self.server = server |
| 725 | self.port = port |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 726 | self.messages = messages |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 727 | |
| 728 | def sendmail(self, from_email, to_email, msg): |
| 729 | self.log.info("Sending email from %s, to %s, with msg %s" % ( |
| 730 | from_email, to_email, msg)) |
| 731 | |
| 732 | headers = msg.split('\n\n', 1)[0] |
| 733 | body = msg.split('\n\n', 1)[1] |
| 734 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 735 | self.messages.append(dict( |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 736 | from_email=from_email, |
| 737 | to_email=to_email, |
| 738 | msg=msg, |
| 739 | headers=headers, |
| 740 | body=body, |
| 741 | )) |
| 742 | |
| 743 | return True |
| 744 | |
| 745 | def quit(self): |
| 746 | return True |
| 747 | |
| 748 | |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 749 | class FakeSwiftClientConnection(swiftclient.client.Connection): |
| 750 | def post_account(self, headers): |
| 751 | # Do nothing |
| 752 | pass |
| 753 | |
| 754 | def get_auth(self): |
| 755 | # Returns endpoint and (unused) auth token |
| 756 | endpoint = os.path.join('https://storage.example.org', 'V1', |
| 757 | 'AUTH_account') |
| 758 | return endpoint, '' |
| 759 | |
| 760 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 761 | class TestScheduler(testtools.TestCase): |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 762 | log = logging.getLogger("zuul.test") |
| 763 | |
| 764 | def setUp(self): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 765 | super(TestScheduler, self).setUp() |
| 766 | test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) |
| 767 | try: |
| 768 | test_timeout = int(test_timeout) |
| 769 | except ValueError: |
| 770 | # If timeout value is invalid do not set a timeout. |
| 771 | test_timeout = 0 |
| 772 | if test_timeout > 0: |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 773 | self.useFixture(fixtures.Timeout(test_timeout, gentle=False)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 774 | |
| 775 | if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or |
| 776 | os.environ.get('OS_STDOUT_CAPTURE') == '1'): |
| 777 | stdout = self.useFixture(fixtures.StringStream('stdout')).stream |
| 778 | self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) |
| 779 | if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or |
| 780 | os.environ.get('OS_STDERR_CAPTURE') == '1'): |
| 781 | stderr = self.useFixture(fixtures.StringStream('stderr')).stream |
| 782 | self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) |
Monty Taylor | e6a6c40 | 2013-07-02 09:25:55 -0700 | [diff] [blame] | 783 | if (os.environ.get('OS_LOG_CAPTURE') == 'True' or |
| 784 | os.environ.get('OS_LOG_CAPTURE') == '1'): |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 785 | self.useFixture(fixtures.FakeLogger( |
| 786 | level=logging.DEBUG, |
| 787 | format='%(asctime)s %(name)-32s ' |
| 788 | '%(levelname)-8s %(message)s')) |
Monty Taylor | 5a5a95c | 2013-07-03 13:39:14 -0700 | [diff] [blame] | 789 | tmp_root = self.useFixture(fixtures.TempDir( |
| 790 | rootdir=os.environ.get("ZUUL_TEST_ROOT"))).path |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 791 | self.test_root = os.path.join(tmp_root, "zuul-test") |
| 792 | self.upstream_root = os.path.join(self.test_root, "upstream") |
| 793 | self.git_root = os.path.join(self.test_root, "git") |
| 794 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 795 | CONFIG.set('merger', 'git_dir', self.git_root) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 796 | if os.path.exists(self.test_root): |
| 797 | shutil.rmtree(self.test_root) |
| 798 | os.makedirs(self.test_root) |
| 799 | os.makedirs(self.upstream_root) |
| 800 | os.makedirs(self.git_root) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 801 | |
| 802 | # For each project in config: |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 803 | self.init_repo("org/project") |
| 804 | self.init_repo("org/project1") |
| 805 | self.init_repo("org/project2") |
| 806 | self.init_repo("org/project3") |
| 807 | self.init_repo("org/one-job-project") |
| 808 | self.init_repo("org/nonvoting-project") |
| 809 | self.init_repo("org/templated-project") |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 810 | self.init_repo("org/layered-project") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 811 | self.init_repo("org/node-project") |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 812 | self.init_repo("org/conflict-project") |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 813 | self.init_repo("org/noop-project") |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 814 | self.init_repo("org/experimental-project") |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 815 | |
| 816 | self.statsd = FakeStatsd() |
| 817 | os.environ['STATSD_HOST'] = 'localhost' |
| 818 | os.environ['STATSD_PORT'] = str(self.statsd.port) |
| 819 | self.statsd.start() |
| 820 | # the statsd client object is configured in the statsd module import |
| 821 | reload(statsd) |
| 822 | reload(zuul.scheduler) |
| 823 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 824 | self.gearman_server = FakeGearmanServer() |
| 825 | |
| 826 | self.config = ConfigParser.ConfigParser() |
| 827 | cfg = StringIO() |
| 828 | CONFIG.write(cfg) |
| 829 | cfg.seek(0) |
| 830 | self.config.readfp(cfg) |
| 831 | self.config.set('gearman', 'port', str(self.gearman_server.port)) |
| 832 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 833 | self.worker = FakeWorker('fake_worker', self) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 834 | self.worker.addServer('127.0.0.1', self.gearman_server.port) |
| 835 | self.gearman_server.worker = self.worker |
| 836 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 837 | self.merge_server = zuul.merger.server.MergeServer(self.config) |
| 838 | self.merge_server.start() |
| 839 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 840 | self.sched = zuul.scheduler.Scheduler() |
| 841 | |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 842 | self.useFixture(fixtures.MonkeyPatch('swiftclient.client.Connection', |
| 843 | FakeSwiftClientConnection)) |
| 844 | self.swift = zuul.lib.swift.Swift(self.config) |
| 845 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 846 | def URLOpenerFactory(*args, **kw): |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 847 | if isinstance(args[0], urllib2.Request): |
| 848 | return old_urlopen(*args, **kw) |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 849 | args = [self.fake_gerrit] + list(args) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 850 | return FakeURLOpener(self.upstream_root, *args, **kw) |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 851 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 852 | old_urlopen = urllib2.urlopen |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 853 | urllib2.urlopen = URLOpenerFactory |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 854 | |
| 855 | self.launcher = zuul.launcher.gearman.Gearman(self.config, self.sched, |
| 856 | self.swift) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 857 | self.merge_client = zuul.merger.client.MergeClient( |
| 858 | self.config, self.sched) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 859 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 860 | self.smtp_messages = [] |
| 861 | |
| 862 | def FakeSMTPFactory(*args, **kw): |
| 863 | args = [self.smtp_messages] + list(args) |
| 864 | return FakeSMTP(*args, **kw) |
| 865 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 866 | zuul.lib.gerrit.Gerrit = FakeGerrit |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 867 | self.useFixture(fixtures.MonkeyPatch('smtplib.SMTP', FakeSMTPFactory)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 868 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 869 | self.gerrit = FakeGerritTrigger( |
| 870 | self.upstream_root, self.config, self.sched) |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 871 | self.gerrit.replication_timeout = 1.5 |
| 872 | self.gerrit.replication_retry_interval = 0.5 |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 873 | self.fake_gerrit = self.gerrit.gerrit |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 874 | self.fake_gerrit.upstream_root = self.upstream_root |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 875 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 876 | self.webapp = zuul.webapp.WebApp(self.sched, port=0) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 877 | self.rpc = zuul.rpclistener.RPCListener(self.config, self.sched) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 878 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 879 | self.sched.setLauncher(self.launcher) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 880 | self.sched.setMerger(self.merge_client) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 881 | self.sched.registerTrigger(self.gerrit) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 882 | self.timer = zuul.trigger.timer.Timer(self.config, self.sched) |
| 883 | self.sched.registerTrigger(self.timer) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 884 | |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 885 | self.sched.registerReporter( |
| 886 | zuul.reporter.gerrit.Reporter(self.gerrit)) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 887 | self.smtp_reporter = zuul.reporter.smtp.Reporter( |
| 888 | self.config.get('smtp', 'default_from'), |
| 889 | self.config.get('smtp', 'default_to'), |
| 890 | self.config.get('smtp', 'server')) |
| 891 | self.sched.registerReporter(self.smtp_reporter) |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 892 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 893 | self.sched.start() |
| 894 | self.sched.reconfigure(self.config) |
| 895 | self.sched.resume() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 896 | self.webapp.start() |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 897 | self.rpc.start() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 898 | self.launcher.gearman.waitForServer() |
| 899 | self.registerJobs() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 900 | self.builds = self.worker.running_builds |
| 901 | self.history = self.worker.build_history |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 902 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 903 | self.addCleanup(self.assertFinalState) |
| 904 | self.addCleanup(self.shutdown) |
| 905 | |
| 906 | def assertFinalState(self): |
| 907 | # Make sure that the change cache is cleared |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 908 | self.assertEqual(len(self.gerrit._change_cache.keys()), 0) |
Clark Boylan | 4ba48d9 | 2013-11-11 18:03:53 -0800 | [diff] [blame] | 909 | # Make sure that git.Repo objects have been garbage collected. |
| 910 | repos = [] |
| 911 | gc.collect() |
| 912 | for obj in gc.get_objects(): |
| 913 | if isinstance(obj, git.Repo): |
| 914 | repos.append(obj) |
| 915 | self.assertEqual(len(repos), 0) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 916 | self.assertEmptyQueues() |
| 917 | |
| 918 | def shutdown(self): |
| 919 | self.log.debug("Shutting down after tests") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 920 | self.launcher.stop() |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 921 | self.merge_server.stop() |
| 922 | self.merge_server.join() |
| 923 | self.merge_client.stop() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 924 | self.worker.shutdown() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 925 | self.gerrit.stop() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 926 | self.timer.stop() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 927 | self.sched.stop() |
| 928 | self.sched.join() |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 929 | self.statsd.stop() |
| 930 | self.statsd.join() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 931 | self.webapp.stop() |
| 932 | self.webapp.join() |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 933 | self.rpc.stop() |
| 934 | self.rpc.join() |
James E. Blair | 491b317 | 2014-03-10 15:05:36 -0700 | [diff] [blame] | 935 | self.gearman_server.shutdown() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 936 | threads = threading.enumerate() |
| 937 | if len(threads) > 1: |
| 938 | self.log.error("More than one thread is running: %s" % threads) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 939 | super(TestScheduler, self).tearDown() |
| 940 | |
| 941 | def init_repo(self, project): |
| 942 | parts = project.split('/') |
| 943 | path = os.path.join(self.upstream_root, *parts[:-1]) |
| 944 | if not os.path.exists(path): |
| 945 | os.makedirs(path) |
| 946 | path = os.path.join(self.upstream_root, project) |
| 947 | repo = git.Repo.init(path) |
| 948 | |
| 949 | repo.config_writer().set_value('user', 'email', 'user@example.com') |
| 950 | repo.config_writer().set_value('user', 'name', 'User Name') |
| 951 | repo.config_writer().write() |
| 952 | |
| 953 | fn = os.path.join(path, 'README') |
| 954 | f = open(fn, 'w') |
| 955 | f.write("test\n") |
| 956 | f.close() |
| 957 | repo.index.add([fn]) |
| 958 | repo.index.commit('initial commit') |
| 959 | master = repo.create_head('master') |
| 960 | repo.create_tag('init') |
| 961 | |
| 962 | mp = repo.create_head('mp') |
| 963 | repo.head.reference = mp |
| 964 | f = open(fn, 'a') |
| 965 | f.write("test mp\n") |
| 966 | f.close() |
| 967 | repo.index.add([fn]) |
| 968 | repo.index.commit('mp commit') |
| 969 | |
| 970 | repo.head.reference = master |
| 971 | repo.head.reset(index=True, working_tree=True) |
| 972 | repo.git.clean('-x', '-f', '-d') |
| 973 | |
| 974 | def ref_has_change(self, ref, change): |
| 975 | path = os.path.join(self.git_root, change.project) |
| 976 | repo = git.Repo(path) |
| 977 | for commit in repo.iter_commits(ref): |
| 978 | if commit.message.strip() == ('%s-1' % change.subject): |
| 979 | return True |
| 980 | return False |
| 981 | |
| 982 | def job_has_changes(self, *args): |
| 983 | job = args[0] |
| 984 | commits = args[1:] |
| 985 | if isinstance(job, FakeBuild): |
| 986 | parameters = job.parameters |
| 987 | else: |
| 988 | parameters = json.loads(job.arguments) |
| 989 | project = parameters['ZUUL_PROJECT'] |
| 990 | path = os.path.join(self.git_root, project) |
| 991 | repo = git.Repo(path) |
| 992 | ref = parameters['ZUUL_REF'] |
| 993 | sha = parameters['ZUUL_COMMIT'] |
| 994 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 995 | repo_shas = [c.hexsha for c in repo.iter_commits(ref)] |
| 996 | commit_messages = ['%s-1' % commit.subject for commit in commits] |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 997 | self.log.debug("Checking if job %s has changes; commit_messages %s;" |
| 998 | " repo_messages %s; sha %s" % (job, commit_messages, |
| 999 | repo_messages, sha)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1000 | for msg in commit_messages: |
| 1001 | if msg not in repo_messages: |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1002 | self.log.debug(" messages do not match") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1003 | return False |
| 1004 | if repo_shas[0] != sha: |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1005 | self.log.debug(" sha does not match") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1006 | return False |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1007 | self.log.debug(" OK") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1008 | return True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1009 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1010 | def registerJobs(self): |
| 1011 | count = 0 |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1012 | for job in self.sched.layout.jobs.keys(): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1013 | self.worker.registerFunction('build:' + job) |
| 1014 | count += 1 |
| 1015 | self.worker.registerFunction('stop:' + self.worker.worker_id) |
| 1016 | count += 1 |
| 1017 | |
| 1018 | while len(self.gearman_server.functions) < count: |
| 1019 | time.sleep(0) |
| 1020 | |
| 1021 | def release(self, job): |
| 1022 | if isinstance(job, FakeBuild): |
| 1023 | job.release() |
| 1024 | else: |
| 1025 | job.waiting = False |
| 1026 | self.log.debug("Queued job %s released" % job.unique) |
| 1027 | self.gearman_server.wakeConnections() |
| 1028 | |
| 1029 | def getParameter(self, job, name): |
| 1030 | if isinstance(job, FakeBuild): |
| 1031 | return job.parameters[name] |
| 1032 | else: |
| 1033 | parameters = json.loads(job.arguments) |
| 1034 | return parameters[name] |
| 1035 | |
| 1036 | def resetGearmanServer(self): |
| 1037 | self.worker.setFunctions([]) |
| 1038 | while True: |
| 1039 | done = True |
| 1040 | for connection in self.gearman_server.active_connections: |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 1041 | if (connection.functions and |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1042 | connection.client_id not in ['Zuul RPC Listener', |
| 1043 | 'Zuul Merger']): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1044 | done = False |
| 1045 | if done: |
| 1046 | break |
| 1047 | time.sleep(0) |
| 1048 | self.gearman_server.functions = set() |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 1049 | self.rpc.register() |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1050 | self.merge_server.register() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1051 | |
| 1052 | def haveAllBuildsReported(self): |
| 1053 | # See if Zuul is waiting on a meta job to complete |
| 1054 | if self.launcher.meta_jobs: |
| 1055 | return False |
| 1056 | # Find out if every build that the worker has completed has been |
| 1057 | # reported back to Zuul. If it hasn't then that means a Gearman |
| 1058 | # event is still in transit and the system is not stable. |
| 1059 | for build in self.worker.build_history: |
| 1060 | zbuild = self.launcher.builds.get(build.uuid) |
| 1061 | if not zbuild: |
| 1062 | # It has already been reported |
| 1063 | continue |
| 1064 | # It hasn't been reported yet. |
| 1065 | return False |
| 1066 | # Make sure that none of the worker connections are in GRAB_WAIT |
| 1067 | for connection in self.worker.active_connections: |
| 1068 | if connection.state == 'GRAB_WAIT': |
| 1069 | return False |
| 1070 | return True |
| 1071 | |
| 1072 | def areAllBuildsWaiting(self): |
| 1073 | ret = True |
| 1074 | |
| 1075 | builds = self.launcher.builds.values() |
| 1076 | for build in builds: |
| 1077 | client_job = None |
| 1078 | for conn in self.launcher.gearman.active_connections: |
| 1079 | for j in conn.related_jobs.values(): |
| 1080 | if j.unique == build.uuid: |
| 1081 | client_job = j |
| 1082 | break |
| 1083 | if not client_job: |
| 1084 | self.log.debug("%s is not known to the gearman client" % |
| 1085 | build) |
| 1086 | ret = False |
| 1087 | continue |
| 1088 | if not client_job.handle: |
| 1089 | self.log.debug("%s has no handle" % client_job) |
| 1090 | ret = False |
| 1091 | continue |
| 1092 | server_job = self.gearman_server.jobs.get(client_job.handle) |
| 1093 | if not server_job: |
| 1094 | self.log.debug("%s is not known to the gearman server" % |
| 1095 | client_job) |
| 1096 | ret = False |
| 1097 | continue |
| 1098 | if not hasattr(server_job, 'waiting'): |
| 1099 | self.log.debug("%s is being enqueued" % server_job) |
| 1100 | ret = False |
| 1101 | continue |
| 1102 | if server_job.waiting: |
| 1103 | continue |
| 1104 | worker_job = self.worker.gearman_jobs.get(server_job.unique) |
| 1105 | if worker_job: |
| 1106 | if worker_job.build.isWaiting(): |
| 1107 | continue |
| 1108 | else: |
| 1109 | self.log.debug("%s is running" % worker_job) |
| 1110 | ret = False |
| 1111 | else: |
| 1112 | self.log.debug("%s is unassigned" % server_job) |
| 1113 | ret = False |
| 1114 | return ret |
| 1115 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1116 | def waitUntilSettled(self): |
| 1117 | self.log.debug("Waiting until settled...") |
| 1118 | start = time.time() |
| 1119 | while True: |
| 1120 | if time.time() - start > 10: |
| 1121 | print 'queue status:', |
| 1122 | print self.sched.trigger_event_queue.empty(), |
| 1123 | print self.sched.result_event_queue.empty(), |
| 1124 | print self.fake_gerrit.event_queue.empty(), |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1125 | print self.areAllBuildsWaiting() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1126 | raise Exception("Timeout waiting for Zuul to settle") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1127 | # Make sure no new events show up while we're checking |
| 1128 | self.worker.lock.acquire() |
| 1129 | # have all build states propogated to zuul? |
| 1130 | if self.haveAllBuildsReported(): |
| 1131 | # Join ensures that the queue is empty _and_ events have been |
| 1132 | # processed |
| 1133 | self.fake_gerrit.event_queue.join() |
| 1134 | self.sched.trigger_event_queue.join() |
| 1135 | self.sched.result_event_queue.join() |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 1136 | self.sched.run_handler_lock.acquire() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1137 | if (self.sched.trigger_event_queue.empty() and |
| 1138 | self.sched.result_event_queue.empty() and |
| 1139 | self.fake_gerrit.event_queue.empty() and |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1140 | not self.merge_client.build_sets and |
James E. Blair | 9c2985a | 2014-03-10 10:59:05 -0700 | [diff] [blame] | 1141 | self.haveAllBuildsReported() and |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1142 | self.areAllBuildsWaiting()): |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 1143 | self.sched.run_handler_lock.release() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1144 | self.worker.lock.release() |
| 1145 | self.log.debug("...settled.") |
| 1146 | return |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 1147 | self.sched.run_handler_lock.release() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1148 | self.worker.lock.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1149 | self.sched.wake_event.wait(0.1) |
| 1150 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1151 | def countJobResults(self, jobs, result): |
James E. Blair | 0018a6c | 2013-02-27 14:11:45 -0800 | [diff] [blame] | 1152 | jobs = filter(lambda x: x.result == result, jobs) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1153 | return len(jobs) |
| 1154 | |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 1155 | def getJobFromHistory(self, name): |
| 1156 | history = self.worker.build_history |
| 1157 | for job in history: |
| 1158 | if job.name == name: |
| 1159 | return job |
| 1160 | raise Exception("Unable to find job %s in history" % name) |
| 1161 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1162 | def assertEmptyQueues(self): |
| 1163 | # Make sure there are no orphaned jobs |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1164 | for pipeline in self.sched.layout.pipelines.values(): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1165 | for queue in pipeline.queues: |
| 1166 | if len(queue.queue) != 0: |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1167 | print 'pipeline %s queue %s contents %s' % ( |
| 1168 | pipeline.name, queue.name, queue.queue) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1169 | self.assertEqual(len(queue.queue), 0) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1170 | |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1171 | def assertReportedStat(self, key, value=None, kind=None): |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1172 | start = time.time() |
| 1173 | while time.time() < (start + 5): |
| 1174 | for stat in self.statsd.stats: |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1175 | pprint.pprint(self.statsd.stats) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1176 | k, v = stat.split(':') |
| 1177 | if key == k: |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1178 | if value is None and kind is None: |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1179 | return |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1180 | elif value: |
| 1181 | if value == v: |
| 1182 | return |
| 1183 | elif kind: |
| 1184 | if v.endswith('|' + kind): |
| 1185 | return |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1186 | time.sleep(0.1) |
| 1187 | |
| 1188 | pprint.pprint(self.statsd.stats) |
| 1189 | raise Exception("Key %s not found in reported stats" % key) |
| 1190 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1191 | def test_jobs_launched(self): |
| 1192 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1193 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1194 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1195 | A.addApproval('CRVW', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1196 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1197 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1198 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1199 | 'SUCCESS') |
| 1200 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1201 | 'SUCCESS') |
| 1202 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1203 | 'SUCCESS') |
| 1204 | self.assertEqual(A.data['status'], 'MERGED') |
| 1205 | self.assertEqual(A.reported, 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1206 | |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1207 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 1208 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 1209 | value='1|g') |
| 1210 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 1211 | kind='ms') |
| 1212 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 1213 | value='1|c') |
| 1214 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 1215 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 1216 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1217 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1218 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1219 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1220 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1221 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 1222 | def test_initial_pipeline_gauges(self): |
| 1223 | "Test that each pipeline reported its length on start" |
| 1224 | pipeline_names = self.sched.layout.pipelines.keys() |
| 1225 | self.assertNotEqual(len(pipeline_names), 0) |
| 1226 | for name in pipeline_names: |
| 1227 | self.assertReportedStat('zuul.pipeline.%s.current_changes' % name, |
| 1228 | value='0|g') |
| 1229 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1230 | def test_duplicate_pipelines(self): |
| 1231 | "Test that a change matching multiple pipelines works" |
James E. Blair | 1b4d972 | 2013-05-21 10:32:04 -0700 | [diff] [blame] | 1232 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1233 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1234 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 1235 | self.waitUntilSettled() |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1236 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1237 | self.assertEqual(len(self.history), 2) |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1238 | self.history[0].name == 'project-test1' |
| 1239 | self.history[1].name == 'project-test1' |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1240 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1241 | self.assertEqual(len(A.messages), 2) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1242 | if 'dup1/project-test1' in A.messages[0]: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1243 | self.assertIn('dup1/project-test1', A.messages[0]) |
| 1244 | self.assertNotIn('dup2/project-test1', A.messages[0]) |
| 1245 | self.assertNotIn('dup1/project-test1', A.messages[1]) |
| 1246 | self.assertIn('dup2/project-test1', A.messages[1]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1247 | else: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1248 | self.assertIn('dup1/project-test1', A.messages[1]) |
| 1249 | self.assertNotIn('dup2/project-test1', A.messages[1]) |
| 1250 | self.assertNotIn('dup1/project-test1', A.messages[0]) |
| 1251 | self.assertIn('dup2/project-test1', A.messages[0]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1252 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1253 | def test_parallel_changes(self): |
| 1254 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1255 | |
| 1256 | self.worker.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1257 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1258 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1259 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1260 | A.addApproval('CRVW', 2) |
| 1261 | B.addApproval('CRVW', 2) |
| 1262 | C.addApproval('CRVW', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1263 | |
| 1264 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1265 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1266 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1267 | |
| 1268 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1269 | self.assertEqual(len(self.builds), 1) |
| 1270 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1271 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1272 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1273 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1274 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1275 | self.assertEqual(len(self.builds), 3) |
| 1276 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1277 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1278 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1279 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 1280 | self.assertEqual(self.builds[2].name, 'project-merge') |
| 1281 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1282 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1283 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1284 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1285 | self.assertEqual(len(self.builds), 5) |
| 1286 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1287 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1288 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1289 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1290 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1291 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1292 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
| 1293 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1294 | self.assertTrue(self.job_has_changes(self.builds[3], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1295 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1296 | self.assertEqual(self.builds[4].name, 'project-merge') |
| 1297 | self.assertTrue(self.job_has_changes(self.builds[4], A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1298 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1299 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1300 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1301 | self.assertEqual(len(self.builds), 6) |
| 1302 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1303 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1304 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1305 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1306 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1307 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1308 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
| 1309 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1310 | self.assertTrue(self.job_has_changes(self.builds[3], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1311 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1312 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1313 | self.assertTrue(self.job_has_changes(self.builds[4], A, B, C)) |
| 1314 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 1315 | self.assertTrue(self.job_has_changes(self.builds[5], A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1316 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1317 | self.worker.hold_jobs_in_build = False |
| 1318 | self.worker.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1319 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1320 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1321 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1322 | self.assertEqual(len(self.history), 9) |
| 1323 | self.assertEqual(A.data['status'], 'MERGED') |
| 1324 | self.assertEqual(B.data['status'], 'MERGED') |
| 1325 | self.assertEqual(C.data['status'], 'MERGED') |
| 1326 | self.assertEqual(A.reported, 2) |
| 1327 | self.assertEqual(B.reported, 2) |
| 1328 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1329 | |
| 1330 | def test_failed_changes(self): |
| 1331 | "Test that a change behind a failed change is retested" |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 1332 | self.worker.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1333 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1334 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1335 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1336 | A.addApproval('CRVW', 2) |
| 1337 | B.addApproval('CRVW', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1338 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1339 | self.worker.addFailTest('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1340 | |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 1341 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1342 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1343 | self.waitUntilSettled() |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 1344 | |
| 1345 | self.worker.release('.*-merge') |
| 1346 | self.waitUntilSettled() |
| 1347 | |
| 1348 | self.worker.hold_jobs_in_build = False |
| 1349 | self.worker.release() |
| 1350 | |
| 1351 | self.waitUntilSettled() |
| 1352 | # It's certain that the merge job for change 2 will run, but |
| 1353 | # the test1 and test2 jobs may or may not run. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1354 | self.assertTrue(len(self.history) > 6) |
| 1355 | self.assertEqual(A.data['status'], 'NEW') |
| 1356 | self.assertEqual(B.data['status'], 'MERGED') |
| 1357 | self.assertEqual(A.reported, 2) |
| 1358 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1359 | |
| 1360 | def test_independent_queues(self): |
| 1361 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1362 | |
| 1363 | self.worker.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1364 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1365 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1366 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1367 | A.addApproval('CRVW', 2) |
| 1368 | B.addApproval('CRVW', 2) |
| 1369 | C.addApproval('CRVW', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1370 | |
| 1371 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1372 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1373 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1374 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1375 | self.waitUntilSettled() |
| 1376 | |
| 1377 | # There should be one merge job at the head of each queue running |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1378 | self.assertEqual(len(self.builds), 2) |
| 1379 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1380 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1381 | self.assertEqual(self.builds[1].name, 'project1-merge') |
| 1382 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1383 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1384 | # Release the current merge builds |
| 1385 | self.worker.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1386 | self.waitUntilSettled() |
| 1387 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1388 | self.worker.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1389 | self.waitUntilSettled() |
| 1390 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1391 | # All the test builds should be running: |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1392 | # project1 (3) + project2 (3) + project (2) = 8 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1393 | self.assertEqual(len(self.builds), 8) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1394 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1395 | self.worker.release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1396 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1397 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1398 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1399 | self.assertEqual(len(self.history), 11) |
| 1400 | self.assertEqual(A.data['status'], 'MERGED') |
| 1401 | self.assertEqual(B.data['status'], 'MERGED') |
| 1402 | self.assertEqual(C.data['status'], 'MERGED') |
| 1403 | self.assertEqual(A.reported, 2) |
| 1404 | self.assertEqual(B.reported, 2) |
| 1405 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1406 | |
| 1407 | def test_failed_change_at_head(self): |
| 1408 | "Test that if a change at the head fails, jobs behind it are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1409 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1410 | self.worker.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1411 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1412 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1413 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1414 | A.addApproval('CRVW', 2) |
| 1415 | B.addApproval('CRVW', 2) |
| 1416 | C.addApproval('CRVW', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1417 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1418 | self.worker.addFailTest('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1419 | |
| 1420 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1421 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1422 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1423 | |
| 1424 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1425 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1426 | self.assertEqual(len(self.builds), 1) |
| 1427 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1428 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1429 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1430 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1431 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1432 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1433 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1434 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1435 | self.waitUntilSettled() |
| 1436 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1437 | self.assertEqual(len(self.builds), 6) |
| 1438 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1439 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1440 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1441 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1442 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1443 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1444 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1445 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1446 | self.waitUntilSettled() |
| 1447 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1448 | # project-test2, project-merge for B |
| 1449 | self.assertEqual(len(self.builds), 2) |
| 1450 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1451 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1452 | self.worker.hold_jobs_in_build = False |
| 1453 | self.worker.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1454 | self.waitUntilSettled() |
| 1455 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1456 | self.assertEqual(len(self.builds), 0) |
| 1457 | self.assertEqual(len(self.history), 15) |
| 1458 | self.assertEqual(A.data['status'], 'NEW') |
| 1459 | self.assertEqual(B.data['status'], 'MERGED') |
| 1460 | self.assertEqual(C.data['status'], 'MERGED') |
| 1461 | self.assertEqual(A.reported, 2) |
| 1462 | self.assertEqual(B.reported, 2) |
| 1463 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1464 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1465 | def test_failed_change_in_middle(self): |
| 1466 | "Test a failed change in the middle of the queue" |
| 1467 | |
| 1468 | self.worker.hold_jobs_in_build = True |
| 1469 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1470 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1471 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1472 | A.addApproval('CRVW', 2) |
| 1473 | B.addApproval('CRVW', 2) |
| 1474 | C.addApproval('CRVW', 2) |
| 1475 | |
| 1476 | self.worker.addFailTest('project-test1', B) |
| 1477 | |
| 1478 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1479 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1480 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1481 | |
| 1482 | self.waitUntilSettled() |
| 1483 | |
| 1484 | self.worker.release('.*-merge') |
| 1485 | self.waitUntilSettled() |
| 1486 | self.worker.release('.*-merge') |
| 1487 | self.waitUntilSettled() |
| 1488 | self.worker.release('.*-merge') |
| 1489 | self.waitUntilSettled() |
| 1490 | |
| 1491 | self.assertEqual(len(self.builds), 6) |
| 1492 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1493 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1494 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1495 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1496 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1497 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 1498 | |
| 1499 | self.release(self.builds[2]) |
| 1500 | self.waitUntilSettled() |
| 1501 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1502 | # project-test1 and project-test2 for A |
| 1503 | # project-test2 for B |
| 1504 | # project-merge for C (without B) |
| 1505 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1506 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 1507 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1508 | self.worker.release('.*-merge') |
| 1509 | self.waitUntilSettled() |
| 1510 | |
| 1511 | # project-test1 and project-test2 for A |
| 1512 | # project-test2 for B |
| 1513 | # project-test1 and project-test2 for C |
| 1514 | self.assertEqual(len(self.builds), 5) |
| 1515 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1516 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 1517 | builds = items[0].current_build_set.getBuilds() |
| 1518 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 1519 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 1520 | builds = items[1].current_build_set.getBuilds() |
| 1521 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 1522 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 1523 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 1524 | builds = items[2].current_build_set.getBuilds() |
| 1525 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1526 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1527 | |
| 1528 | self.worker.hold_jobs_in_build = False |
| 1529 | self.worker.release() |
| 1530 | self.waitUntilSettled() |
| 1531 | |
| 1532 | self.assertEqual(len(self.builds), 0) |
| 1533 | self.assertEqual(len(self.history), 12) |
| 1534 | self.assertEqual(A.data['status'], 'MERGED') |
| 1535 | self.assertEqual(B.data['status'], 'NEW') |
| 1536 | self.assertEqual(C.data['status'], 'MERGED') |
| 1537 | self.assertEqual(A.reported, 2) |
| 1538 | self.assertEqual(B.reported, 2) |
| 1539 | self.assertEqual(C.reported, 2) |
| 1540 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1541 | def test_failed_change_at_head_with_queue(self): |
| 1542 | "Test that if a change at the head fails, queued jobs are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1543 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1544 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1545 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1546 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1547 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1548 | A.addApproval('CRVW', 2) |
| 1549 | B.addApproval('CRVW', 2) |
| 1550 | C.addApproval('CRVW', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1551 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1552 | self.worker.addFailTest('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1553 | |
| 1554 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1555 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1556 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1557 | |
| 1558 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1559 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1560 | self.assertEqual(len(self.builds), 0) |
| 1561 | self.assertEqual(len(queue), 1) |
| 1562 | self.assertEqual(queue[0].name, 'build:project-merge') |
| 1563 | self.assertTrue(self.job_has_changes(queue[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1564 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1565 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1566 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1567 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1568 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1569 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1570 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1571 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1572 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1573 | self.assertEqual(len(self.builds), 0) |
| 1574 | self.assertEqual(len(queue), 6) |
| 1575 | self.assertEqual(queue[0].name, 'build:project-test1') |
| 1576 | self.assertEqual(queue[1].name, 'build:project-test2') |
| 1577 | self.assertEqual(queue[2].name, 'build:project-test1') |
| 1578 | self.assertEqual(queue[3].name, 'build:project-test2') |
| 1579 | self.assertEqual(queue[4].name, 'build:project-test1') |
| 1580 | self.assertEqual(queue[5].name, 'build:project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1581 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1582 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1583 | self.waitUntilSettled() |
| 1584 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1585 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1586 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1587 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 1588 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1589 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1590 | self.gearman_server.hold_jobs_in_queue = False |
| 1591 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1592 | self.waitUntilSettled() |
| 1593 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1594 | self.assertEqual(len(self.builds), 0) |
| 1595 | self.assertEqual(len(self.history), 11) |
| 1596 | self.assertEqual(A.data['status'], 'NEW') |
| 1597 | self.assertEqual(B.data['status'], 'MERGED') |
| 1598 | self.assertEqual(C.data['status'], 'MERGED') |
| 1599 | self.assertEqual(A.reported, 2) |
| 1600 | self.assertEqual(B.reported, 2) |
| 1601 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1602 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 1603 | def test_two_failed_changes_at_head(self): |
| 1604 | "Test that changes are reparented correctly if 2 fail at head" |
| 1605 | |
| 1606 | self.worker.hold_jobs_in_build = True |
| 1607 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1608 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1609 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1610 | A.addApproval('CRVW', 2) |
| 1611 | B.addApproval('CRVW', 2) |
| 1612 | C.addApproval('CRVW', 2) |
| 1613 | |
| 1614 | self.worker.addFailTest('project-test1', A) |
| 1615 | self.worker.addFailTest('project-test1', B) |
| 1616 | |
| 1617 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1618 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1619 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1620 | self.waitUntilSettled() |
| 1621 | |
| 1622 | self.worker.release('.*-merge') |
| 1623 | self.waitUntilSettled() |
| 1624 | self.worker.release('.*-merge') |
| 1625 | self.waitUntilSettled() |
| 1626 | self.worker.release('.*-merge') |
| 1627 | self.waitUntilSettled() |
| 1628 | |
| 1629 | self.assertEqual(len(self.builds), 6) |
| 1630 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1631 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1632 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1633 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1634 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1635 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 1636 | |
| 1637 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1638 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 1639 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 1640 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 1641 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 1642 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 1643 | |
| 1644 | # Fail change B first |
| 1645 | self.release(self.builds[2]) |
| 1646 | self.waitUntilSettled() |
| 1647 | |
| 1648 | # restart of C after B failure |
| 1649 | self.worker.release('.*-merge') |
| 1650 | self.waitUntilSettled() |
| 1651 | |
| 1652 | self.assertEqual(len(self.builds), 5) |
| 1653 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1654 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1655 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 1656 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1657 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 1658 | |
| 1659 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 1660 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 1661 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 1662 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 1663 | self.assertFalse(self.job_has_changes(self.builds[4], B)) |
| 1664 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 1665 | |
| 1666 | # Finish running all passing jobs for change A |
| 1667 | self.release(self.builds[1]) |
| 1668 | self.waitUntilSettled() |
| 1669 | # Fail and report change A |
| 1670 | self.release(self.builds[0]) |
| 1671 | self.waitUntilSettled() |
| 1672 | |
| 1673 | # restart of B,C after A failure |
| 1674 | self.worker.release('.*-merge') |
| 1675 | self.waitUntilSettled() |
| 1676 | self.worker.release('.*-merge') |
| 1677 | self.waitUntilSettled() |
| 1678 | |
| 1679 | self.assertEqual(len(self.builds), 4) |
| 1680 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 1681 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 1682 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 1683 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 1684 | |
| 1685 | self.assertFalse(self.job_has_changes(self.builds[1], A)) |
| 1686 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
| 1687 | self.assertFalse(self.job_has_changes(self.builds[1], C)) |
| 1688 | |
| 1689 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 1690 | # After A failed and B and C restarted, B should be back in |
| 1691 | # C's tests because it has not failed yet. |
| 1692 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 1693 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 1694 | |
| 1695 | self.worker.hold_jobs_in_build = False |
| 1696 | self.worker.release() |
| 1697 | self.waitUntilSettled() |
| 1698 | |
| 1699 | self.assertEqual(len(self.builds), 0) |
| 1700 | self.assertEqual(len(self.history), 21) |
| 1701 | self.assertEqual(A.data['status'], 'NEW') |
| 1702 | self.assertEqual(B.data['status'], 'NEW') |
| 1703 | self.assertEqual(C.data['status'], 'MERGED') |
| 1704 | self.assertEqual(A.reported, 2) |
| 1705 | self.assertEqual(B.reported, 2) |
| 1706 | self.assertEqual(C.reported, 2) |
| 1707 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1708 | def test_patch_order(self): |
| 1709 | "Test that dependent patches are tested in the right order" |
| 1710 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1711 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1712 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1713 | A.addApproval('CRVW', 2) |
| 1714 | B.addApproval('CRVW', 2) |
| 1715 | C.addApproval('CRVW', 2) |
| 1716 | |
| 1717 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 1718 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1719 | M2.setMerged() |
| 1720 | M1.setMerged() |
| 1721 | |
| 1722 | # C -> B -> A -> M1 -> M2 |
| 1723 | # M2 is here to make sure it is never queried. If it is, it |
| 1724 | # means zuul is walking down the entire history of merged |
| 1725 | # changes. |
| 1726 | |
| 1727 | C.setDependsOn(B, 1) |
| 1728 | B.setDependsOn(A, 1) |
| 1729 | A.setDependsOn(M1, 1) |
| 1730 | M1.setDependsOn(M2, 1) |
| 1731 | |
| 1732 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1733 | |
| 1734 | self.waitUntilSettled() |
| 1735 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1736 | self.assertEqual(A.data['status'], 'NEW') |
| 1737 | self.assertEqual(B.data['status'], 'NEW') |
| 1738 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1739 | |
| 1740 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1741 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1742 | |
| 1743 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1744 | self.assertEqual(M2.queried, 0) |
| 1745 | self.assertEqual(A.data['status'], 'MERGED') |
| 1746 | self.assertEqual(B.data['status'], 'MERGED') |
| 1747 | self.assertEqual(C.data['status'], 'MERGED') |
| 1748 | self.assertEqual(A.reported, 2) |
| 1749 | self.assertEqual(B.reported, 2) |
| 1750 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1751 | |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 1752 | def test_trigger_cache(self): |
| 1753 | "Test that the trigger cache operates correctly" |
| 1754 | self.worker.hold_jobs_in_build = True |
| 1755 | |
| 1756 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1757 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1758 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
| 1759 | A.addApproval('CRVW', 2) |
| 1760 | B.addApproval('CRVW', 2) |
| 1761 | |
| 1762 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1763 | M1.setMerged() |
| 1764 | |
| 1765 | B.setDependsOn(A, 1) |
| 1766 | A.setDependsOn(M1, 1) |
| 1767 | |
| 1768 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1769 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 1770 | |
| 1771 | self.waitUntilSettled() |
| 1772 | |
| 1773 | for build in self.builds: |
| 1774 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 1775 | build.release() |
| 1776 | self.waitUntilSettled() |
| 1777 | for build in self.builds: |
| 1778 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 1779 | build.release() |
| 1780 | self.waitUntilSettled() |
| 1781 | |
| 1782 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1783 | self.waitUntilSettled() |
| 1784 | |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1785 | self.log.debug("len %s " % self.gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 1786 | # there should still be changes in the cache |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1787 | self.assertNotEqual(len(self.gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 1788 | |
| 1789 | self.worker.hold_jobs_in_build = False |
| 1790 | self.worker.release() |
| 1791 | self.waitUntilSettled() |
| 1792 | |
| 1793 | self.assertEqual(A.data['status'], 'MERGED') |
| 1794 | self.assertEqual(B.data['status'], 'MERGED') |
| 1795 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 1796 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 1797 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1798 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1799 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1800 | # TODO: move to test_gerrit (this is a unit test!) |
| 1801 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1802 | trigger = self.sched.layout.pipelines['gate'].trigger |
| 1803 | a = self.sched.triggers['gerrit'].getChange(1, 2) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1804 | mgr = self.sched.layout.pipelines['gate'].manager |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1805 | self.assertFalse(trigger.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1806 | |
| 1807 | A.addApproval('CRVW', 2) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1808 | a = trigger.getChange(1, 2, refresh=True) |
| 1809 | self.assertFalse(trigger.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1810 | |
| 1811 | A.addApproval('APRV', 1) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1812 | a = trigger.getChange(1, 2, refresh=True) |
| 1813 | self.assertTrue(trigger.canMerge(a, mgr.getSubmitAllowNeeds())) |
| 1814 | trigger.maintainCache([]) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1815 | |
| 1816 | def test_build_configuration(self): |
| 1817 | "Test that zuul merges the right commits for testing" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1818 | |
| 1819 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1820 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1821 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1822 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1823 | A.addApproval('CRVW', 2) |
| 1824 | B.addApproval('CRVW', 2) |
| 1825 | C.addApproval('CRVW', 2) |
| 1826 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1827 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1828 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1829 | self.waitUntilSettled() |
| 1830 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1831 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1832 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1833 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1834 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1835 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1836 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1837 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1838 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1839 | self.gearman_server.hold_jobs_in_queue = False |
| 1840 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1841 | self.waitUntilSettled() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1842 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1843 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1844 | repo = git.Repo(path) |
| 1845 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1846 | repo_messages.reverse() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1847 | correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1848 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1849 | |
| 1850 | def test_build_configuration_conflict(self): |
| 1851 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1852 | |
| 1853 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1854 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1855 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1856 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1857 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1858 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1859 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1860 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1861 | 'master', 'C') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1862 | A.addApproval('CRVW', 2) |
| 1863 | B.addApproval('CRVW', 2) |
| 1864 | C.addApproval('CRVW', 2) |
| 1865 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1866 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1867 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1868 | self.waitUntilSettled() |
| 1869 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1870 | self.assertEqual(A.reported, 1) |
| 1871 | self.assertEqual(B.reported, 1) |
| 1872 | self.assertEqual(C.reported, 1) |
| 1873 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1874 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1875 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1876 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1877 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1878 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1879 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1880 | |
| 1881 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 1882 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1883 | self.gearman_server.hold_jobs_in_queue = False |
| 1884 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1885 | self.waitUntilSettled() |
| 1886 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1887 | self.assertEqual(A.data['status'], 'MERGED') |
| 1888 | self.assertEqual(B.data['status'], 'NEW') |
| 1889 | self.assertEqual(C.data['status'], 'MERGED') |
| 1890 | self.assertEqual(A.reported, 2) |
| 1891 | self.assertEqual(B.reported, 2) |
| 1892 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1893 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1894 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1895 | def test_post(self): |
| 1896 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1897 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1898 | e = { |
| 1899 | "type": "ref-updated", |
| 1900 | "submitter": { |
| 1901 | "name": "User Name", |
| 1902 | }, |
| 1903 | "refUpdate": { |
| 1904 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1905 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1906 | "refName": "master", |
| 1907 | "project": "org/project", |
| 1908 | } |
| 1909 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1910 | self.fake_gerrit.addEvent(e) |
| 1911 | self.waitUntilSettled() |
| 1912 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1913 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1914 | self.assertEqual(len(self.history), 1) |
| 1915 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1916 | |
| 1917 | def test_build_configuration_branch(self): |
| 1918 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1919 | |
| 1920 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1921 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1922 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1923 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
| 1924 | A.addApproval('CRVW', 2) |
| 1925 | B.addApproval('CRVW', 2) |
| 1926 | C.addApproval('CRVW', 2) |
| 1927 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1928 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1929 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1930 | self.waitUntilSettled() |
| 1931 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1932 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1933 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1934 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1935 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1936 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1937 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1938 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1939 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1940 | self.gearman_server.hold_jobs_in_queue = False |
| 1941 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1942 | self.waitUntilSettled() |
| 1943 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1944 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1945 | repo = git.Repo(path) |
| 1946 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1947 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1948 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1949 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1950 | |
| 1951 | def test_build_configuration_branch_interaction(self): |
| 1952 | "Test that switching between branches works" |
| 1953 | self.test_build_configuration() |
| 1954 | self.test_build_configuration_branch() |
| 1955 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1956 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1957 | repo = git.Repo(path) |
| 1958 | repo.heads.master.commit = repo.commit('init') |
| 1959 | self.test_build_configuration() |
| 1960 | |
| 1961 | def test_build_configuration_multi_branch(self): |
| 1962 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1963 | |
| 1964 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1965 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1966 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1967 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1968 | A.addApproval('CRVW', 2) |
| 1969 | B.addApproval('CRVW', 2) |
| 1970 | C.addApproval('CRVW', 2) |
| 1971 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1972 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1973 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1974 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1975 | queue = self.gearman_server.getQueue() |
| 1976 | job_A = None |
| 1977 | for job in queue: |
| 1978 | if 'project-merge' in job.name: |
| 1979 | job_A = job |
| 1980 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 1981 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 1982 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 1983 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1984 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1985 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1986 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1987 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1988 | job_B = None |
| 1989 | for job in queue: |
| 1990 | if 'project-merge' in job.name: |
| 1991 | job_B = job |
| 1992 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1993 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1994 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1995 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 1996 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1997 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1998 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1999 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 2000 | for job in queue: |
| 2001 | if 'project-merge' in job.name: |
| 2002 | job_C = job |
| 2003 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2004 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 2005 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2006 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2007 | self.gearman_server.hold_jobs_in_queue = False |
| 2008 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2009 | self.waitUntilSettled() |
| 2010 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 2011 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2012 | repo = git.Repo(path) |
| 2013 | |
| 2014 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 2015 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2016 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2017 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2018 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2019 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2020 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2021 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 2022 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2023 | |
| 2024 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 2025 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2026 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2027 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 2028 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2029 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 2030 | self.assertEqual(repo_shas[0], commit_B) |
| 2031 | |
| 2032 | repo_messages = [c.message.strip() |
| 2033 | for c in repo.iter_commits(ref_A)] |
| 2034 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 2035 | repo_messages.reverse() |
| 2036 | correct_messages = ['initial commit', 'A-1'] |
| 2037 | self.assertEqual(repo_messages, correct_messages) |
| 2038 | self.assertEqual(repo_shas[0], commit_A) |
| 2039 | |
| 2040 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 2041 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 2042 | |
| 2043 | def test_one_job_project(self): |
| 2044 | "Test that queueing works with one job" |
| 2045 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 2046 | 'master', 'A') |
| 2047 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 2048 | 'master', 'B') |
| 2049 | A.addApproval('CRVW', 2) |
| 2050 | B.addApproval('CRVW', 2) |
| 2051 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2052 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2053 | self.waitUntilSettled() |
| 2054 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2055 | self.assertEqual(A.data['status'], 'MERGED') |
| 2056 | self.assertEqual(A.reported, 2) |
| 2057 | self.assertEqual(B.data['status'], 'MERGED') |
| 2058 | self.assertEqual(B.reported, 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2059 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 2060 | def test_job_from_templates_launched(self): |
| 2061 | "Test whether a job generated via a template can be launched" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2062 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 2063 | A = self.fake_gerrit.addFakeChange( |
| 2064 | 'org/templated-project', 'master', 'A') |
| 2065 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2066 | self.waitUntilSettled() |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 2067 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2068 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2069 | 'SUCCESS') |
| 2070 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2071 | 'SUCCESS') |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 2072 | |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 2073 | def test_layered_templates(self): |
| 2074 | "Test whether a job generated via a template can be launched" |
| 2075 | |
| 2076 | A = self.fake_gerrit.addFakeChange( |
| 2077 | 'org/layered-project', 'master', 'A') |
| 2078 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2079 | self.waitUntilSettled() |
| 2080 | |
| 2081 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2082 | 'SUCCESS') |
| 2083 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2084 | 'SUCCESS') |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 2085 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 2086 | ).result, 'SUCCESS') |
| 2087 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 2088 | ).result, 'SUCCESS') |
James E. Blair | 12a92b1 | 2014-03-26 11:54:53 -0700 | [diff] [blame] | 2089 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 2090 | ).result, 'SUCCESS') |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 2091 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 2092 | 'SUCCESS') |
| 2093 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2094 | def test_dependent_changes_dequeue(self): |
| 2095 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2096 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2097 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2098 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2099 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2100 | A.addApproval('CRVW', 2) |
| 2101 | B.addApproval('CRVW', 2) |
| 2102 | C.addApproval('CRVW', 2) |
| 2103 | |
| 2104 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 2105 | M1.setMerged() |
| 2106 | |
| 2107 | # C -> B -> A -> M1 |
| 2108 | |
| 2109 | C.setDependsOn(B, 1) |
| 2110 | B.setDependsOn(A, 1) |
| 2111 | A.setDependsOn(M1, 1) |
| 2112 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2113 | self.worker.addFailTest('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2114 | |
| 2115 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2116 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2117 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2118 | |
| 2119 | self.waitUntilSettled() |
| 2120 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2121 | self.assertEqual(A.data['status'], 'NEW') |
| 2122 | self.assertEqual(A.reported, 2) |
| 2123 | self.assertEqual(B.data['status'], 'NEW') |
| 2124 | self.assertEqual(B.reported, 2) |
| 2125 | self.assertEqual(C.data['status'], 'NEW') |
| 2126 | self.assertEqual(C.reported, 2) |
| 2127 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2128 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 2129 | def test_failing_dependent_changes(self): |
| 2130 | "Test that failing dependent patches are taken out of stream" |
| 2131 | self.worker.hold_jobs_in_build = True |
| 2132 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2133 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2134 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2135 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 2136 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 2137 | A.addApproval('CRVW', 2) |
| 2138 | B.addApproval('CRVW', 2) |
| 2139 | C.addApproval('CRVW', 2) |
| 2140 | D.addApproval('CRVW', 2) |
| 2141 | E.addApproval('CRVW', 2) |
| 2142 | |
| 2143 | # E, D -> C -> B, A |
| 2144 | |
| 2145 | D.setDependsOn(C, 1) |
| 2146 | C.setDependsOn(B, 1) |
| 2147 | |
| 2148 | self.worker.addFailTest('project-test1', B) |
| 2149 | |
| 2150 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2151 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2152 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2153 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2154 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 2155 | |
| 2156 | self.waitUntilSettled() |
| 2157 | self.worker.release('.*-merge') |
| 2158 | self.waitUntilSettled() |
| 2159 | self.worker.release('.*-merge') |
| 2160 | self.waitUntilSettled() |
| 2161 | self.worker.release('.*-merge') |
| 2162 | self.waitUntilSettled() |
| 2163 | self.worker.release('.*-merge') |
| 2164 | self.waitUntilSettled() |
| 2165 | self.worker.release('.*-merge') |
| 2166 | self.waitUntilSettled() |
| 2167 | |
| 2168 | self.worker.hold_jobs_in_build = False |
| 2169 | for build in self.builds: |
| 2170 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 2171 | build.release() |
| 2172 | self.waitUntilSettled() |
| 2173 | |
| 2174 | self.worker.release() |
| 2175 | self.waitUntilSettled() |
| 2176 | |
| 2177 | self.assertEqual(A.data['status'], 'MERGED') |
| 2178 | self.assertEqual(A.reported, 2) |
| 2179 | self.assertEqual(B.data['status'], 'NEW') |
| 2180 | self.assertEqual(B.reported, 2) |
| 2181 | self.assertEqual(C.data['status'], 'NEW') |
| 2182 | self.assertEqual(C.reported, 2) |
| 2183 | self.assertEqual(D.data['status'], 'NEW') |
| 2184 | self.assertEqual(D.reported, 2) |
| 2185 | self.assertEqual(E.data['status'], 'MERGED') |
| 2186 | self.assertEqual(E.reported, 2) |
| 2187 | self.assertEqual(len(self.history), 18) |
| 2188 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2189 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2190 | "Test that if a change at the head fails it is dequeued only once" |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2191 | # If it's dequeued more than once, we should see extra |
| 2192 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2193 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2194 | self.worker.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2195 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2196 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2197 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2198 | A.addApproval('CRVW', 2) |
| 2199 | B.addApproval('CRVW', 2) |
| 2200 | C.addApproval('CRVW', 2) |
| 2201 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2202 | self.worker.addFailTest('project1-test1', A) |
| 2203 | self.worker.addFailTest('project1-test2', A) |
| 2204 | self.worker.addFailTest('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2205 | |
| 2206 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2207 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2208 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2209 | |
| 2210 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2211 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2212 | self.assertEqual(len(self.builds), 1) |
| 2213 | self.assertEqual(self.builds[0].name, 'project1-merge') |
| 2214 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2215 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2216 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2217 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2218 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2219 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2220 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2221 | self.waitUntilSettled() |
| 2222 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2223 | self.assertEqual(len(self.builds), 9) |
| 2224 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 2225 | self.assertEqual(self.builds[1].name, 'project1-test2') |
| 2226 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
| 2227 | self.assertEqual(self.builds[3].name, 'project1-test1') |
| 2228 | self.assertEqual(self.builds[4].name, 'project1-test2') |
| 2229 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
| 2230 | self.assertEqual(self.builds[6].name, 'project1-test1') |
| 2231 | self.assertEqual(self.builds[7].name, 'project1-test2') |
| 2232 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2233 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2234 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2235 | self.waitUntilSettled() |
| 2236 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2237 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 2238 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2239 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2240 | self.worker.hold_jobs_in_build = False |
| 2241 | self.worker.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2242 | self.waitUntilSettled() |
| 2243 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2244 | self.assertEqual(len(self.builds), 0) |
| 2245 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2246 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2247 | self.assertEqual(A.data['status'], 'NEW') |
| 2248 | self.assertEqual(B.data['status'], 'MERGED') |
| 2249 | self.assertEqual(C.data['status'], 'MERGED') |
| 2250 | self.assertEqual(A.reported, 2) |
| 2251 | self.assertEqual(B.reported, 2) |
| 2252 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2253 | |
| 2254 | def test_nonvoting_job(self): |
| 2255 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2256 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2257 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 2258 | 'master', 'A') |
| 2259 | A.addApproval('CRVW', 2) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2260 | self.worker.addFailTest('nonvoting-project-test2', A) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2261 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2262 | |
| 2263 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2264 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2265 | self.assertEqual(A.data['status'], 'MERGED') |
| 2266 | self.assertEqual(A.reported, 2) |
| 2267 | self.assertEqual( |
| 2268 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 2269 | 'SUCCESS') |
| 2270 | self.assertEqual( |
| 2271 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 2272 | 'SUCCESS') |
| 2273 | self.assertEqual( |
| 2274 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 2275 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2276 | |
| 2277 | def test_check_queue_success(self): |
| 2278 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2279 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2280 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2281 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2282 | |
| 2283 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2284 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2285 | self.assertEqual(A.data['status'], 'NEW') |
| 2286 | self.assertEqual(A.reported, 1) |
| 2287 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2288 | 'SUCCESS') |
| 2289 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2290 | 'SUCCESS') |
| 2291 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2292 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2293 | |
| 2294 | def test_check_queue_failure(self): |
| 2295 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2296 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2297 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2298 | self.worker.addFailTest('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2299 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2300 | |
| 2301 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2302 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2303 | self.assertEqual(A.data['status'], 'NEW') |
| 2304 | self.assertEqual(A.reported, 1) |
| 2305 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 2306 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2307 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2308 | 'SUCCESS') |
| 2309 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2310 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2311 | |
| 2312 | def test_dependent_behind_dequeue(self): |
| 2313 | "test that dependent changes behind dequeued changes work" |
| 2314 | # This complicated test is a reproduction of a real life bug |
| 2315 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2316 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2317 | self.worker.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2318 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2319 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2320 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2321 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 2322 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 2323 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 2324 | D.setDependsOn(C, 1) |
| 2325 | E.setDependsOn(D, 1) |
| 2326 | A.addApproval('CRVW', 2) |
| 2327 | B.addApproval('CRVW', 2) |
| 2328 | C.addApproval('CRVW', 2) |
| 2329 | D.addApproval('CRVW', 2) |
| 2330 | E.addApproval('CRVW', 2) |
| 2331 | F.addApproval('CRVW', 2) |
| 2332 | |
| 2333 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2334 | |
| 2335 | # Change object re-use in the gerrit trigger is hidden if |
| 2336 | # changes are added in quick succession; waiting makes it more |
| 2337 | # like real life. |
| 2338 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2339 | self.waitUntilSettled() |
| 2340 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2341 | self.waitUntilSettled() |
| 2342 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2343 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2344 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2345 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2346 | self.waitUntilSettled() |
| 2347 | |
| 2348 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2349 | self.waitUntilSettled() |
| 2350 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2351 | self.waitUntilSettled() |
| 2352 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 2353 | self.waitUntilSettled() |
| 2354 | self.fake_gerrit.addEvent(F.addApproval('APRV', 1)) |
| 2355 | self.waitUntilSettled() |
| 2356 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2357 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2358 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2359 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2360 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2361 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2362 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2363 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2364 | self.waitUntilSettled() |
| 2365 | |
| 2366 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 2367 | |
| 2368 | # Grab pointers to the jobs we want to release before |
| 2369 | # releasing any, because list indexes may change as |
| 2370 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2371 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 2372 | a.release() |
| 2373 | b.release() |
| 2374 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2375 | self.waitUntilSettled() |
| 2376 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2377 | self.worker.hold_jobs_in_build = False |
| 2378 | self.worker.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2379 | self.waitUntilSettled() |
| 2380 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2381 | self.assertEqual(A.data['status'], 'NEW') |
| 2382 | self.assertEqual(B.data['status'], 'MERGED') |
| 2383 | self.assertEqual(C.data['status'], 'MERGED') |
| 2384 | self.assertEqual(D.data['status'], 'MERGED') |
| 2385 | self.assertEqual(E.data['status'], 'MERGED') |
| 2386 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2387 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2388 | self.assertEqual(A.reported, 2) |
| 2389 | self.assertEqual(B.reported, 2) |
| 2390 | self.assertEqual(C.reported, 2) |
| 2391 | self.assertEqual(D.reported, 2) |
| 2392 | self.assertEqual(E.reported, 2) |
| 2393 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2394 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2395 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 2396 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2397 | |
| 2398 | def test_merger_repack(self): |
| 2399 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2400 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2401 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2402 | A.addApproval('CRVW', 2) |
| 2403 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2404 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2405 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2406 | 'SUCCESS') |
| 2407 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2408 | 'SUCCESS') |
| 2409 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2410 | 'SUCCESS') |
| 2411 | self.assertEqual(A.data['status'], 'MERGED') |
| 2412 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2413 | self.assertEmptyQueues() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2414 | self.worker.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2415 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 2416 | path = os.path.join(self.git_root, "org/project") |
| 2417 | print repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2418 | |
| 2419 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2420 | A.addApproval('CRVW', 2) |
| 2421 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2422 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2423 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2424 | 'SUCCESS') |
| 2425 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2426 | 'SUCCESS') |
| 2427 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2428 | 'SUCCESS') |
| 2429 | self.assertEqual(A.data['status'], 'MERGED') |
| 2430 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2431 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2432 | def test_merger_repack_large_change(self): |
| 2433 | "Test that the merger works with large changes after a repack" |
| 2434 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 2435 | # This test assumes the repo is already cloned; make sure it is |
| 2436 | url = self.sched.triggers['gerrit'].getGitUrl( |
| 2437 | self.sched.layout.projects['org/project1']) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 2438 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2439 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2440 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 2441 | path = os.path.join(self.upstream_root, "org/project1") |
| 2442 | print repack_repo(path) |
| 2443 | path = os.path.join(self.git_root, "org/project1") |
| 2444 | print repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2445 | |
| 2446 | A.addApproval('CRVW', 2) |
| 2447 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2448 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2449 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2450 | 'SUCCESS') |
| 2451 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2452 | 'SUCCESS') |
| 2453 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2454 | 'SUCCESS') |
| 2455 | self.assertEqual(A.data['status'], 'MERGED') |
| 2456 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2457 | |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2458 | def test_nonexistent_job(self): |
| 2459 | "Test launching a job that doesn't exist" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2460 | # Set to the state immediately after a restart |
| 2461 | self.resetGearmanServer() |
| 2462 | self.launcher.negative_function_cache_ttl = 0 |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2463 | |
| 2464 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2465 | A.addApproval('CRVW', 2) |
| 2466 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2467 | # There may be a thread about to report a lost change |
| 2468 | while A.reported < 2: |
| 2469 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2470 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2471 | self.assertFalse(job_names) |
| 2472 | self.assertEqual(A.data['status'], 'NEW') |
| 2473 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2474 | self.assertEmptyQueues() |
| 2475 | |
| 2476 | # Make sure things still work: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2477 | self.registerJobs() |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2478 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2479 | A.addApproval('CRVW', 2) |
| 2480 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2481 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2482 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2483 | 'SUCCESS') |
| 2484 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2485 | 'SUCCESS') |
| 2486 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2487 | 'SUCCESS') |
| 2488 | self.assertEqual(A.data['status'], 'MERGED') |
| 2489 | self.assertEqual(A.reported, 2) |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 2490 | |
| 2491 | def test_single_nonexistent_post_job(self): |
| 2492 | "Test launching a single post job that doesn't exist" |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 2493 | e = { |
| 2494 | "type": "ref-updated", |
| 2495 | "submitter": { |
| 2496 | "name": "User Name", |
| 2497 | }, |
| 2498 | "refUpdate": { |
| 2499 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 2500 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 2501 | "refName": "master", |
| 2502 | "project": "org/project", |
| 2503 | } |
| 2504 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2505 | # Set to the state immediately after a restart |
| 2506 | self.resetGearmanServer() |
| 2507 | self.launcher.negative_function_cache_ttl = 0 |
| 2508 | |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 2509 | self.fake_gerrit.addEvent(e) |
| 2510 | self.waitUntilSettled() |
| 2511 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2512 | self.assertEqual(len(self.history), 0) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2513 | |
| 2514 | def test_new_patchset_dequeues_old(self): |
| 2515 | "Test that a new patchset causes the old to be dequeued" |
| 2516 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2517 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2518 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2519 | M.setMerged() |
| 2520 | |
| 2521 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2522 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2523 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2524 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 2525 | A.addApproval('CRVW', 2) |
| 2526 | B.addApproval('CRVW', 2) |
| 2527 | C.addApproval('CRVW', 2) |
| 2528 | D.addApproval('CRVW', 2) |
| 2529 | |
| 2530 | C.setDependsOn(B, 1) |
| 2531 | B.setDependsOn(A, 1) |
| 2532 | A.setDependsOn(M, 1) |
| 2533 | |
| 2534 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2535 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2536 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2537 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2538 | self.waitUntilSettled() |
| 2539 | |
| 2540 | B.addPatchset() |
| 2541 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2542 | self.waitUntilSettled() |
| 2543 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2544 | self.worker.hold_jobs_in_build = False |
| 2545 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2546 | self.waitUntilSettled() |
| 2547 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2548 | self.assertEqual(A.data['status'], 'MERGED') |
| 2549 | self.assertEqual(A.reported, 2) |
| 2550 | self.assertEqual(B.data['status'], 'NEW') |
| 2551 | self.assertEqual(B.reported, 2) |
| 2552 | self.assertEqual(C.data['status'], 'NEW') |
| 2553 | self.assertEqual(C.reported, 2) |
| 2554 | self.assertEqual(D.data['status'], 'MERGED') |
| 2555 | self.assertEqual(D.reported, 2) |
| 2556 | self.assertEqual(len(self.history), 9) # 3 each for A, B, D. |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2557 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2558 | def test_zuul_url_return(self): |
| 2559 | "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf" |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 2560 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2561 | self.worker.hold_jobs_in_build = True |
| 2562 | |
| 2563 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2564 | A.addApproval('CRVW', 2) |
| 2565 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2566 | self.waitUntilSettled() |
| 2567 | |
| 2568 | self.assertEqual(len(self.builds), 1) |
| 2569 | for build in self.builds: |
| 2570 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 2571 | |
| 2572 | self.worker.hold_jobs_in_build = False |
| 2573 | self.worker.release() |
| 2574 | self.waitUntilSettled() |
| 2575 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2576 | def test_new_patchset_dequeues_old_on_head(self): |
| 2577 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2578 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2579 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2580 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2581 | M.setMerged() |
| 2582 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2583 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2584 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2585 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 2586 | A.addApproval('CRVW', 2) |
| 2587 | B.addApproval('CRVW', 2) |
| 2588 | C.addApproval('CRVW', 2) |
| 2589 | D.addApproval('CRVW', 2) |
| 2590 | |
| 2591 | C.setDependsOn(B, 1) |
| 2592 | B.setDependsOn(A, 1) |
| 2593 | A.setDependsOn(M, 1) |
| 2594 | |
| 2595 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2596 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2597 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2598 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2599 | self.waitUntilSettled() |
| 2600 | |
| 2601 | A.addPatchset() |
| 2602 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2603 | self.waitUntilSettled() |
| 2604 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2605 | self.worker.hold_jobs_in_build = False |
| 2606 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2607 | self.waitUntilSettled() |
| 2608 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2609 | self.assertEqual(A.data['status'], 'NEW') |
| 2610 | self.assertEqual(A.reported, 2) |
| 2611 | self.assertEqual(B.data['status'], 'NEW') |
| 2612 | self.assertEqual(B.reported, 2) |
| 2613 | self.assertEqual(C.data['status'], 'NEW') |
| 2614 | self.assertEqual(C.reported, 2) |
| 2615 | self.assertEqual(D.data['status'], 'MERGED') |
| 2616 | self.assertEqual(D.reported, 2) |
| 2617 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2618 | |
| 2619 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2620 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2621 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2622 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2623 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2624 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2625 | A.addApproval('CRVW', 2) |
| 2626 | B.addApproval('CRVW', 2) |
| 2627 | C.addApproval('CRVW', 2) |
| 2628 | |
| 2629 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2630 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2631 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2632 | self.waitUntilSettled() |
| 2633 | |
| 2634 | B.addPatchset() |
| 2635 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2636 | self.waitUntilSettled() |
| 2637 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2638 | self.worker.hold_jobs_in_build = False |
| 2639 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2640 | self.waitUntilSettled() |
| 2641 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2642 | self.assertEqual(A.data['status'], 'MERGED') |
| 2643 | self.assertEqual(A.reported, 2) |
| 2644 | self.assertEqual(B.data['status'], 'NEW') |
| 2645 | self.assertEqual(B.reported, 2) |
| 2646 | self.assertEqual(C.data['status'], 'MERGED') |
| 2647 | self.assertEqual(C.reported, 2) |
| 2648 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2649 | |
| 2650 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2651 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2652 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2653 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2654 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2655 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2656 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2657 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2658 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2659 | self.waitUntilSettled() |
| 2660 | |
| 2661 | B.addPatchset() |
| 2662 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2663 | self.waitUntilSettled() |
| 2664 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2665 | self.worker.hold_jobs_in_build = False |
| 2666 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2667 | self.waitUntilSettled() |
| 2668 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2669 | self.assertEqual(A.data['status'], 'NEW') |
| 2670 | self.assertEqual(A.reported, 1) |
| 2671 | self.assertEqual(B.data['status'], 'NEW') |
| 2672 | self.assertEqual(B.reported, 1) |
| 2673 | self.assertEqual(C.data['status'], 'NEW') |
| 2674 | self.assertEqual(C.reported, 1) |
| 2675 | self.assertEqual(len(self.history), 10) |
| 2676 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2677 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2678 | def test_noop_job(self): |
| 2679 | "Test that the internal noop job works" |
| 2680 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
| 2681 | A.addApproval('CRVW', 2) |
| 2682 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2683 | self.waitUntilSettled() |
| 2684 | |
| 2685 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2686 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2687 | self.assertEqual(len(self.history), 0) |
| 2688 | self.assertEqual(A.data['status'], 'MERGED') |
| 2689 | self.assertEqual(A.reported, 2) |
| 2690 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2691 | def test_zuul_refs(self): |
| 2692 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2693 | self.worker.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2694 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2695 | M1.setMerged() |
| 2696 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2697 | M2.setMerged() |
| 2698 | |
| 2699 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2700 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2701 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2702 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 2703 | A.addApproval('CRVW', 2) |
| 2704 | B.addApproval('CRVW', 2) |
| 2705 | C.addApproval('CRVW', 2) |
| 2706 | D.addApproval('CRVW', 2) |
| 2707 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2708 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2709 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2710 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2711 | |
| 2712 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2713 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2714 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2715 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2716 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2717 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2718 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2719 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2720 | self.waitUntilSettled() |
| 2721 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2722 | a_zref = b_zref = c_zref = d_zref = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2723 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2724 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 2725 | a_zref = x.parameters['ZUUL_REF'] |
| 2726 | if x.parameters['ZUUL_CHANGE'] == '4': |
| 2727 | b_zref = x.parameters['ZUUL_REF'] |
| 2728 | if x.parameters['ZUUL_CHANGE'] == '5': |
| 2729 | c_zref = x.parameters['ZUUL_REF'] |
| 2730 | if x.parameters['ZUUL_CHANGE'] == '6': |
| 2731 | d_zref = x.parameters['ZUUL_REF'] |
| 2732 | |
| 2733 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2734 | self.assertIsNotNone(a_zref) |
| 2735 | self.assertIsNotNone(b_zref) |
| 2736 | self.assertIsNotNone(c_zref) |
| 2737 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2738 | |
| 2739 | # And they should all be different |
| 2740 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2741 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2742 | |
| 2743 | # a ref should have a, not b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2744 | self.assertTrue(self.ref_has_change(a_zref, A)) |
| 2745 | self.assertFalse(self.ref_has_change(a_zref, B)) |
| 2746 | self.assertFalse(self.ref_has_change(a_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2747 | |
| 2748 | # b ref should have a and b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2749 | self.assertTrue(self.ref_has_change(b_zref, A)) |
| 2750 | self.assertTrue(self.ref_has_change(b_zref, B)) |
| 2751 | self.assertFalse(self.ref_has_change(b_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2752 | |
| 2753 | # c ref should have a and b in 1, c in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2754 | self.assertTrue(self.ref_has_change(c_zref, A)) |
| 2755 | self.assertTrue(self.ref_has_change(c_zref, B)) |
| 2756 | self.assertTrue(self.ref_has_change(c_zref, C)) |
| 2757 | self.assertFalse(self.ref_has_change(c_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2758 | |
| 2759 | # d ref should have a and b in 1, c and d in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2760 | self.assertTrue(self.ref_has_change(d_zref, A)) |
| 2761 | self.assertTrue(self.ref_has_change(d_zref, B)) |
| 2762 | self.assertTrue(self.ref_has_change(d_zref, C)) |
| 2763 | self.assertTrue(self.ref_has_change(d_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2764 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2765 | self.worker.hold_jobs_in_build = False |
| 2766 | self.worker.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2767 | self.waitUntilSettled() |
| 2768 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2769 | self.assertEqual(A.data['status'], 'MERGED') |
| 2770 | self.assertEqual(A.reported, 2) |
| 2771 | self.assertEqual(B.data['status'], 'MERGED') |
| 2772 | self.assertEqual(B.reported, 2) |
| 2773 | self.assertEqual(C.data['status'], 'MERGED') |
| 2774 | self.assertEqual(C.reported, 2) |
| 2775 | self.assertEqual(D.data['status'], 'MERGED') |
| 2776 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2777 | |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 2778 | def test_required_approval_check_and_gate(self): |
| 2779 | "Test required-approval triggers both check and gate" |
| 2780 | self.config.set('zuul', 'layout_config', |
| 2781 | 'tests/fixtures/layout-require-approval.yaml') |
| 2782 | self.sched.reconfigure(self.config) |
| 2783 | self.registerJobs() |
| 2784 | |
| 2785 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2786 | A.addApproval('CRVW', 2) |
| 2787 | # Add a too-old +1 |
| 2788 | A.addApproval('VRFY', 1, granted_on=time.time() - 72 * 60 * 60) |
| 2789 | |
| 2790 | aprv = A.addApproval('APRV', 1) |
| 2791 | self.fake_gerrit.addEvent(aprv) |
| 2792 | self.waitUntilSettled() |
| 2793 | # Should have run a check job |
| 2794 | self.assertEqual(len(self.history), 1) |
| 2795 | self.assertEqual(self.history[0].name, 'project-check') |
| 2796 | |
| 2797 | # Report the result of that check job (overrides previous vrfy) |
| 2798 | # Skynet alert: this should trigger a gate job now that |
| 2799 | # all reqs are met |
| 2800 | self.fake_gerrit.addEvent(A.addApproval('VRFY', 1)) |
| 2801 | self.waitUntilSettled() |
| 2802 | self.assertEqual(len(self.history), 2) |
| 2803 | self.assertEqual(self.history[1].name, 'project-gate') |
| 2804 | |
| 2805 | def test_required_approval_newer(self): |
| 2806 | "Test required-approval newer trigger parameter" |
| 2807 | self.config.set('zuul', 'layout_config', |
| 2808 | 'tests/fixtures/layout-require-approval.yaml') |
| 2809 | self.sched.reconfigure(self.config) |
| 2810 | self.registerJobs() |
| 2811 | |
| 2812 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2813 | A.addApproval('CRVW', 2) |
| 2814 | aprv = A.addApproval('APRV', 1) |
| 2815 | self.fake_gerrit.addEvent(aprv) |
| 2816 | self.waitUntilSettled() |
| 2817 | # No +1 from Jenkins so should not be enqueued |
| 2818 | self.assertEqual(len(self.history), 0) |
| 2819 | |
| 2820 | # Add a too-old +1, should trigger check but not gate |
| 2821 | A.addApproval('VRFY', 1, granted_on=time.time() - 72 * 60 * 60) |
| 2822 | self.fake_gerrit.addEvent(aprv) |
| 2823 | self.waitUntilSettled() |
| 2824 | self.assertEqual(len(self.history), 1) |
| 2825 | self.assertEqual(self.history[0].name, 'project-check') |
| 2826 | |
| 2827 | # Add a recent +1 |
| 2828 | self.fake_gerrit.addEvent(A.addApproval('VRFY', 1)) |
| 2829 | self.fake_gerrit.addEvent(aprv) |
| 2830 | self.waitUntilSettled() |
| 2831 | self.assertEqual(len(self.history), 2) |
| 2832 | self.assertEqual(self.history[1].name, 'project-gate') |
| 2833 | |
| 2834 | def test_required_approval_older(self): |
| 2835 | "Test required-approval older trigger parameter" |
| 2836 | self.config.set('zuul', 'layout_config', |
| 2837 | 'tests/fixtures/layout-require-approval.yaml') |
| 2838 | self.sched.reconfigure(self.config) |
| 2839 | self.registerJobs() |
| 2840 | |
| 2841 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2842 | crvw = A.addApproval('CRVW', 2) |
| 2843 | self.fake_gerrit.addEvent(crvw) |
| 2844 | self.waitUntilSettled() |
| 2845 | # No +1 from Jenkins so should not be enqueued |
| 2846 | self.assertEqual(len(self.history), 0) |
| 2847 | |
| 2848 | # Add an old +1 and trigger check with a comment |
| 2849 | A.addApproval('VRFY', 1, granted_on=time.time() - 72 * 60 * 60) |
| 2850 | self.fake_gerrit.addEvent(crvw) |
| 2851 | self.waitUntilSettled() |
| 2852 | self.assertEqual(len(self.history), 1) |
| 2853 | self.assertEqual(self.history[0].name, 'project-check') |
| 2854 | |
| 2855 | # Add a recent +1 and make sure nothing changes |
| 2856 | A.addApproval('VRFY', 1) |
| 2857 | self.fake_gerrit.addEvent(crvw) |
| 2858 | self.waitUntilSettled() |
| 2859 | self.assertEqual(len(self.history), 1) |
| 2860 | |
| 2861 | # The last thing we did was query a change then do nothing |
| 2862 | # with a pipeline, so it will be in the cache; clean it up so |
| 2863 | # it does not fail the test. |
| 2864 | for pipeline in self.sched.layout.pipelines.values(): |
| 2865 | pipeline.trigger.maintainCache([]) |
| 2866 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2867 | def test_rerun_on_error(self): |
| 2868 | "Test that if a worker fails to run a job, it is run again" |
| 2869 | self.worker.hold_jobs_in_build = True |
| 2870 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2871 | A.addApproval('CRVW', 2) |
| 2872 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2873 | self.waitUntilSettled() |
| 2874 | |
| 2875 | self.builds[0].run_error = True |
| 2876 | self.worker.hold_jobs_in_build = False |
| 2877 | self.worker.release() |
| 2878 | self.waitUntilSettled() |
| 2879 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2880 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2881 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2882 | def test_statsd(self): |
| 2883 | "Test each of the statsd methods used in the scheduler" |
| 2884 | import extras |
| 2885 | statsd = extras.try_import('statsd.statsd') |
| 2886 | statsd.incr('test-incr') |
| 2887 | statsd.timing('test-timing', 3) |
| 2888 | statsd.gauge('test-guage', 12) |
| 2889 | self.assertReportedStat('test-incr', '1|c') |
| 2890 | self.assertReportedStat('test-timing', '3|ms') |
| 2891 | self.assertReportedStat('test-guage', '12|g') |
| 2892 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2893 | def test_stuck_job_cleanup(self): |
| 2894 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2895 | # This job won't be registered at startup because it is not in |
| 2896 | # the standard layout, but we need it to already be registerd |
| 2897 | # for when we reconfigure, as that is when Zuul will attempt |
| 2898 | # to run the new job. |
| 2899 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2900 | self.gearman_server.hold_jobs_in_queue = True |
| 2901 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2902 | A.addApproval('CRVW', 2) |
| 2903 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2904 | self.waitUntilSettled() |
| 2905 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2906 | |
| 2907 | self.config.set('zuul', 'layout_config', |
| 2908 | 'tests/fixtures/layout-no-jobs.yaml') |
| 2909 | self.sched.reconfigure(self.config) |
| 2910 | self.waitUntilSettled() |
| 2911 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2912 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2913 | self.waitUntilSettled() |
| 2914 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2915 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2916 | |
| 2917 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2918 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2919 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2920 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2921 | def test_file_jobs(self): |
| 2922 | "Test that file jobs run only when appropriate" |
| 2923 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2924 | A.addPatchset(['pip-requires']) |
| 2925 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2926 | A.addApproval('CRVW', 2) |
| 2927 | B.addApproval('CRVW', 2) |
| 2928 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2929 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2930 | self.waitUntilSettled() |
| 2931 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2932 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2933 | if x.name == 'project-testfile'] |
| 2934 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2935 | self.assertEqual(len(testfile_jobs), 1) |
| 2936 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2937 | self.assertEqual(A.data['status'], 'MERGED') |
| 2938 | self.assertEqual(A.reported, 2) |
| 2939 | self.assertEqual(B.data['status'], 'MERGED') |
| 2940 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2941 | |
| 2942 | def test_test_config(self): |
| 2943 | "Test that we can test the config" |
| 2944 | sched = zuul.scheduler.Scheduler() |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 2945 | sched.registerTrigger(None, 'gerrit') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2946 | sched.registerTrigger(None, 'timer') |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2947 | sched.testConfig(CONFIG.get('zuul', 'layout_config')) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2948 | |
| 2949 | def test_build_description(self): |
| 2950 | "Test that build descriptions update" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2951 | self.worker.registerFunction('set_description:' + |
| 2952 | self.worker.worker_id) |
| 2953 | |
| 2954 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2955 | A.addApproval('CRVW', 2) |
| 2956 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2957 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2958 | desc = self.history[0].description |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2959 | self.log.debug("Description: %s" % desc) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2960 | self.assertTrue(re.search("Branch.*master", desc)) |
| 2961 | self.assertTrue(re.search("Pipeline.*gate", desc)) |
| 2962 | self.assertTrue(re.search("project-merge.*SUCCESS", desc)) |
| 2963 | self.assertTrue(re.search("project-test1.*SUCCESS", desc)) |
| 2964 | self.assertTrue(re.search("project-test2.*SUCCESS", desc)) |
| 2965 | self.assertTrue(re.search("Reported result.*SUCCESS", desc)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2966 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2967 | def test_queue_precedence(self): |
| 2968 | "Test that queue precedence works" |
| 2969 | |
| 2970 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2971 | self.worker.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2972 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2973 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2974 | A.addApproval('CRVW', 2) |
| 2975 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2976 | |
| 2977 | self.waitUntilSettled() |
| 2978 | self.gearman_server.hold_jobs_in_queue = False |
| 2979 | self.gearman_server.release() |
| 2980 | self.waitUntilSettled() |
| 2981 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2982 | # Run one build at a time to ensure non-race order: |
| 2983 | for x in range(6): |
| 2984 | self.release(self.builds[0]) |
| 2985 | self.waitUntilSettled() |
| 2986 | self.worker.hold_jobs_in_build = False |
| 2987 | self.waitUntilSettled() |
| 2988 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2989 | self.log.debug(self.history) |
| 2990 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2991 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2992 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2993 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2994 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2995 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2996 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 2997 | def test_json_status(self, compressed=False): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2998 | "Test that we can retrieve JSON status info" |
| 2999 | self.worker.hold_jobs_in_build = True |
| 3000 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3001 | A.addApproval('CRVW', 2) |
| 3002 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3003 | self.waitUntilSettled() |
| 3004 | |
| 3005 | port = self.webapp.server.socket.getsockname()[1] |
| 3006 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3007 | req = urllib2.Request("http://localhost:%s/status.json" % port) |
| 3008 | if compressed: |
| 3009 | req.add_header("accept-encoding", "gzip") |
| 3010 | f = urllib2.urlopen(req) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3011 | data = f.read() |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3012 | if compressed: |
| 3013 | gz = gzip.GzipFile(fileobj=StringIO(data)) |
| 3014 | data = gz.read() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3015 | |
| 3016 | self.worker.hold_jobs_in_build = False |
| 3017 | self.worker.release() |
| 3018 | self.waitUntilSettled() |
| 3019 | |
| 3020 | data = json.loads(data) |
| 3021 | status_jobs = set() |
| 3022 | for p in data['pipelines']: |
| 3023 | for q in p['change_queues']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 3024 | if q['dependent']: |
| 3025 | self.assertEqual(q['window'], 20) |
| 3026 | else: |
| 3027 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3028 | for head in q['heads']: |
| 3029 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 3030 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3031 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3032 | for job in change['jobs']: |
| 3033 | status_jobs.add(job['name']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3034 | self.assertIn('project-merge', status_jobs) |
| 3035 | self.assertIn('project-test1', status_jobs) |
| 3036 | self.assertIn('project-test2', status_jobs) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3037 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3038 | def test_json_status_gzip(self): |
| 3039 | self.test_json_status(True) |
| 3040 | |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 3041 | def test_merging_queues(self): |
| 3042 | "Test that transitively-connected change queues are merged" |
| 3043 | self.config.set('zuul', 'layout_config', |
| 3044 | 'tests/fixtures/layout-merge-queues.yaml') |
| 3045 | self.sched.reconfigure(self.config) |
| 3046 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 3047 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 3048 | def test_node_label(self): |
| 3049 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 3050 | self.worker.registerFunction('build:node-project-test1:debian') |
| 3051 | |
| 3052 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 3053 | A.addApproval('CRVW', 2) |
| 3054 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3055 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 3056 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3057 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 3058 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 3059 | 'debian') |
| 3060 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 3061 | |
| 3062 | def test_live_reconfiguration(self): |
| 3063 | "Test that live reconfiguration works" |
| 3064 | self.worker.hold_jobs_in_build = True |
| 3065 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3066 | A.addApproval('CRVW', 2) |
| 3067 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3068 | self.waitUntilSettled() |
| 3069 | |
| 3070 | self.sched.reconfigure(self.config) |
| 3071 | |
| 3072 | self.worker.hold_jobs_in_build = False |
| 3073 | self.worker.release() |
| 3074 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3075 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3076 | 'SUCCESS') |
| 3077 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3078 | 'SUCCESS') |
| 3079 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3080 | 'SUCCESS') |
| 3081 | self.assertEqual(A.data['status'], 'MERGED') |
| 3082 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3083 | |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 3084 | def test_live_reconfiguration_functions(self): |
| 3085 | "Test live reconfiguration with a custom function" |
| 3086 | self.worker.registerFunction('build:node-project-test1:debian') |
| 3087 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 3088 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 3089 | A.addApproval('CRVW', 2) |
| 3090 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3091 | self.waitUntilSettled() |
| 3092 | |
| 3093 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 3094 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 3095 | 'debian') |
| 3096 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 3097 | |
| 3098 | self.config.set('zuul', 'layout_config', |
| 3099 | 'tests/fixtures/layout-live-' |
| 3100 | 'reconfiguration-functions.yaml') |
| 3101 | self.sched.reconfigure(self.config) |
| 3102 | self.worker.build_history = [] |
| 3103 | |
| 3104 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
| 3105 | B.addApproval('CRVW', 2) |
| 3106 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3107 | self.waitUntilSettled() |
| 3108 | |
| 3109 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 3110 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 3111 | 'wheezy') |
| 3112 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 3113 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3114 | def test_delayed_repo_init(self): |
| 3115 | self.config.set('zuul', 'layout_config', |
| 3116 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
| 3117 | self.sched.reconfigure(self.config) |
| 3118 | |
| 3119 | self.init_repo("org/new-project") |
| 3120 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3121 | |
| 3122 | A.addApproval('CRVW', 2) |
| 3123 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3124 | self.waitUntilSettled() |
| 3125 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3126 | 'SUCCESS') |
| 3127 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3128 | 'SUCCESS') |
| 3129 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3130 | 'SUCCESS') |
| 3131 | self.assertEqual(A.data['status'], 'MERGED') |
| 3132 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3133 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3134 | def test_repo_deleted(self): |
| 3135 | self.config.set('zuul', 'layout_config', |
| 3136 | 'tests/fixtures/layout-repo-deleted.yaml') |
| 3137 | self.sched.reconfigure(self.config) |
| 3138 | |
| 3139 | self.init_repo("org/delete-project") |
| 3140 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3141 | |
| 3142 | A.addApproval('CRVW', 2) |
| 3143 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3144 | self.waitUntilSettled() |
| 3145 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3146 | 'SUCCESS') |
| 3147 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3148 | 'SUCCESS') |
| 3149 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3150 | 'SUCCESS') |
| 3151 | self.assertEqual(A.data['status'], 'MERGED') |
| 3152 | self.assertEqual(A.reported, 2) |
| 3153 | |
| 3154 | # Delete org/new-project zuul repo. Should be recloned. |
| 3155 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 3156 | |
| 3157 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3158 | |
| 3159 | B.addApproval('CRVW', 2) |
| 3160 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3161 | self.waitUntilSettled() |
| 3162 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3163 | 'SUCCESS') |
| 3164 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3165 | 'SUCCESS') |
| 3166 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3167 | 'SUCCESS') |
| 3168 | self.assertEqual(B.data['status'], 'MERGED') |
| 3169 | self.assertEqual(B.reported, 2) |
| 3170 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3171 | def test_timer(self): |
| 3172 | "Test that a periodic job is triggered" |
| 3173 | self.worker.hold_jobs_in_build = True |
| 3174 | self.config.set('zuul', 'layout_config', |
| 3175 | 'tests/fixtures/layout-timer.yaml') |
| 3176 | self.sched.reconfigure(self.config) |
| 3177 | self.registerJobs() |
| 3178 | |
| 3179 | start = time.time() |
| 3180 | failed = True |
| 3181 | while ((time.time() - start) < 30): |
| 3182 | if len(self.builds) == 2: |
| 3183 | failed = False |
| 3184 | break |
| 3185 | else: |
| 3186 | time.sleep(1) |
| 3187 | |
| 3188 | if failed: |
| 3189 | raise Exception("Expected jobs never ran") |
| 3190 | |
| 3191 | self.waitUntilSettled() |
| 3192 | port = self.webapp.server.socket.getsockname()[1] |
| 3193 | |
| 3194 | f = urllib.urlopen("http://localhost:%s/status.json" % port) |
| 3195 | data = f.read() |
| 3196 | |
| 3197 | self.worker.hold_jobs_in_build = False |
| 3198 | self.worker.release() |
| 3199 | self.waitUntilSettled() |
| 3200 | |
| 3201 | self.assertEqual(self.getJobFromHistory( |
| 3202 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3203 | self.assertEqual(self.getJobFromHistory( |
| 3204 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3205 | |
| 3206 | data = json.loads(data) |
| 3207 | status_jobs = set() |
| 3208 | for p in data['pipelines']: |
| 3209 | for q in p['change_queues']: |
| 3210 | for head in q['heads']: |
| 3211 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 3212 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3213 | for job in change['jobs']: |
| 3214 | status_jobs.add(job['name']) |
| 3215 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 3216 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3217 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3218 | def test_idle(self): |
| 3219 | "Test that frequent periodic jobs work" |
| 3220 | self.worker.hold_jobs_in_build = True |
| 3221 | self.config.set('zuul', 'layout_config', |
| 3222 | 'tests/fixtures/layout-idle.yaml') |
| 3223 | self.sched.reconfigure(self.config) |
| 3224 | self.registerJobs() |
| 3225 | |
| 3226 | # The pipeline triggers every second, so we should have seen |
| 3227 | # several by now. |
| 3228 | time.sleep(5) |
| 3229 | self.waitUntilSettled() |
| 3230 | self.assertEqual(len(self.builds), 2) |
| 3231 | self.worker.release('.*') |
| 3232 | self.waitUntilSettled() |
| 3233 | self.assertEqual(len(self.builds), 0) |
| 3234 | self.assertEqual(len(self.history), 2) |
| 3235 | |
| 3236 | time.sleep(5) |
| 3237 | self.waitUntilSettled() |
| 3238 | self.assertEqual(len(self.builds), 2) |
| 3239 | self.assertEqual(len(self.history), 2) |
| 3240 | self.worker.release('.*') |
| 3241 | self.waitUntilSettled() |
| 3242 | self.assertEqual(len(self.builds), 0) |
| 3243 | self.assertEqual(len(self.history), 4) |
| 3244 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3245 | def test_check_smtp_pool(self): |
| 3246 | self.config.set('zuul', 'layout_config', |
| 3247 | 'tests/fixtures/layout-smtp.yaml') |
| 3248 | self.sched.reconfigure(self.config) |
| 3249 | |
| 3250 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3251 | self.waitUntilSettled() |
| 3252 | |
| 3253 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3254 | self.waitUntilSettled() |
| 3255 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3256 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3257 | |
| 3258 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3259 | # work on the knowledge of what the first message should be as |
| 3260 | # it is only configured to go to SMTP. |
| 3261 | |
| 3262 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3263 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3264 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3265 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3266 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3267 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3268 | |
| 3269 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3270 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3271 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3272 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3273 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3274 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3275 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3276 | def test_timer_smtp(self): |
| 3277 | "Test that a periodic job is triggered" |
| 3278 | self.config.set('zuul', 'layout_config', |
| 3279 | 'tests/fixtures/layout-timer-smtp.yaml') |
| 3280 | self.sched.reconfigure(self.config) |
| 3281 | self.registerJobs() |
| 3282 | |
| 3283 | start = time.time() |
| 3284 | failed = True |
| 3285 | while ((time.time() - start) < 30): |
| 3286 | if len(self.history) == 2: |
| 3287 | failed = False |
| 3288 | break |
| 3289 | else: |
| 3290 | time.sleep(1) |
| 3291 | |
| 3292 | if failed: |
| 3293 | raise Exception("Expected jobs never ran") |
| 3294 | |
| 3295 | self.waitUntilSettled() |
| 3296 | |
| 3297 | self.assertEqual(self.getJobFromHistory( |
| 3298 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3299 | self.assertEqual(self.getJobFromHistory( |
| 3300 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3301 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3302 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3303 | |
| 3304 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3305 | # work on the knowledge of what the first message should be as |
| 3306 | # it is only configured to go to SMTP. |
| 3307 | |
| 3308 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3309 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3310 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3311 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3312 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3313 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3314 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3315 | def test_client_enqueue(self): |
| 3316 | "Test that the RPC client can enqueue a change" |
| 3317 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3318 | A.addApproval('CRVW', 2) |
| 3319 | A.addApproval('APRV', 1) |
| 3320 | |
| 3321 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3322 | self.gearman_server.port) |
| 3323 | r = client.enqueue(pipeline='gate', |
| 3324 | project='org/project', |
| 3325 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3326 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3327 | self.waitUntilSettled() |
| 3328 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3329 | 'SUCCESS') |
| 3330 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3331 | 'SUCCESS') |
| 3332 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3333 | 'SUCCESS') |
| 3334 | self.assertEqual(A.data['status'], 'MERGED') |
| 3335 | self.assertEqual(A.reported, 2) |
| 3336 | self.assertEqual(r, True) |
| 3337 | |
| 3338 | def test_client_enqueue_negative(self): |
| 3339 | "Test that the RPC client returns errors" |
| 3340 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3341 | self.gearman_server.port) |
| 3342 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3343 | "Invalid project"): |
| 3344 | r = client.enqueue(pipeline='gate', |
| 3345 | project='project-does-not-exist', |
| 3346 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3347 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3348 | client.shutdown() |
| 3349 | self.assertEqual(r, False) |
| 3350 | |
| 3351 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3352 | "Invalid pipeline"): |
| 3353 | r = client.enqueue(pipeline='pipeline-does-not-exist', |
| 3354 | project='org/project', |
| 3355 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3356 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3357 | client.shutdown() |
| 3358 | self.assertEqual(r, False) |
| 3359 | |
| 3360 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3361 | "Invalid trigger"): |
| 3362 | r = client.enqueue(pipeline='gate', |
| 3363 | project='org/project', |
| 3364 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3365 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3366 | client.shutdown() |
| 3367 | self.assertEqual(r, False) |
| 3368 | |
| 3369 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3370 | "Invalid change"): |
| 3371 | r = client.enqueue(pipeline='gate', |
| 3372 | project='org/project', |
| 3373 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3374 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3375 | client.shutdown() |
| 3376 | self.assertEqual(r, False) |
| 3377 | |
| 3378 | self.waitUntilSettled() |
| 3379 | self.assertEqual(len(self.history), 0) |
| 3380 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3381 | |
| 3382 | def test_client_promote(self): |
| 3383 | "Test that the RPC client can promote a change" |
| 3384 | self.worker.hold_jobs_in_build = True |
| 3385 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3386 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3387 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3388 | A.addApproval('CRVW', 2) |
| 3389 | B.addApproval('CRVW', 2) |
| 3390 | C.addApproval('CRVW', 2) |
| 3391 | |
| 3392 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3393 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3394 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3395 | |
| 3396 | self.waitUntilSettled() |
| 3397 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3398 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3399 | enqueue_times = {} |
| 3400 | for item in items: |
| 3401 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3402 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3403 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3404 | self.gearman_server.port) |
| 3405 | r = client.promote(pipeline='gate', |
| 3406 | change_ids=['2,1', '3,1']) |
| 3407 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3408 | # ensure that enqueue times are durable |
| 3409 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3410 | for item in items: |
| 3411 | self.assertEqual( |
| 3412 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3413 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3414 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3415 | self.worker.release('.*-merge') |
| 3416 | self.waitUntilSettled() |
| 3417 | self.worker.release('.*-merge') |
| 3418 | self.waitUntilSettled() |
| 3419 | self.worker.release('.*-merge') |
| 3420 | self.waitUntilSettled() |
| 3421 | |
| 3422 | self.assertEqual(len(self.builds), 6) |
| 3423 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3424 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3425 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3426 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3427 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3428 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3429 | |
| 3430 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3431 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3432 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3433 | |
| 3434 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3435 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3436 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3437 | |
| 3438 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3439 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3440 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3441 | |
| 3442 | self.worker.release() |
| 3443 | self.waitUntilSettled() |
| 3444 | |
| 3445 | self.assertEqual(A.data['status'], 'MERGED') |
| 3446 | self.assertEqual(A.reported, 2) |
| 3447 | self.assertEqual(B.data['status'], 'MERGED') |
| 3448 | self.assertEqual(B.reported, 2) |
| 3449 | self.assertEqual(C.data['status'], 'MERGED') |
| 3450 | self.assertEqual(C.reported, 2) |
| 3451 | |
| 3452 | client.shutdown() |
| 3453 | self.assertEqual(r, True) |
| 3454 | |
| 3455 | def test_client_promote_dependent(self): |
| 3456 | "Test that the RPC client can promote a dependent change" |
| 3457 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3458 | # A -> C (depends on B) -> B |
| 3459 | self.worker.hold_jobs_in_build = True |
| 3460 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3461 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3462 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3463 | |
| 3464 | C.setDependsOn(B, 1) |
| 3465 | |
| 3466 | A.addApproval('CRVW', 2) |
| 3467 | B.addApproval('CRVW', 2) |
| 3468 | C.addApproval('CRVW', 2) |
| 3469 | |
| 3470 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3471 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3472 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3473 | |
| 3474 | self.waitUntilSettled() |
| 3475 | |
| 3476 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3477 | self.gearman_server.port) |
| 3478 | r = client.promote(pipeline='gate', |
| 3479 | change_ids=['3,1']) |
| 3480 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3481 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3482 | self.worker.release('.*-merge') |
| 3483 | self.waitUntilSettled() |
| 3484 | self.worker.release('.*-merge') |
| 3485 | self.waitUntilSettled() |
| 3486 | self.worker.release('.*-merge') |
| 3487 | self.waitUntilSettled() |
| 3488 | |
| 3489 | self.assertEqual(len(self.builds), 6) |
| 3490 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3491 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3492 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3493 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3494 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3495 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3496 | |
| 3497 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3498 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3499 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3500 | |
| 3501 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3502 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3503 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3504 | |
| 3505 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3506 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3507 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3508 | |
| 3509 | self.worker.release() |
| 3510 | self.waitUntilSettled() |
| 3511 | |
| 3512 | self.assertEqual(A.data['status'], 'MERGED') |
| 3513 | self.assertEqual(A.reported, 2) |
| 3514 | self.assertEqual(B.data['status'], 'MERGED') |
| 3515 | self.assertEqual(B.reported, 2) |
| 3516 | self.assertEqual(C.data['status'], 'MERGED') |
| 3517 | self.assertEqual(C.reported, 2) |
| 3518 | |
| 3519 | client.shutdown() |
| 3520 | self.assertEqual(r, True) |
| 3521 | |
| 3522 | def test_client_promote_negative(self): |
| 3523 | "Test that the RPC client returns errors for promotion" |
| 3524 | self.worker.hold_jobs_in_build = True |
| 3525 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3526 | A.addApproval('CRVW', 2) |
| 3527 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3528 | self.waitUntilSettled() |
| 3529 | |
| 3530 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3531 | self.gearman_server.port) |
| 3532 | |
| 3533 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3534 | r = client.promote(pipeline='nonexistent', |
| 3535 | change_ids=['2,1', '3,1']) |
| 3536 | client.shutdown() |
| 3537 | self.assertEqual(r, False) |
| 3538 | |
| 3539 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3540 | r = client.promote(pipeline='gate', |
| 3541 | change_ids=['4,1']) |
| 3542 | client.shutdown() |
| 3543 | self.assertEqual(r, False) |
| 3544 | |
| 3545 | self.worker.hold_jobs_in_build = False |
| 3546 | self.worker.release() |
| 3547 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3548 | |
| 3549 | def test_queue_rate_limiting(self): |
| 3550 | "Test that DependentPipelines are rate limited with dep across window" |
| 3551 | self.config.set('zuul', 'layout_config', |
| 3552 | 'tests/fixtures/layout-rate-limit.yaml') |
| 3553 | self.sched.reconfigure(self.config) |
| 3554 | self.worker.hold_jobs_in_build = True |
| 3555 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3556 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3557 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3558 | |
| 3559 | C.setDependsOn(B, 1) |
| 3560 | self.worker.addFailTest('project-test1', A) |
| 3561 | |
| 3562 | A.addApproval('CRVW', 2) |
| 3563 | B.addApproval('CRVW', 2) |
| 3564 | C.addApproval('CRVW', 2) |
| 3565 | |
| 3566 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3567 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3568 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3569 | self.waitUntilSettled() |
| 3570 | |
| 3571 | # Only A and B will have their merge jobs queued because |
| 3572 | # window is 2. |
| 3573 | self.assertEqual(len(self.builds), 2) |
| 3574 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3575 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3576 | |
| 3577 | self.worker.release('.*-merge') |
| 3578 | self.waitUntilSettled() |
| 3579 | self.worker.release('.*-merge') |
| 3580 | self.waitUntilSettled() |
| 3581 | |
| 3582 | # Only A and B will have their test jobs queued because |
| 3583 | # window is 2. |
| 3584 | self.assertEqual(len(self.builds), 4) |
| 3585 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3586 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3587 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3588 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3589 | |
| 3590 | self.worker.release('project-.*') |
| 3591 | self.waitUntilSettled() |
| 3592 | |
| 3593 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3594 | # A failed so window is reduced by 1 to 1. |
| 3595 | self.assertEqual(queue.window, 1) |
| 3596 | self.assertEqual(queue.window_floor, 1) |
| 3597 | self.assertEqual(A.data['status'], 'NEW') |
| 3598 | |
| 3599 | # Gate is reset and only B's merge job is queued because |
| 3600 | # window shrunk to 1. |
| 3601 | self.assertEqual(len(self.builds), 1) |
| 3602 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3603 | |
| 3604 | self.worker.release('.*-merge') |
| 3605 | self.waitUntilSettled() |
| 3606 | |
| 3607 | # Only B's test jobs are queued because window is still 1. |
| 3608 | self.assertEqual(len(self.builds), 2) |
| 3609 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3610 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3611 | |
| 3612 | self.worker.release('project-.*') |
| 3613 | self.waitUntilSettled() |
| 3614 | |
| 3615 | # B was successfully merged so window is increased to 2. |
| 3616 | self.assertEqual(queue.window, 2) |
| 3617 | self.assertEqual(queue.window_floor, 1) |
| 3618 | self.assertEqual(B.data['status'], 'MERGED') |
| 3619 | |
| 3620 | # Only C is left and its merge job is queued. |
| 3621 | self.assertEqual(len(self.builds), 1) |
| 3622 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3623 | |
| 3624 | self.worker.release('.*-merge') |
| 3625 | self.waitUntilSettled() |
| 3626 | |
| 3627 | # After successful merge job the test jobs for C are queued. |
| 3628 | self.assertEqual(len(self.builds), 2) |
| 3629 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3630 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3631 | |
| 3632 | self.worker.release('project-.*') |
| 3633 | self.waitUntilSettled() |
| 3634 | |
| 3635 | # C successfully merged so window is bumped to 3. |
| 3636 | self.assertEqual(queue.window, 3) |
| 3637 | self.assertEqual(queue.window_floor, 1) |
| 3638 | self.assertEqual(C.data['status'], 'MERGED') |
| 3639 | |
| 3640 | def test_queue_rate_limiting_dependent(self): |
| 3641 | "Test that DependentPipelines are rate limited with dep in window" |
| 3642 | self.config.set('zuul', 'layout_config', |
| 3643 | 'tests/fixtures/layout-rate-limit.yaml') |
| 3644 | self.sched.reconfigure(self.config) |
| 3645 | self.worker.hold_jobs_in_build = True |
| 3646 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3647 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3648 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3649 | |
| 3650 | B.setDependsOn(A, 1) |
| 3651 | |
| 3652 | self.worker.addFailTest('project-test1', A) |
| 3653 | |
| 3654 | A.addApproval('CRVW', 2) |
| 3655 | B.addApproval('CRVW', 2) |
| 3656 | C.addApproval('CRVW', 2) |
| 3657 | |
| 3658 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3659 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3660 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3661 | self.waitUntilSettled() |
| 3662 | |
| 3663 | # Only A and B will have their merge jobs queued because |
| 3664 | # window is 2. |
| 3665 | self.assertEqual(len(self.builds), 2) |
| 3666 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3667 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3668 | |
| 3669 | self.worker.release('.*-merge') |
| 3670 | self.waitUntilSettled() |
| 3671 | self.worker.release('.*-merge') |
| 3672 | self.waitUntilSettled() |
| 3673 | |
| 3674 | # Only A and B will have their test jobs queued because |
| 3675 | # window is 2. |
| 3676 | self.assertEqual(len(self.builds), 4) |
| 3677 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3678 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3679 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3680 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3681 | |
| 3682 | self.worker.release('project-.*') |
| 3683 | self.waitUntilSettled() |
| 3684 | |
| 3685 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3686 | # A failed so window is reduced by 1 to 1. |
| 3687 | self.assertEqual(queue.window, 1) |
| 3688 | self.assertEqual(queue.window_floor, 1) |
| 3689 | self.assertEqual(A.data['status'], 'NEW') |
| 3690 | self.assertEqual(B.data['status'], 'NEW') |
| 3691 | |
| 3692 | # Gate is reset and only C's merge job is queued because |
| 3693 | # window shrunk to 1 and A and B were dequeued. |
| 3694 | self.assertEqual(len(self.builds), 1) |
| 3695 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3696 | |
| 3697 | self.worker.release('.*-merge') |
| 3698 | self.waitUntilSettled() |
| 3699 | |
| 3700 | # Only C's test jobs are queued because window is still 1. |
| 3701 | self.assertEqual(len(self.builds), 2) |
| 3702 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3703 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3704 | |
| 3705 | self.worker.release('project-.*') |
| 3706 | self.waitUntilSettled() |
| 3707 | |
| 3708 | # C was successfully merged so window is increased to 2. |
| 3709 | self.assertEqual(queue.window, 2) |
| 3710 | self.assertEqual(queue.window_floor, 1) |
| 3711 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3712 | |
| 3713 | def test_worker_update_metadata(self): |
| 3714 | "Test if a worker can send back metadata about itself" |
| 3715 | self.worker.hold_jobs_in_build = True |
| 3716 | |
| 3717 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3718 | A.addApproval('CRVW', 2) |
| 3719 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3720 | self.waitUntilSettled() |
| 3721 | |
| 3722 | self.assertEqual(len(self.launcher.builds), 1) |
| 3723 | |
| 3724 | self.log.debug('Current builds:') |
| 3725 | self.log.debug(self.launcher.builds) |
| 3726 | |
| 3727 | start = time.time() |
| 3728 | while True: |
| 3729 | if time.time() - start > 10: |
| 3730 | raise Exception("Timeout waiting for gearman server to report " |
| 3731 | + "back to the client") |
| 3732 | build = self.launcher.builds.values()[0] |
| 3733 | if build.worker.name == "My Worker": |
| 3734 | break |
| 3735 | else: |
| 3736 | time.sleep(0) |
| 3737 | |
| 3738 | self.log.debug(build) |
| 3739 | self.assertEqual("My Worker", build.worker.name) |
| 3740 | self.assertEqual("localhost", build.worker.hostname) |
| 3741 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3742 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3743 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3744 | self.assertEqual("v1.1", build.worker.version) |
| 3745 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3746 | |
| 3747 | self.worker.hold_jobs_in_build = False |
| 3748 | self.worker.release() |
| 3749 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3750 | |
| 3751 | def test_footer_message(self): |
| 3752 | "Test a pipeline's footer message is correctly added to the report." |
| 3753 | self.config.set('zuul', 'layout_config', |
| 3754 | 'tests/fixtures/layout-footer-message.yaml') |
| 3755 | self.sched.reconfigure(self.config) |
| 3756 | self.registerJobs() |
| 3757 | |
| 3758 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3759 | A.addApproval('CRVW', 2) |
| 3760 | self.worker.addFailTest('test1', A) |
| 3761 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3762 | self.waitUntilSettled() |
| 3763 | |
| 3764 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3765 | B.addApproval('CRVW', 2) |
| 3766 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3767 | self.waitUntilSettled() |
| 3768 | |
| 3769 | self.assertEqual(2, len(self.smtp_messages)) |
| 3770 | |
| 3771 | failure_body = """\ |
| 3772 | Build failed. For information on how to proceed, see \ |
| 3773 | http://wiki.example.org/Test_Failures |
| 3774 | |
| 3775 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3776 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3777 | |
| 3778 | For CI problems and help debugging, contact ci@example.org""" |
| 3779 | |
| 3780 | success_body = """\ |
| 3781 | Build succeeded. |
| 3782 | |
| 3783 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3784 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3785 | |
| 3786 | For CI problems and help debugging, contact ci@example.org""" |
| 3787 | |
| 3788 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3789 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3790 | |
| 3791 | def test_merge_failure_reporters(self): |
| 3792 | """Check that the config is set up correctly""" |
| 3793 | |
| 3794 | self.config.set('zuul', 'layout_config', |
| 3795 | 'tests/fixtures/layout-merge-failure.yaml') |
| 3796 | self.sched.reconfigure(self.config) |
| 3797 | self.registerJobs() |
| 3798 | |
| 3799 | self.assertEqual( |
| 3800 | "Merge Failed.\n\nThis change was unable to be automatically " |
| 3801 | "merged with the current state of the repository. Please rebase " |
| 3802 | "your change and upload a new patchset.", |
| 3803 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3804 | self.assertEqual( |
| 3805 | "The merge failed! For more information...", |
| 3806 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3807 | |
| 3808 | self.assertEqual( |
| 3809 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3810 | self.assertEqual( |
| 3811 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3812 | |
| 3813 | self.assertTrue(isinstance( |
| 3814 | self.sched.layout.pipelines['check'].merge_failure_actions[0]. |
| 3815 | reporter, zuul.reporter.gerrit.Reporter)) |
| 3816 | |
| 3817 | self.assertTrue( |
| 3818 | ( |
| 3819 | isinstance(self.sched.layout.pipelines['gate']. |
| 3820 | merge_failure_actions[0].reporter, |
| 3821 | zuul.reporter.smtp.Reporter) and |
| 3822 | isinstance(self.sched.layout.pipelines['gate']. |
| 3823 | merge_failure_actions[1].reporter, |
| 3824 | zuul.reporter.gerrit.Reporter) |
| 3825 | ) or ( |
| 3826 | isinstance(self.sched.layout.pipelines['gate']. |
| 3827 | merge_failure_actions[0].reporter, |
| 3828 | zuul.reporter.gerrit.Reporter) and |
| 3829 | isinstance(self.sched.layout.pipelines['gate']. |
| 3830 | merge_failure_actions[1].reporter, |
| 3831 | zuul.reporter.smtp.Reporter) |
| 3832 | ) |
| 3833 | ) |
| 3834 | |
| 3835 | def test_merge_failure_reports(self): |
| 3836 | """Check that when a change fails to merge the correct message is sent |
| 3837 | to the correct reporter""" |
| 3838 | self.config.set('zuul', 'layout_config', |
| 3839 | 'tests/fixtures/layout-merge-failure.yaml') |
| 3840 | self.sched.reconfigure(self.config) |
| 3841 | self.registerJobs() |
| 3842 | |
| 3843 | # Check a test failure isn't reported to SMTP |
| 3844 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3845 | A.addApproval('CRVW', 2) |
| 3846 | self.worker.addFailTest('project-test1', A) |
| 3847 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3848 | self.waitUntilSettled() |
| 3849 | |
| 3850 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3851 | self.assertEqual(0, len(self.smtp_messages)) |
| 3852 | |
| 3853 | # Check a merge failure is reported to SMTP |
| 3854 | # B should be merged, but C will conflict with B |
| 3855 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3856 | B.addPatchset(['conflict']) |
| 3857 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3858 | C.addPatchset(['conflict']) |
| 3859 | B.addApproval('CRVW', 2) |
| 3860 | C.addApproval('CRVW', 2) |
| 3861 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3862 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3863 | self.waitUntilSettled() |
| 3864 | |
| 3865 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3866 | self.assertEqual(1, len(self.smtp_messages)) |
| 3867 | self.assertEqual('The merge failed! For more information...', |
| 3868 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3869 | |
| 3870 | def test_swift_instructions(self): |
| 3871 | "Test that the correct swift instructions are sent to the workers" |
| 3872 | self.config.set('zuul', 'layout_config', |
| 3873 | 'tests/fixtures/layout-swift.yaml') |
| 3874 | self.sched.reconfigure(self.config) |
| 3875 | self.registerJobs() |
| 3876 | |
| 3877 | self.worker.hold_jobs_in_build = True |
| 3878 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3879 | |
| 3880 | A.addApproval('CRVW', 2) |
| 3881 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3882 | self.waitUntilSettled() |
| 3883 | |
| 3884 | self.assertEqual( |
| 3885 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3886 | "gate/test-merge/", |
| 3887 | self.builds[0].parameters['SWIFT_logs_URL'][:-32]) |
| 3888 | self.assertEqual(5, |
| 3889 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3890 | split('\n'))) |
| 3891 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3892 | |
| 3893 | self.assertEqual( |
| 3894 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3895 | "gate/test-test/", |
| 3896 | self.builds[1].parameters['SWIFT_logs_URL'][:-32]) |
| 3897 | self.assertEqual(5, |
| 3898 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3899 | split('\n'))) |
| 3900 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3901 | |
| 3902 | self.assertEqual( |
| 3903 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3904 | "gate/test-test/", |
| 3905 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-32]) |
| 3906 | self.assertEqual(5, |
| 3907 | len(self.builds[1]. |
| 3908 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3909 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3910 | |
| 3911 | self.worker.hold_jobs_in_build = False |
| 3912 | self.worker.release() |
| 3913 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3914 | |
| 3915 | def test_client_get_running_jobs(self): |
| 3916 | "Test that the RPC client can get a list of running jobs" |
| 3917 | self.worker.hold_jobs_in_build = True |
| 3918 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3919 | A.addApproval('CRVW', 2) |
| 3920 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3921 | self.waitUntilSettled() |
| 3922 | |
| 3923 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3924 | self.gearman_server.port) |
| 3925 | |
| 3926 | # Wait for gearman server to send the initial workData back to zuul |
| 3927 | start = time.time() |
| 3928 | while True: |
| 3929 | if time.time() - start > 10: |
| 3930 | raise Exception("Timeout waiting for gearman server to report " |
| 3931 | + "back to the client") |
| 3932 | build = self.launcher.builds.values()[0] |
| 3933 | if build.worker.name == "My Worker": |
| 3934 | break |
| 3935 | else: |
| 3936 | time.sleep(0) |
| 3937 | |
| 3938 | running_items = client.get_running_jobs() |
| 3939 | |
| 3940 | self.assertEqual(1, len(running_items)) |
| 3941 | running_item = running_items[0] |
| 3942 | self.assertEqual([], running_item['failing_reasons']) |
| 3943 | self.assertEqual([], running_item['items_behind']) |
| 3944 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3945 | self.assertEqual(None, running_item['item_ahead']) |
| 3946 | self.assertEqual('org/project', running_item['project']) |
| 3947 | self.assertEqual(None, running_item['remaining_time']) |
| 3948 | self.assertEqual(True, running_item['active']) |
| 3949 | self.assertEqual('1,1', running_item['id']) |
| 3950 | |
| 3951 | self.assertEqual(3, len(running_item['jobs'])) |
| 3952 | for job in running_item['jobs']: |
| 3953 | if job['name'] == 'project-merge': |
| 3954 | self.assertEqual('project-merge', job['name']) |
| 3955 | self.assertEqual('gate', job['pipeline']) |
| 3956 | self.assertEqual(False, job['retry']) |
| 3957 | self.assertEqual(13, len(job['parameters'])) |
| 3958 | self.assertEqual('https://server/job/project-merge/0/', |
| 3959 | job['url']) |
| 3960 | self.assertEqual(7, len(job['worker'])) |
| 3961 | self.assertEqual(False, job['canceled']) |
| 3962 | self.assertEqual(True, job['voting']) |
| 3963 | self.assertEqual(None, job['result']) |
| 3964 | self.assertEqual('gate', job['pipeline']) |
| 3965 | break |
| 3966 | |
| 3967 | self.worker.hold_jobs_in_build = False |
| 3968 | self.worker.release() |
| 3969 | self.waitUntilSettled() |
| 3970 | |
| 3971 | running_items = client.get_running_jobs() |
| 3972 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3973 | |
| 3974 | def test_nonvoting_pipeline(self): |
| 3975 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3976 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame^] | 3977 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3978 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3979 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3980 | self.waitUntilSettled() |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame^] | 3981 | self.assertEqual( |
| 3982 | self.getJobFromHistory('experimental-project-test').result, |
| 3983 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3984 | self.assertEqual(A.reported, 1) |