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 | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2967 | def test_queue_names(self): |
| 2968 | "Test shared change queue names" |
| 2969 | project1 = self.sched.layout.projects['org/project1'] |
| 2970 | project2 = self.sched.layout.projects['org/project2'] |
| 2971 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2972 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2973 | self.assertEqual(q1.name, 'integration') |
| 2974 | self.assertEqual(q2.name, 'integration') |
| 2975 | |
| 2976 | self.config.set('zuul', 'layout_config', |
| 2977 | 'tests/fixtures/layout-bad-queue.yaml') |
| 2978 | with testtools.ExpectedException( |
| 2979 | Exception, "More than one name assigned to change queue"): |
| 2980 | self.sched.reconfigure(self.config) |
| 2981 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2982 | def test_queue_precedence(self): |
| 2983 | "Test that queue precedence works" |
| 2984 | |
| 2985 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2986 | self.worker.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2987 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2988 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2989 | A.addApproval('CRVW', 2) |
| 2990 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2991 | |
| 2992 | self.waitUntilSettled() |
| 2993 | self.gearman_server.hold_jobs_in_queue = False |
| 2994 | self.gearman_server.release() |
| 2995 | self.waitUntilSettled() |
| 2996 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2997 | # Run one build at a time to ensure non-race order: |
| 2998 | for x in range(6): |
| 2999 | self.release(self.builds[0]) |
| 3000 | self.waitUntilSettled() |
| 3001 | self.worker.hold_jobs_in_build = False |
| 3002 | self.waitUntilSettled() |
| 3003 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 3004 | self.log.debug(self.history) |
| 3005 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 3006 | self.assertEqual(self.history[1].pipeline, 'check') |
| 3007 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 3008 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 3009 | self.assertEqual(self.history[4].pipeline, 'check') |
| 3010 | self.assertEqual(self.history[5].pipeline, 'check') |
| 3011 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3012 | def test_json_status(self, compressed=False): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3013 | "Test that we can retrieve JSON status info" |
| 3014 | self.worker.hold_jobs_in_build = True |
| 3015 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3016 | A.addApproval('CRVW', 2) |
| 3017 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3018 | self.waitUntilSettled() |
| 3019 | |
| 3020 | port = self.webapp.server.socket.getsockname()[1] |
| 3021 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3022 | req = urllib2.Request("http://localhost:%s/status.json" % port) |
| 3023 | if compressed: |
| 3024 | req.add_header("accept-encoding", "gzip") |
| 3025 | f = urllib2.urlopen(req) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3026 | data = f.read() |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3027 | if compressed: |
| 3028 | gz = gzip.GzipFile(fileobj=StringIO(data)) |
| 3029 | data = gz.read() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3030 | |
| 3031 | self.worker.hold_jobs_in_build = False |
| 3032 | self.worker.release() |
| 3033 | self.waitUntilSettled() |
| 3034 | |
| 3035 | data = json.loads(data) |
| 3036 | status_jobs = set() |
| 3037 | for p in data['pipelines']: |
| 3038 | for q in p['change_queues']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 3039 | if q['dependent']: |
| 3040 | self.assertEqual(q['window'], 20) |
| 3041 | else: |
| 3042 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3043 | for head in q['heads']: |
| 3044 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 3045 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3046 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3047 | for job in change['jobs']: |
| 3048 | status_jobs.add(job['name']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3049 | self.assertIn('project-merge', status_jobs) |
| 3050 | self.assertIn('project-test1', status_jobs) |
| 3051 | self.assertIn('project-test2', status_jobs) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 3052 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 3053 | def test_json_status_gzip(self): |
| 3054 | self.test_json_status(True) |
| 3055 | |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 3056 | def test_merging_queues(self): |
| 3057 | "Test that transitively-connected change queues are merged" |
| 3058 | self.config.set('zuul', 'layout_config', |
| 3059 | 'tests/fixtures/layout-merge-queues.yaml') |
| 3060 | self.sched.reconfigure(self.config) |
| 3061 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 3062 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 3063 | def test_node_label(self): |
| 3064 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 3065 | self.worker.registerFunction('build:node-project-test1:debian') |
| 3066 | |
| 3067 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 3068 | A.addApproval('CRVW', 2) |
| 3069 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3070 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 3071 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3072 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 3073 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 3074 | 'debian') |
| 3075 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 3076 | |
| 3077 | def test_live_reconfiguration(self): |
| 3078 | "Test that live reconfiguration works" |
| 3079 | self.worker.hold_jobs_in_build = True |
| 3080 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3081 | A.addApproval('CRVW', 2) |
| 3082 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3083 | self.waitUntilSettled() |
| 3084 | |
| 3085 | self.sched.reconfigure(self.config) |
| 3086 | |
| 3087 | self.worker.hold_jobs_in_build = False |
| 3088 | self.worker.release() |
| 3089 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 3090 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3091 | 'SUCCESS') |
| 3092 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3093 | 'SUCCESS') |
| 3094 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3095 | 'SUCCESS') |
| 3096 | self.assertEqual(A.data['status'], 'MERGED') |
| 3097 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3098 | |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 3099 | def test_live_reconfiguration_functions(self): |
| 3100 | "Test live reconfiguration with a custom function" |
| 3101 | self.worker.registerFunction('build:node-project-test1:debian') |
| 3102 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 3103 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 3104 | A.addApproval('CRVW', 2) |
| 3105 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3106 | self.waitUntilSettled() |
| 3107 | |
| 3108 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 3109 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 3110 | 'debian') |
| 3111 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 3112 | |
| 3113 | self.config.set('zuul', 'layout_config', |
| 3114 | 'tests/fixtures/layout-live-' |
| 3115 | 'reconfiguration-functions.yaml') |
| 3116 | self.sched.reconfigure(self.config) |
| 3117 | self.worker.build_history = [] |
| 3118 | |
| 3119 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
| 3120 | B.addApproval('CRVW', 2) |
| 3121 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3122 | self.waitUntilSettled() |
| 3123 | |
| 3124 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 3125 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 3126 | 'wheezy') |
| 3127 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 3128 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3129 | def test_delayed_repo_init(self): |
| 3130 | self.config.set('zuul', 'layout_config', |
| 3131 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
| 3132 | self.sched.reconfigure(self.config) |
| 3133 | |
| 3134 | self.init_repo("org/new-project") |
| 3135 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3136 | |
| 3137 | A.addApproval('CRVW', 2) |
| 3138 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3139 | self.waitUntilSettled() |
| 3140 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3141 | 'SUCCESS') |
| 3142 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3143 | 'SUCCESS') |
| 3144 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3145 | 'SUCCESS') |
| 3146 | self.assertEqual(A.data['status'], 'MERGED') |
| 3147 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3148 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3149 | def test_repo_deleted(self): |
| 3150 | self.config.set('zuul', 'layout_config', |
| 3151 | 'tests/fixtures/layout-repo-deleted.yaml') |
| 3152 | self.sched.reconfigure(self.config) |
| 3153 | |
| 3154 | self.init_repo("org/delete-project") |
| 3155 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3156 | |
| 3157 | A.addApproval('CRVW', 2) |
| 3158 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3159 | self.waitUntilSettled() |
| 3160 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3161 | 'SUCCESS') |
| 3162 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3163 | 'SUCCESS') |
| 3164 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3165 | 'SUCCESS') |
| 3166 | self.assertEqual(A.data['status'], 'MERGED') |
| 3167 | self.assertEqual(A.reported, 2) |
| 3168 | |
| 3169 | # Delete org/new-project zuul repo. Should be recloned. |
| 3170 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 3171 | |
| 3172 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3173 | |
| 3174 | B.addApproval('CRVW', 2) |
| 3175 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3176 | self.waitUntilSettled() |
| 3177 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3178 | 'SUCCESS') |
| 3179 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3180 | 'SUCCESS') |
| 3181 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3182 | 'SUCCESS') |
| 3183 | self.assertEqual(B.data['status'], 'MERGED') |
| 3184 | self.assertEqual(B.reported, 2) |
| 3185 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3186 | def test_timer(self): |
| 3187 | "Test that a periodic job is triggered" |
| 3188 | self.worker.hold_jobs_in_build = True |
| 3189 | self.config.set('zuul', 'layout_config', |
| 3190 | 'tests/fixtures/layout-timer.yaml') |
| 3191 | self.sched.reconfigure(self.config) |
| 3192 | self.registerJobs() |
| 3193 | |
| 3194 | start = time.time() |
| 3195 | failed = True |
| 3196 | while ((time.time() - start) < 30): |
| 3197 | if len(self.builds) == 2: |
| 3198 | failed = False |
| 3199 | break |
| 3200 | else: |
| 3201 | time.sleep(1) |
| 3202 | |
| 3203 | if failed: |
| 3204 | raise Exception("Expected jobs never ran") |
| 3205 | |
| 3206 | self.waitUntilSettled() |
| 3207 | port = self.webapp.server.socket.getsockname()[1] |
| 3208 | |
| 3209 | f = urllib.urlopen("http://localhost:%s/status.json" % port) |
| 3210 | data = f.read() |
| 3211 | |
| 3212 | self.worker.hold_jobs_in_build = False |
| 3213 | self.worker.release() |
| 3214 | self.waitUntilSettled() |
| 3215 | |
| 3216 | self.assertEqual(self.getJobFromHistory( |
| 3217 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3218 | self.assertEqual(self.getJobFromHistory( |
| 3219 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3220 | |
| 3221 | data = json.loads(data) |
| 3222 | status_jobs = set() |
| 3223 | for p in data['pipelines']: |
| 3224 | for q in p['change_queues']: |
| 3225 | for head in q['heads']: |
| 3226 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 3227 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3228 | for job in change['jobs']: |
| 3229 | status_jobs.add(job['name']) |
| 3230 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 3231 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3232 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3233 | def test_idle(self): |
| 3234 | "Test that frequent periodic jobs work" |
| 3235 | self.worker.hold_jobs_in_build = True |
| 3236 | self.config.set('zuul', 'layout_config', |
| 3237 | 'tests/fixtures/layout-idle.yaml') |
| 3238 | self.sched.reconfigure(self.config) |
| 3239 | self.registerJobs() |
| 3240 | |
| 3241 | # The pipeline triggers every second, so we should have seen |
| 3242 | # several by now. |
| 3243 | time.sleep(5) |
| 3244 | self.waitUntilSettled() |
| 3245 | self.assertEqual(len(self.builds), 2) |
| 3246 | self.worker.release('.*') |
| 3247 | self.waitUntilSettled() |
| 3248 | self.assertEqual(len(self.builds), 0) |
| 3249 | self.assertEqual(len(self.history), 2) |
| 3250 | |
| 3251 | time.sleep(5) |
| 3252 | self.waitUntilSettled() |
| 3253 | self.assertEqual(len(self.builds), 2) |
| 3254 | self.assertEqual(len(self.history), 2) |
| 3255 | self.worker.release('.*') |
| 3256 | self.waitUntilSettled() |
| 3257 | self.assertEqual(len(self.builds), 0) |
| 3258 | self.assertEqual(len(self.history), 4) |
| 3259 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3260 | def test_check_smtp_pool(self): |
| 3261 | self.config.set('zuul', 'layout_config', |
| 3262 | 'tests/fixtures/layout-smtp.yaml') |
| 3263 | self.sched.reconfigure(self.config) |
| 3264 | |
| 3265 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3266 | self.waitUntilSettled() |
| 3267 | |
| 3268 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3269 | self.waitUntilSettled() |
| 3270 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3271 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3272 | |
| 3273 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3274 | # work on the knowledge of what the first message should be as |
| 3275 | # it is only configured to go to SMTP. |
| 3276 | |
| 3277 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3278 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3279 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3280 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3281 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3282 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3283 | |
| 3284 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3285 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3286 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3287 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3288 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3289 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3290 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3291 | def test_timer_smtp(self): |
| 3292 | "Test that a periodic job is triggered" |
| 3293 | self.config.set('zuul', 'layout_config', |
| 3294 | 'tests/fixtures/layout-timer-smtp.yaml') |
| 3295 | self.sched.reconfigure(self.config) |
| 3296 | self.registerJobs() |
| 3297 | |
| 3298 | start = time.time() |
| 3299 | failed = True |
| 3300 | while ((time.time() - start) < 30): |
| 3301 | if len(self.history) == 2: |
| 3302 | failed = False |
| 3303 | break |
| 3304 | else: |
| 3305 | time.sleep(1) |
| 3306 | |
| 3307 | if failed: |
| 3308 | raise Exception("Expected jobs never ran") |
| 3309 | |
| 3310 | self.waitUntilSettled() |
| 3311 | |
| 3312 | self.assertEqual(self.getJobFromHistory( |
| 3313 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3314 | self.assertEqual(self.getJobFromHistory( |
| 3315 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3316 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3317 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3318 | |
| 3319 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3320 | # work on the knowledge of what the first message should be as |
| 3321 | # it is only configured to go to SMTP. |
| 3322 | |
| 3323 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3324 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3325 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3326 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3327 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3328 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3329 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3330 | def test_client_enqueue(self): |
| 3331 | "Test that the RPC client can enqueue a change" |
| 3332 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3333 | A.addApproval('CRVW', 2) |
| 3334 | A.addApproval('APRV', 1) |
| 3335 | |
| 3336 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3337 | self.gearman_server.port) |
| 3338 | r = client.enqueue(pipeline='gate', |
| 3339 | project='org/project', |
| 3340 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3341 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3342 | self.waitUntilSettled() |
| 3343 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3344 | 'SUCCESS') |
| 3345 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3346 | 'SUCCESS') |
| 3347 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3348 | 'SUCCESS') |
| 3349 | self.assertEqual(A.data['status'], 'MERGED') |
| 3350 | self.assertEqual(A.reported, 2) |
| 3351 | self.assertEqual(r, True) |
| 3352 | |
| 3353 | def test_client_enqueue_negative(self): |
| 3354 | "Test that the RPC client returns errors" |
| 3355 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3356 | self.gearman_server.port) |
| 3357 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3358 | "Invalid project"): |
| 3359 | r = client.enqueue(pipeline='gate', |
| 3360 | project='project-does-not-exist', |
| 3361 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3362 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3363 | client.shutdown() |
| 3364 | self.assertEqual(r, False) |
| 3365 | |
| 3366 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3367 | "Invalid pipeline"): |
| 3368 | r = client.enqueue(pipeline='pipeline-does-not-exist', |
| 3369 | project='org/project', |
| 3370 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3371 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3372 | client.shutdown() |
| 3373 | self.assertEqual(r, False) |
| 3374 | |
| 3375 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3376 | "Invalid trigger"): |
| 3377 | r = client.enqueue(pipeline='gate', |
| 3378 | project='org/project', |
| 3379 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3380 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3381 | client.shutdown() |
| 3382 | self.assertEqual(r, False) |
| 3383 | |
| 3384 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3385 | "Invalid change"): |
| 3386 | r = client.enqueue(pipeline='gate', |
| 3387 | project='org/project', |
| 3388 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3389 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3390 | client.shutdown() |
| 3391 | self.assertEqual(r, False) |
| 3392 | |
| 3393 | self.waitUntilSettled() |
| 3394 | self.assertEqual(len(self.history), 0) |
| 3395 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3396 | |
| 3397 | def test_client_promote(self): |
| 3398 | "Test that the RPC client can promote a change" |
| 3399 | self.worker.hold_jobs_in_build = True |
| 3400 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3401 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3402 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3403 | A.addApproval('CRVW', 2) |
| 3404 | B.addApproval('CRVW', 2) |
| 3405 | C.addApproval('CRVW', 2) |
| 3406 | |
| 3407 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3408 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3409 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3410 | |
| 3411 | self.waitUntilSettled() |
| 3412 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3413 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3414 | enqueue_times = {} |
| 3415 | for item in items: |
| 3416 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3417 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3418 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3419 | self.gearman_server.port) |
| 3420 | r = client.promote(pipeline='gate', |
| 3421 | change_ids=['2,1', '3,1']) |
| 3422 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3423 | # ensure that enqueue times are durable |
| 3424 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3425 | for item in items: |
| 3426 | self.assertEqual( |
| 3427 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3428 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3429 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3430 | self.worker.release('.*-merge') |
| 3431 | self.waitUntilSettled() |
| 3432 | self.worker.release('.*-merge') |
| 3433 | self.waitUntilSettled() |
| 3434 | self.worker.release('.*-merge') |
| 3435 | self.waitUntilSettled() |
| 3436 | |
| 3437 | self.assertEqual(len(self.builds), 6) |
| 3438 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3439 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3440 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3441 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3442 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3443 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3444 | |
| 3445 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3446 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3447 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3448 | |
| 3449 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3450 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3451 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3452 | |
| 3453 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3454 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3455 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3456 | |
| 3457 | self.worker.release() |
| 3458 | self.waitUntilSettled() |
| 3459 | |
| 3460 | self.assertEqual(A.data['status'], 'MERGED') |
| 3461 | self.assertEqual(A.reported, 2) |
| 3462 | self.assertEqual(B.data['status'], 'MERGED') |
| 3463 | self.assertEqual(B.reported, 2) |
| 3464 | self.assertEqual(C.data['status'], 'MERGED') |
| 3465 | self.assertEqual(C.reported, 2) |
| 3466 | |
| 3467 | client.shutdown() |
| 3468 | self.assertEqual(r, True) |
| 3469 | |
| 3470 | def test_client_promote_dependent(self): |
| 3471 | "Test that the RPC client can promote a dependent change" |
| 3472 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3473 | # A -> C (depends on B) -> B |
| 3474 | self.worker.hold_jobs_in_build = True |
| 3475 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3476 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3477 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3478 | |
| 3479 | C.setDependsOn(B, 1) |
| 3480 | |
| 3481 | A.addApproval('CRVW', 2) |
| 3482 | B.addApproval('CRVW', 2) |
| 3483 | C.addApproval('CRVW', 2) |
| 3484 | |
| 3485 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3486 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3487 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3488 | |
| 3489 | self.waitUntilSettled() |
| 3490 | |
| 3491 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3492 | self.gearman_server.port) |
| 3493 | r = client.promote(pipeline='gate', |
| 3494 | change_ids=['3,1']) |
| 3495 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3496 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3497 | self.worker.release('.*-merge') |
| 3498 | self.waitUntilSettled() |
| 3499 | self.worker.release('.*-merge') |
| 3500 | self.waitUntilSettled() |
| 3501 | self.worker.release('.*-merge') |
| 3502 | self.waitUntilSettled() |
| 3503 | |
| 3504 | self.assertEqual(len(self.builds), 6) |
| 3505 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3506 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3507 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3508 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3509 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3510 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3511 | |
| 3512 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3513 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3514 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3515 | |
| 3516 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3517 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3518 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3519 | |
| 3520 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3521 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3522 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3523 | |
| 3524 | self.worker.release() |
| 3525 | self.waitUntilSettled() |
| 3526 | |
| 3527 | self.assertEqual(A.data['status'], 'MERGED') |
| 3528 | self.assertEqual(A.reported, 2) |
| 3529 | self.assertEqual(B.data['status'], 'MERGED') |
| 3530 | self.assertEqual(B.reported, 2) |
| 3531 | self.assertEqual(C.data['status'], 'MERGED') |
| 3532 | self.assertEqual(C.reported, 2) |
| 3533 | |
| 3534 | client.shutdown() |
| 3535 | self.assertEqual(r, True) |
| 3536 | |
| 3537 | def test_client_promote_negative(self): |
| 3538 | "Test that the RPC client returns errors for promotion" |
| 3539 | self.worker.hold_jobs_in_build = True |
| 3540 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3541 | A.addApproval('CRVW', 2) |
| 3542 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3543 | self.waitUntilSettled() |
| 3544 | |
| 3545 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3546 | self.gearman_server.port) |
| 3547 | |
| 3548 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3549 | r = client.promote(pipeline='nonexistent', |
| 3550 | change_ids=['2,1', '3,1']) |
| 3551 | client.shutdown() |
| 3552 | self.assertEqual(r, False) |
| 3553 | |
| 3554 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3555 | r = client.promote(pipeline='gate', |
| 3556 | change_ids=['4,1']) |
| 3557 | client.shutdown() |
| 3558 | self.assertEqual(r, False) |
| 3559 | |
| 3560 | self.worker.hold_jobs_in_build = False |
| 3561 | self.worker.release() |
| 3562 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3563 | |
| 3564 | def test_queue_rate_limiting(self): |
| 3565 | "Test that DependentPipelines are rate limited with dep across window" |
| 3566 | self.config.set('zuul', 'layout_config', |
| 3567 | 'tests/fixtures/layout-rate-limit.yaml') |
| 3568 | self.sched.reconfigure(self.config) |
| 3569 | self.worker.hold_jobs_in_build = True |
| 3570 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3571 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3572 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3573 | |
| 3574 | C.setDependsOn(B, 1) |
| 3575 | self.worker.addFailTest('project-test1', A) |
| 3576 | |
| 3577 | A.addApproval('CRVW', 2) |
| 3578 | B.addApproval('CRVW', 2) |
| 3579 | C.addApproval('CRVW', 2) |
| 3580 | |
| 3581 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3582 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3583 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3584 | self.waitUntilSettled() |
| 3585 | |
| 3586 | # Only A and B will have their merge jobs queued because |
| 3587 | # window is 2. |
| 3588 | self.assertEqual(len(self.builds), 2) |
| 3589 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3590 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3591 | |
| 3592 | self.worker.release('.*-merge') |
| 3593 | self.waitUntilSettled() |
| 3594 | self.worker.release('.*-merge') |
| 3595 | self.waitUntilSettled() |
| 3596 | |
| 3597 | # Only A and B will have their test jobs queued because |
| 3598 | # window is 2. |
| 3599 | self.assertEqual(len(self.builds), 4) |
| 3600 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3601 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3602 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3603 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3604 | |
| 3605 | self.worker.release('project-.*') |
| 3606 | self.waitUntilSettled() |
| 3607 | |
| 3608 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3609 | # A failed so window is reduced by 1 to 1. |
| 3610 | self.assertEqual(queue.window, 1) |
| 3611 | self.assertEqual(queue.window_floor, 1) |
| 3612 | self.assertEqual(A.data['status'], 'NEW') |
| 3613 | |
| 3614 | # Gate is reset and only B's merge job is queued because |
| 3615 | # window shrunk to 1. |
| 3616 | self.assertEqual(len(self.builds), 1) |
| 3617 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3618 | |
| 3619 | self.worker.release('.*-merge') |
| 3620 | self.waitUntilSettled() |
| 3621 | |
| 3622 | # Only B's test jobs are queued because window is still 1. |
| 3623 | self.assertEqual(len(self.builds), 2) |
| 3624 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3625 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3626 | |
| 3627 | self.worker.release('project-.*') |
| 3628 | self.waitUntilSettled() |
| 3629 | |
| 3630 | # B was successfully merged so window is increased to 2. |
| 3631 | self.assertEqual(queue.window, 2) |
| 3632 | self.assertEqual(queue.window_floor, 1) |
| 3633 | self.assertEqual(B.data['status'], 'MERGED') |
| 3634 | |
| 3635 | # Only C is left and its merge job is queued. |
| 3636 | self.assertEqual(len(self.builds), 1) |
| 3637 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3638 | |
| 3639 | self.worker.release('.*-merge') |
| 3640 | self.waitUntilSettled() |
| 3641 | |
| 3642 | # After successful merge job the test jobs for C are queued. |
| 3643 | self.assertEqual(len(self.builds), 2) |
| 3644 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3645 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3646 | |
| 3647 | self.worker.release('project-.*') |
| 3648 | self.waitUntilSettled() |
| 3649 | |
| 3650 | # C successfully merged so window is bumped to 3. |
| 3651 | self.assertEqual(queue.window, 3) |
| 3652 | self.assertEqual(queue.window_floor, 1) |
| 3653 | self.assertEqual(C.data['status'], 'MERGED') |
| 3654 | |
| 3655 | def test_queue_rate_limiting_dependent(self): |
| 3656 | "Test that DependentPipelines are rate limited with dep in window" |
| 3657 | self.config.set('zuul', 'layout_config', |
| 3658 | 'tests/fixtures/layout-rate-limit.yaml') |
| 3659 | self.sched.reconfigure(self.config) |
| 3660 | self.worker.hold_jobs_in_build = True |
| 3661 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3662 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3663 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3664 | |
| 3665 | B.setDependsOn(A, 1) |
| 3666 | |
| 3667 | self.worker.addFailTest('project-test1', A) |
| 3668 | |
| 3669 | A.addApproval('CRVW', 2) |
| 3670 | B.addApproval('CRVW', 2) |
| 3671 | C.addApproval('CRVW', 2) |
| 3672 | |
| 3673 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3674 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3675 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3676 | self.waitUntilSettled() |
| 3677 | |
| 3678 | # Only A and B will have their merge jobs queued because |
| 3679 | # window is 2. |
| 3680 | self.assertEqual(len(self.builds), 2) |
| 3681 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3682 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3683 | |
| 3684 | self.worker.release('.*-merge') |
| 3685 | self.waitUntilSettled() |
| 3686 | self.worker.release('.*-merge') |
| 3687 | self.waitUntilSettled() |
| 3688 | |
| 3689 | # Only A and B will have their test jobs queued because |
| 3690 | # window is 2. |
| 3691 | self.assertEqual(len(self.builds), 4) |
| 3692 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3693 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3694 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3695 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3696 | |
| 3697 | self.worker.release('project-.*') |
| 3698 | self.waitUntilSettled() |
| 3699 | |
| 3700 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3701 | # A failed so window is reduced by 1 to 1. |
| 3702 | self.assertEqual(queue.window, 1) |
| 3703 | self.assertEqual(queue.window_floor, 1) |
| 3704 | self.assertEqual(A.data['status'], 'NEW') |
| 3705 | self.assertEqual(B.data['status'], 'NEW') |
| 3706 | |
| 3707 | # Gate is reset and only C's merge job is queued because |
| 3708 | # window shrunk to 1 and A and B were dequeued. |
| 3709 | self.assertEqual(len(self.builds), 1) |
| 3710 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3711 | |
| 3712 | self.worker.release('.*-merge') |
| 3713 | self.waitUntilSettled() |
| 3714 | |
| 3715 | # Only C's test jobs are queued because window is still 1. |
| 3716 | self.assertEqual(len(self.builds), 2) |
| 3717 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3718 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3719 | |
| 3720 | self.worker.release('project-.*') |
| 3721 | self.waitUntilSettled() |
| 3722 | |
| 3723 | # C was successfully merged so window is increased to 2. |
| 3724 | self.assertEqual(queue.window, 2) |
| 3725 | self.assertEqual(queue.window_floor, 1) |
| 3726 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3727 | |
| 3728 | def test_worker_update_metadata(self): |
| 3729 | "Test if a worker can send back metadata about itself" |
| 3730 | self.worker.hold_jobs_in_build = True |
| 3731 | |
| 3732 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3733 | A.addApproval('CRVW', 2) |
| 3734 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3735 | self.waitUntilSettled() |
| 3736 | |
| 3737 | self.assertEqual(len(self.launcher.builds), 1) |
| 3738 | |
| 3739 | self.log.debug('Current builds:') |
| 3740 | self.log.debug(self.launcher.builds) |
| 3741 | |
| 3742 | start = time.time() |
| 3743 | while True: |
| 3744 | if time.time() - start > 10: |
| 3745 | raise Exception("Timeout waiting for gearman server to report " |
| 3746 | + "back to the client") |
| 3747 | build = self.launcher.builds.values()[0] |
| 3748 | if build.worker.name == "My Worker": |
| 3749 | break |
| 3750 | else: |
| 3751 | time.sleep(0) |
| 3752 | |
| 3753 | self.log.debug(build) |
| 3754 | self.assertEqual("My Worker", build.worker.name) |
| 3755 | self.assertEqual("localhost", build.worker.hostname) |
| 3756 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3757 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3758 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3759 | self.assertEqual("v1.1", build.worker.version) |
| 3760 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3761 | |
| 3762 | self.worker.hold_jobs_in_build = False |
| 3763 | self.worker.release() |
| 3764 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3765 | |
| 3766 | def test_footer_message(self): |
| 3767 | "Test a pipeline's footer message is correctly added to the report." |
| 3768 | self.config.set('zuul', 'layout_config', |
| 3769 | 'tests/fixtures/layout-footer-message.yaml') |
| 3770 | self.sched.reconfigure(self.config) |
| 3771 | self.registerJobs() |
| 3772 | |
| 3773 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3774 | A.addApproval('CRVW', 2) |
| 3775 | self.worker.addFailTest('test1', A) |
| 3776 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3777 | self.waitUntilSettled() |
| 3778 | |
| 3779 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3780 | B.addApproval('CRVW', 2) |
| 3781 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3782 | self.waitUntilSettled() |
| 3783 | |
| 3784 | self.assertEqual(2, len(self.smtp_messages)) |
| 3785 | |
| 3786 | failure_body = """\ |
| 3787 | Build failed. For information on how to proceed, see \ |
| 3788 | http://wiki.example.org/Test_Failures |
| 3789 | |
| 3790 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3791 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3792 | |
| 3793 | For CI problems and help debugging, contact ci@example.org""" |
| 3794 | |
| 3795 | success_body = """\ |
| 3796 | Build succeeded. |
| 3797 | |
| 3798 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3799 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3800 | |
| 3801 | For CI problems and help debugging, contact ci@example.org""" |
| 3802 | |
| 3803 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3804 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3805 | |
| 3806 | def test_merge_failure_reporters(self): |
| 3807 | """Check that the config is set up correctly""" |
| 3808 | |
| 3809 | self.config.set('zuul', 'layout_config', |
| 3810 | 'tests/fixtures/layout-merge-failure.yaml') |
| 3811 | self.sched.reconfigure(self.config) |
| 3812 | self.registerJobs() |
| 3813 | |
| 3814 | self.assertEqual( |
| 3815 | "Merge Failed.\n\nThis change was unable to be automatically " |
| 3816 | "merged with the current state of the repository. Please rebase " |
| 3817 | "your change and upload a new patchset.", |
| 3818 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3819 | self.assertEqual( |
| 3820 | "The merge failed! For more information...", |
| 3821 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3822 | |
| 3823 | self.assertEqual( |
| 3824 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3825 | self.assertEqual( |
| 3826 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3827 | |
| 3828 | self.assertTrue(isinstance( |
| 3829 | self.sched.layout.pipelines['check'].merge_failure_actions[0]. |
| 3830 | reporter, zuul.reporter.gerrit.Reporter)) |
| 3831 | |
| 3832 | self.assertTrue( |
| 3833 | ( |
| 3834 | isinstance(self.sched.layout.pipelines['gate']. |
| 3835 | merge_failure_actions[0].reporter, |
| 3836 | zuul.reporter.smtp.Reporter) and |
| 3837 | isinstance(self.sched.layout.pipelines['gate']. |
| 3838 | merge_failure_actions[1].reporter, |
| 3839 | zuul.reporter.gerrit.Reporter) |
| 3840 | ) or ( |
| 3841 | isinstance(self.sched.layout.pipelines['gate']. |
| 3842 | merge_failure_actions[0].reporter, |
| 3843 | zuul.reporter.gerrit.Reporter) and |
| 3844 | isinstance(self.sched.layout.pipelines['gate']. |
| 3845 | merge_failure_actions[1].reporter, |
| 3846 | zuul.reporter.smtp.Reporter) |
| 3847 | ) |
| 3848 | ) |
| 3849 | |
| 3850 | def test_merge_failure_reports(self): |
| 3851 | """Check that when a change fails to merge the correct message is sent |
| 3852 | to the correct reporter""" |
| 3853 | self.config.set('zuul', 'layout_config', |
| 3854 | 'tests/fixtures/layout-merge-failure.yaml') |
| 3855 | self.sched.reconfigure(self.config) |
| 3856 | self.registerJobs() |
| 3857 | |
| 3858 | # Check a test failure isn't reported to SMTP |
| 3859 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3860 | A.addApproval('CRVW', 2) |
| 3861 | self.worker.addFailTest('project-test1', A) |
| 3862 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3863 | self.waitUntilSettled() |
| 3864 | |
| 3865 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3866 | self.assertEqual(0, len(self.smtp_messages)) |
| 3867 | |
| 3868 | # Check a merge failure is reported to SMTP |
| 3869 | # B should be merged, but C will conflict with B |
| 3870 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3871 | B.addPatchset(['conflict']) |
| 3872 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3873 | C.addPatchset(['conflict']) |
| 3874 | B.addApproval('CRVW', 2) |
| 3875 | C.addApproval('CRVW', 2) |
| 3876 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3877 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3878 | self.waitUntilSettled() |
| 3879 | |
| 3880 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3881 | self.assertEqual(1, len(self.smtp_messages)) |
| 3882 | self.assertEqual('The merge failed! For more information...', |
| 3883 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3884 | |
| 3885 | def test_swift_instructions(self): |
| 3886 | "Test that the correct swift instructions are sent to the workers" |
| 3887 | self.config.set('zuul', 'layout_config', |
| 3888 | 'tests/fixtures/layout-swift.yaml') |
| 3889 | self.sched.reconfigure(self.config) |
| 3890 | self.registerJobs() |
| 3891 | |
| 3892 | self.worker.hold_jobs_in_build = True |
| 3893 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3894 | |
| 3895 | A.addApproval('CRVW', 2) |
| 3896 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3897 | self.waitUntilSettled() |
| 3898 | |
| 3899 | self.assertEqual( |
| 3900 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3901 | "gate/test-merge/", |
| 3902 | self.builds[0].parameters['SWIFT_logs_URL'][:-32]) |
| 3903 | self.assertEqual(5, |
| 3904 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3905 | split('\n'))) |
| 3906 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3907 | |
| 3908 | self.assertEqual( |
| 3909 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3910 | "gate/test-test/", |
| 3911 | self.builds[1].parameters['SWIFT_logs_URL'][:-32]) |
| 3912 | self.assertEqual(5, |
| 3913 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3914 | split('\n'))) |
| 3915 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3916 | |
| 3917 | self.assertEqual( |
| 3918 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3919 | "gate/test-test/", |
| 3920 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-32]) |
| 3921 | self.assertEqual(5, |
| 3922 | len(self.builds[1]. |
| 3923 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3924 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3925 | |
| 3926 | self.worker.hold_jobs_in_build = False |
| 3927 | self.worker.release() |
| 3928 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3929 | |
| 3930 | def test_client_get_running_jobs(self): |
| 3931 | "Test that the RPC client can get a list of running jobs" |
| 3932 | self.worker.hold_jobs_in_build = True |
| 3933 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3934 | A.addApproval('CRVW', 2) |
| 3935 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3936 | self.waitUntilSettled() |
| 3937 | |
| 3938 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3939 | self.gearman_server.port) |
| 3940 | |
| 3941 | # Wait for gearman server to send the initial workData back to zuul |
| 3942 | start = time.time() |
| 3943 | while True: |
| 3944 | if time.time() - start > 10: |
| 3945 | raise Exception("Timeout waiting for gearman server to report " |
| 3946 | + "back to the client") |
| 3947 | build = self.launcher.builds.values()[0] |
| 3948 | if build.worker.name == "My Worker": |
| 3949 | break |
| 3950 | else: |
| 3951 | time.sleep(0) |
| 3952 | |
| 3953 | running_items = client.get_running_jobs() |
| 3954 | |
| 3955 | self.assertEqual(1, len(running_items)) |
| 3956 | running_item = running_items[0] |
| 3957 | self.assertEqual([], running_item['failing_reasons']) |
| 3958 | self.assertEqual([], running_item['items_behind']) |
| 3959 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3960 | self.assertEqual(None, running_item['item_ahead']) |
| 3961 | self.assertEqual('org/project', running_item['project']) |
| 3962 | self.assertEqual(None, running_item['remaining_time']) |
| 3963 | self.assertEqual(True, running_item['active']) |
| 3964 | self.assertEqual('1,1', running_item['id']) |
| 3965 | |
| 3966 | self.assertEqual(3, len(running_item['jobs'])) |
| 3967 | for job in running_item['jobs']: |
| 3968 | if job['name'] == 'project-merge': |
| 3969 | self.assertEqual('project-merge', job['name']) |
| 3970 | self.assertEqual('gate', job['pipeline']) |
| 3971 | self.assertEqual(False, job['retry']) |
| 3972 | self.assertEqual(13, len(job['parameters'])) |
| 3973 | self.assertEqual('https://server/job/project-merge/0/', |
| 3974 | job['url']) |
| 3975 | self.assertEqual(7, len(job['worker'])) |
| 3976 | self.assertEqual(False, job['canceled']) |
| 3977 | self.assertEqual(True, job['voting']) |
| 3978 | self.assertEqual(None, job['result']) |
| 3979 | self.assertEqual('gate', job['pipeline']) |
| 3980 | break |
| 3981 | |
| 3982 | self.worker.hold_jobs_in_build = False |
| 3983 | self.worker.release() |
| 3984 | self.waitUntilSettled() |
| 3985 | |
| 3986 | running_items = client.get_running_jobs() |
| 3987 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3988 | |
| 3989 | def test_nonvoting_pipeline(self): |
| 3990 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3991 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3992 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3993 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3994 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3995 | self.waitUntilSettled() |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3996 | self.assertEqual( |
| 3997 | self.getJobFromHistory('experimental-project-test').result, |
| 3998 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3999 | self.assertEqual(A.reported, 1) |