James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012-2014 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 | |
| 17 | import logging |
| 18 | import time |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 19 | from unittest import skip |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 20 | |
| 21 | from tests.base import ZuulTestCase |
| 22 | |
| 23 | logging.basicConfig(level=logging.DEBUG, |
| 24 | format='%(asctime)s %(name)-32s ' |
| 25 | '%(levelname)-8s %(message)s') |
| 26 | |
| 27 | |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 28 | class TestRequirementsApprovalNewerThan(ZuulTestCase): |
| 29 | """Requirements with a newer-than comment requirement""" |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 30 | |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 31 | tenant_config_file = 'config/requirements/newer-than/main.yaml' |
| 32 | |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 33 | def test_pipeline_require_approval_newer_than(self): |
| 34 | "Test pipeline requirement: approval newer than" |
| 35 | return self._test_require_approval_newer_than('org/project1', |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 36 | 'project1-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 37 | |
| 38 | def test_trigger_require_approval_newer_than(self): |
| 39 | "Test trigger requirement: approval newer than" |
| 40 | return self._test_require_approval_newer_than('org/project2', |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 41 | 'project2-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 42 | |
| 43 | def _test_require_approval_newer_than(self, project, job): |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 44 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 45 | # A comment event that we will keep submitting to trigger |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 46 | comment = A.addApproval('code-review', 2, username='nobody') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 47 | self.fake_gerrit.addEvent(comment) |
| 48 | self.waitUntilSettled() |
| 49 | # No +1 from Jenkins so should not be enqueued |
| 50 | self.assertEqual(len(self.history), 0) |
| 51 | |
| 52 | # Add a too-old +1, should not be enqueued |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 53 | A.addApproval('verified', 1, username='jenkins', |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 54 | granted_on=time.time() - 72 * 60 * 60) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 55 | self.fake_gerrit.addEvent(comment) |
| 56 | self.waitUntilSettled() |
| 57 | self.assertEqual(len(self.history), 0) |
| 58 | |
| 59 | # Add a recent +1 |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 60 | self.fake_gerrit.addEvent(A.addApproval('verified', 1, |
| 61 | username='jenkins')) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 62 | self.fake_gerrit.addEvent(comment) |
| 63 | self.waitUntilSettled() |
| 64 | self.assertEqual(len(self.history), 1) |
| 65 | self.assertEqual(self.history[0].name, job) |
| 66 | |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 67 | |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 68 | class TestRequirementsApprovalOlderThan(ZuulTestCase): |
| 69 | """Requirements with a older-than comment requirement""" |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 70 | |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 71 | tenant_config_file = 'config/requirements/older-than/main.yaml' |
Jamie Lennox | b59a73f | 2016-11-23 14:27:18 +1100 | [diff] [blame] | 72 | |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 73 | def test_pipeline_require_approval_older_than(self): |
| 74 | "Test pipeline requirement: approval older than" |
| 75 | return self._test_require_approval_older_than('org/project1', |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 76 | 'project1-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 77 | |
| 78 | def test_trigger_require_approval_older_than(self): |
| 79 | "Test trigger requirement: approval older than" |
| 80 | return self._test_require_approval_older_than('org/project2', |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 81 | 'project2-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 82 | |
| 83 | def _test_require_approval_older_than(self, project, job): |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 84 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 85 | # A comment event that we will keep submitting to trigger |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 86 | comment = A.addApproval('code-review', 2, username='nobody') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 87 | self.fake_gerrit.addEvent(comment) |
| 88 | self.waitUntilSettled() |
| 89 | # No +1 from Jenkins so should not be enqueued |
| 90 | self.assertEqual(len(self.history), 0) |
| 91 | |
| 92 | # Add a recent +1 which should not be enqueued |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 93 | A.addApproval('verified', 1) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 94 | self.fake_gerrit.addEvent(comment) |
| 95 | self.waitUntilSettled() |
| 96 | self.assertEqual(len(self.history), 0) |
| 97 | |
| 98 | # Add an old +1 which should be enqueued |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 99 | A.addApproval('verified', 1, username='jenkins', |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 100 | granted_on=time.time() - 72 * 60 * 60) |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 101 | self.fake_gerrit.addEvent(comment) |
| 102 | self.waitUntilSettled() |
| 103 | self.assertEqual(len(self.history), 1) |
| 104 | self.assertEqual(self.history[0].name, job) |
| 105 | |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 106 | |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 107 | class TestRequirementsUserName(ZuulTestCase): |
| 108 | """Requirements with a username requirement""" |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 109 | |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 110 | tenant_config_file = 'config/requirements/username/main.yaml' |
Jamie Lennox | 8faa71e | 2016-11-23 14:33:52 +1100 | [diff] [blame] | 111 | |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 112 | def test_pipeline_require_approval_username(self): |
| 113 | "Test pipeline requirement: approval username" |
| 114 | return self._test_require_approval_username('org/project1', |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 115 | 'project1-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 116 | |
| 117 | def test_trigger_require_approval_username(self): |
| 118 | "Test trigger requirement: approval username" |
| 119 | return self._test_require_approval_username('org/project2', |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 120 | 'project2-job') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 121 | |
| 122 | def _test_require_approval_username(self, project, job): |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 123 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 124 | # A comment event that we will keep submitting to trigger |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 125 | comment = A.addApproval('code-review', 2, username='nobody') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 126 | self.fake_gerrit.addEvent(comment) |
| 127 | self.waitUntilSettled() |
| 128 | # No approval from Jenkins so should not be enqueued |
| 129 | self.assertEqual(len(self.history), 0) |
| 130 | |
| 131 | # Add an approval from Jenkins |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 132 | A.addApproval('verified', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 133 | self.fake_gerrit.addEvent(comment) |
| 134 | self.waitUntilSettled() |
| 135 | self.assertEqual(len(self.history), 1) |
| 136 | self.assertEqual(self.history[0].name, job) |
| 137 | |
Jamie Lennox | db3b4e0 | 2016-11-23 14:36:12 +1100 | [diff] [blame^] | 138 | |
| 139 | class TestRequirements(ZuulTestCase): |
| 140 | """Test pipeline and trigger requirements""" |
| 141 | |
| 142 | tenant_config_file = 'config/requirements/main.yaml' |
| 143 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 144 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 145 | def test_pipeline_require_approval_email(self): |
| 146 | "Test pipeline requirement: approval email" |
| 147 | return self._test_require_approval_email('org/project1', |
| 148 | 'project1-pipeline') |
| 149 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 150 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 151 | def test_trigger_require_approval_email(self): |
| 152 | "Test trigger requirement: approval email" |
| 153 | return self._test_require_approval_email('org/project2', |
| 154 | 'project2-trigger') |
| 155 | |
| 156 | def _test_require_approval_email(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 157 | self.updateConfigLayout( |
| 158 | 'tests/fixtures/layout-requirement-email.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 159 | self.sched.reconfigure(self.config) |
| 160 | self.registerJobs() |
| 161 | |
| 162 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 163 | # A comment event that we will keep submitting to trigger |
| 164 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 165 | self.fake_gerrit.addEvent(comment) |
| 166 | self.waitUntilSettled() |
| 167 | # No approval from Jenkins so should not be enqueued |
| 168 | self.assertEqual(len(self.history), 0) |
| 169 | |
| 170 | # Add an approval from Jenkins |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 171 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 172 | self.fake_gerrit.addEvent(comment) |
| 173 | self.waitUntilSettled() |
| 174 | self.assertEqual(len(self.history), 1) |
| 175 | self.assertEqual(self.history[0].name, job) |
| 176 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 177 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 178 | def test_pipeline_require_approval_vote1(self): |
| 179 | "Test pipeline requirement: approval vote with one value" |
| 180 | return self._test_require_approval_vote1('org/project1', |
| 181 | 'project1-pipeline') |
| 182 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 183 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 184 | def test_trigger_require_approval_vote1(self): |
| 185 | "Test trigger requirement: approval vote with one value" |
| 186 | return self._test_require_approval_vote1('org/project2', |
| 187 | 'project2-trigger') |
| 188 | |
| 189 | def _test_require_approval_vote1(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 190 | self.updateConfigLayout( |
| 191 | 'tests/fixtures/layout-requirement-vote1.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 192 | self.sched.reconfigure(self.config) |
| 193 | self.registerJobs() |
| 194 | |
| 195 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 196 | # A comment event that we will keep submitting to trigger |
| 197 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 198 | self.fake_gerrit.addEvent(comment) |
| 199 | self.waitUntilSettled() |
| 200 | # No approval from Jenkins so should not be enqueued |
| 201 | self.assertEqual(len(self.history), 0) |
| 202 | |
| 203 | # A -1 from jenkins should not cause it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 204 | A.addApproval('VRFY', -1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 205 | self.fake_gerrit.addEvent(comment) |
| 206 | self.waitUntilSettled() |
| 207 | self.assertEqual(len(self.history), 0) |
| 208 | |
| 209 | # A +1 should allow it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 210 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 211 | self.fake_gerrit.addEvent(comment) |
| 212 | self.waitUntilSettled() |
| 213 | self.assertEqual(len(self.history), 1) |
| 214 | self.assertEqual(self.history[0].name, job) |
| 215 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 216 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 217 | def test_pipeline_require_approval_vote2(self): |
| 218 | "Test pipeline requirement: approval vote with two values" |
| 219 | return self._test_require_approval_vote2('org/project1', |
| 220 | 'project1-pipeline') |
| 221 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 222 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 223 | def test_trigger_require_approval_vote2(self): |
| 224 | "Test trigger requirement: approval vote with two values" |
| 225 | return self._test_require_approval_vote2('org/project2', |
| 226 | 'project2-trigger') |
| 227 | |
| 228 | def _test_require_approval_vote2(self, project, job): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 229 | self.updateConfigLayout( |
| 230 | 'tests/fixtures/layout-requirement-vote2.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 231 | self.sched.reconfigure(self.config) |
| 232 | self.registerJobs() |
| 233 | |
| 234 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 235 | # A comment event that we will keep submitting to trigger |
| 236 | comment = A.addApproval('CRVW', 2, username='nobody') |
| 237 | self.fake_gerrit.addEvent(comment) |
| 238 | self.waitUntilSettled() |
| 239 | # No approval from Jenkins so should not be enqueued |
| 240 | self.assertEqual(len(self.history), 0) |
| 241 | |
| 242 | # A -1 from jenkins should not cause it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 243 | A.addApproval('VRFY', -1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 244 | self.fake_gerrit.addEvent(comment) |
| 245 | self.waitUntilSettled() |
| 246 | self.assertEqual(len(self.history), 0) |
| 247 | |
| 248 | # A -2 from jenkins should not cause it to be enqueued |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 249 | A.addApproval('VRFY', -2, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 250 | self.fake_gerrit.addEvent(comment) |
| 251 | self.waitUntilSettled() |
| 252 | self.assertEqual(len(self.history), 0) |
| 253 | |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 254 | # A +1 from jenkins should allow it to be enqueued |
| 255 | A.addApproval('VRFY', 1, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 256 | self.fake_gerrit.addEvent(comment) |
| 257 | self.waitUntilSettled() |
| 258 | self.assertEqual(len(self.history), 1) |
| 259 | self.assertEqual(self.history[0].name, job) |
| 260 | |
| 261 | # A +2 should allow it to be enqueued |
| 262 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 263 | # A comment event that we will keep submitting to trigger |
| 264 | comment = B.addApproval('CRVW', 2, username='nobody') |
| 265 | self.fake_gerrit.addEvent(comment) |
| 266 | self.waitUntilSettled() |
| 267 | self.assertEqual(len(self.history), 1) |
| 268 | |
Joshua Hesketh | 642824b | 2014-07-01 17:54:59 +1000 | [diff] [blame] | 269 | B.addApproval('VRFY', 2, username='jenkins') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 270 | self.fake_gerrit.addEvent(comment) |
| 271 | self.waitUntilSettled() |
| 272 | self.assertEqual(len(self.history), 2) |
| 273 | self.assertEqual(self.history[1].name, job) |
| 274 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 275 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 276 | def test_pipeline_require_current_patchset(self): |
| 277 | "Test pipeline requirement: current-patchset" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 278 | self.updateConfigLayout( |
| 279 | 'tests/fixtures/layout-requirement-current-patchset.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 280 | self.sched.reconfigure(self.config) |
| 281 | self.registerJobs() |
| 282 | # Create two patchsets and let their tests settle out. Then |
| 283 | # comment on first patchset and check that no additional |
| 284 | # jobs are run. |
| 285 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 286 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1)) |
| 287 | self.waitUntilSettled() |
| 288 | A.addPatchset() |
| 289 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1)) |
| 290 | self.waitUntilSettled() |
| 291 | |
| 292 | self.assertEqual(len(self.history), 2) # one job for each ps |
| 293 | self.fake_gerrit.addEvent(A.getChangeCommentEvent(1)) |
| 294 | self.waitUntilSettled() |
| 295 | |
| 296 | # Assert no new jobs ran after event for old patchset. |
| 297 | self.assertEqual(len(self.history), 2) |
| 298 | |
| 299 | # Make sure the same event on a new PS will trigger |
| 300 | self.fake_gerrit.addEvent(A.getChangeCommentEvent(2)) |
| 301 | self.waitUntilSettled() |
| 302 | self.assertEqual(len(self.history), 3) |
| 303 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 304 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 305 | def test_pipeline_require_open(self): |
| 306 | "Test pipeline requirement: open" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 307 | self.updateConfigLayout( |
| 308 | 'tests/fixtures/layout-requirement-open.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 309 | self.sched.reconfigure(self.config) |
| 310 | self.registerJobs() |
| 311 | |
| 312 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 313 | status='MERGED') |
| 314 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 2)) |
| 315 | self.waitUntilSettled() |
| 316 | self.assertEqual(len(self.history), 0) |
| 317 | |
| 318 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 319 | self.fake_gerrit.addEvent(B.addApproval('CRVW', 2)) |
| 320 | self.waitUntilSettled() |
| 321 | self.assertEqual(len(self.history), 1) |
| 322 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 323 | @skip("Disabled for early v3 development") |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 324 | def test_pipeline_require_status(self): |
| 325 | "Test pipeline requirement: status" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 326 | self.updateConfigLayout( |
| 327 | 'tests/fixtures/layout-requirement-status.yaml') |
James E. Blair | 9c17dbf | 2014-06-23 14:21:58 -0700 | [diff] [blame] | 328 | self.sched.reconfigure(self.config) |
| 329 | self.registerJobs() |
| 330 | |
| 331 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 332 | status='MERGED') |
| 333 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 2)) |
| 334 | self.waitUntilSettled() |
| 335 | self.assertEqual(len(self.history), 0) |
| 336 | |
| 337 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 338 | self.fake_gerrit.addEvent(B.addApproval('CRVW', 2)) |
| 339 | self.waitUntilSettled() |
| 340 | self.assertEqual(len(self.history), 1) |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 341 | |
| 342 | def _test_require_reject_username(self, project, job): |
| 343 | "Test negative username's match" |
| 344 | # Should only trigger if Jenkins hasn't voted. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 345 | self.updateConfigLayout( |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 346 | 'tests/fixtures/layout-requirement-reject-username.yaml') |
| 347 | self.sched.reconfigure(self.config) |
| 348 | self.registerJobs() |
| 349 | |
| 350 | # add in a change with no comments |
| 351 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 352 | self.waitUntilSettled() |
| 353 | self.assertEqual(len(self.history), 0) |
| 354 | |
| 355 | # add in a comment that will trigger |
| 356 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1, |
| 357 | username='reviewer')) |
| 358 | self.waitUntilSettled() |
| 359 | self.assertEqual(len(self.history), 1) |
| 360 | self.assertEqual(self.history[0].name, job) |
| 361 | |
| 362 | # add in a comment from jenkins user which shouldn't trigger |
| 363 | self.fake_gerrit.addEvent(A.addApproval('VRFY', 1, username='jenkins')) |
| 364 | self.waitUntilSettled() |
| 365 | self.assertEqual(len(self.history), 1) |
| 366 | |
| 367 | # Check future reviews also won't trigger as a 'jenkins' user has |
| 368 | # commented previously |
| 369 | self.fake_gerrit.addEvent(A.addApproval('CRVW', 1, |
| 370 | username='reviewer')) |
| 371 | self.waitUntilSettled() |
| 372 | self.assertEqual(len(self.history), 1) |
| 373 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 374 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 375 | def test_pipeline_reject_username(self): |
| 376 | "Test negative pipeline requirement: no comment from jenkins" |
| 377 | return self._test_require_reject_username('org/project1', |
| 378 | 'project1-pipeline') |
| 379 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 380 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 381 | def test_trigger_reject_username(self): |
| 382 | "Test negative trigger requirement: no comment from jenkins" |
| 383 | return self._test_require_reject_username('org/project2', |
| 384 | 'project2-trigger') |
| 385 | |
| 386 | def _test_require_reject(self, project, job): |
| 387 | "Test no approval matches a reject param" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 388 | self.updateConfigLayout( |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 389 | 'tests/fixtures/layout-requirement-reject.yaml') |
| 390 | self.sched.reconfigure(self.config) |
| 391 | self.registerJobs() |
| 392 | |
| 393 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 394 | self.waitUntilSettled() |
| 395 | self.assertEqual(len(self.history), 0) |
| 396 | |
| 397 | # First positive vote should not queue until jenkins has +1'd |
| 398 | comment = A.addApproval('VRFY', 1, username='reviewer_a') |
| 399 | self.fake_gerrit.addEvent(comment) |
| 400 | self.waitUntilSettled() |
| 401 | self.assertEqual(len(self.history), 0) |
| 402 | |
| 403 | # Jenkins should put in a +1 which will also queue |
| 404 | comment = A.addApproval('VRFY', 1, username='jenkins') |
| 405 | self.fake_gerrit.addEvent(comment) |
| 406 | self.waitUntilSettled() |
| 407 | self.assertEqual(len(self.history), 1) |
| 408 | self.assertEqual(self.history[0].name, job) |
| 409 | |
| 410 | # Negative vote should not queue |
| 411 | comment = A.addApproval('VRFY', -1, username='reviewer_b') |
| 412 | self.fake_gerrit.addEvent(comment) |
| 413 | self.waitUntilSettled() |
| 414 | self.assertEqual(len(self.history), 1) |
| 415 | |
| 416 | # Future approvals should do nothing |
| 417 | comment = A.addApproval('VRFY', 1, username='reviewer_c') |
| 418 | self.fake_gerrit.addEvent(comment) |
| 419 | self.waitUntilSettled() |
| 420 | self.assertEqual(len(self.history), 1) |
| 421 | |
| 422 | # Change/update negative vote should queue |
| 423 | comment = A.addApproval('VRFY', 1, username='reviewer_b') |
| 424 | self.fake_gerrit.addEvent(comment) |
| 425 | self.waitUntilSettled() |
| 426 | self.assertEqual(len(self.history), 2) |
| 427 | self.assertEqual(self.history[1].name, job) |
| 428 | |
| 429 | # Future approvals should also queue |
| 430 | comment = A.addApproval('VRFY', 1, username='reviewer_d') |
| 431 | self.fake_gerrit.addEvent(comment) |
| 432 | self.waitUntilSettled() |
| 433 | self.assertEqual(len(self.history), 3) |
| 434 | self.assertEqual(self.history[2].name, job) |
| 435 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 436 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 437 | def test_pipeline_require_reject(self): |
| 438 | "Test pipeline requirement: rejections absent" |
| 439 | return self._test_require_reject('org/project1', 'project1-pipeline') |
| 440 | |
Jamie Lennox | ff3e0b9 | 2016-11-23 10:38:25 +1100 | [diff] [blame] | 441 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 66c8e52 | 2014-06-26 15:30:08 +1000 | [diff] [blame] | 442 | def test_trigger_require_reject(self): |
| 443 | "Test trigger requirement: rejections absent" |
| 444 | return self._test_require_reject('org/project2', 'project2-trigger') |