Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1 | # Copyright 2014 Rackspace Australia |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 15 | import sqlalchemy as sa |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 16 | |
| 17 | from tests.base import ZuulTestCase, ZuulDBTestCase |
| 18 | |
| 19 | |
| 20 | def _get_reporter_from_connection_name(reporters, connection_name): |
| 21 | # Reporters are placed into lists for each action they may exist in. |
| 22 | # Search through the given list for the correct reporter by its conncetion |
| 23 | # name |
| 24 | for r in reporters: |
| 25 | if r.connection.connection_name == connection_name: |
| 26 | return r |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 27 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 28 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 29 | class TestConnections(ZuulTestCase): |
Morgan Fainberg | 4245a42 | 2016-08-05 16:20:12 -0700 | [diff] [blame] | 30 | config_file = 'zuul-connections-same-gerrit.conf' |
| 31 | tenant_config_file = 'config/zuul-connections-same-gerrit/main.yaml' |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 32 | |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 33 | def test_multiple_gerrit_connections(self): |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 34 | "Test multiple connections to the one gerrit" |
| 35 | |
| 36 | A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 7fc8daa | 2016-08-08 15:37:15 -0700 | [diff] [blame] | 37 | self.addEvent('review_gerrit', A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 38 | |
| 39 | self.waitUntilSettled() |
| 40 | |
| 41 | self.assertEqual(len(A.patchsets[-1]['approvals']), 1) |
Tobias Henkel | ea98a19 | 2017-05-29 21:15:17 +0200 | [diff] [blame] | 42 | self.assertEqual(A.patchsets[-1]['approvals'][0]['type'], 'Verified') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 43 | self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1') |
| 44 | self.assertEqual(A.patchsets[-1]['approvals'][0]['by']['username'], |
| 45 | 'jenkins') |
| 46 | |
| 47 | B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 48 | self.executor_server.failJob('project-test2', B) |
James E. Blair | 7fc8daa | 2016-08-08 15:37:15 -0700 | [diff] [blame] | 49 | self.addEvent('review_gerrit', B.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 50 | |
| 51 | self.waitUntilSettled() |
| 52 | |
| 53 | self.assertEqual(len(B.patchsets[-1]['approvals']), 1) |
Tobias Henkel | ea98a19 | 2017-05-29 21:15:17 +0200 | [diff] [blame] | 54 | self.assertEqual(B.patchsets[-1]['approvals'][0]['type'], 'Verified') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 55 | self.assertEqual(B.patchsets[-1]['approvals'][0]['value'], '-1') |
| 56 | self.assertEqual(B.patchsets[-1]['approvals'][0]['by']['username'], |
| 57 | 'civoter') |
| 58 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 59 | |
| 60 | class TestSQLConnection(ZuulDBTestCase): |
| 61 | config_file = 'zuul-sql-driver.conf' |
| 62 | tenant_config_file = 'config/sql-driver/main.yaml' |
| 63 | |
| 64 | def test_sql_tables_created(self, metadata_table=None): |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 65 | "Test the tables for storing results are created properly" |
| 66 | buildset_table = 'zuul_buildset' |
| 67 | build_table = 'zuul_build' |
| 68 | |
| 69 | insp = sa.engine.reflection.Inspector( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 70 | self.connections.connections['resultsdb'].engine) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 71 | |
Tristan Cacqueray | 6467520 | 2017-07-17 06:14:07 +0000 | [diff] [blame] | 72 | self.assertEqual(10, len(insp.get_columns(buildset_table))) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 73 | self.assertEqual(10, len(insp.get_columns(build_table))) |
| 74 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 75 | def test_sql_results(self): |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 76 | "Test results are entered into an sql table" |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 77 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 78 | # Grab the sa tables |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 79 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 80 | reporter = _get_reporter_from_connection_name( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 81 | tenant.layout.pipelines['check'].success_actions, |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 82 | 'resultsdb' |
| 83 | ) |
| 84 | |
| 85 | # Add a success result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 86 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 87 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 88 | self.waitUntilSettled() |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 89 | self.orderedRelease() |
| 90 | self.waitUntilSettled() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 91 | |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 92 | # Add a failed result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 93 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 94 | |
| 95 | self.executor_server.failJob('project-test1', B) |
| 96 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 97 | self.waitUntilSettled() |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 98 | self.orderedRelease() |
| 99 | self.waitUntilSettled() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 100 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 101 | conn = self.connections.connections['resultsdb'].engine.connect() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 102 | result = conn.execute( |
| 103 | sa.sql.select([reporter.connection.zuul_buildset_table])) |
| 104 | |
| 105 | buildsets = result.fetchall() |
| 106 | self.assertEqual(2, len(buildsets)) |
| 107 | buildset0 = buildsets[0] |
| 108 | buildset1 = buildsets[1] |
| 109 | |
| 110 | self.assertEqual('check', buildset0['pipeline']) |
| 111 | self.assertEqual('org/project', buildset0['project']) |
| 112 | self.assertEqual(1, buildset0['change']) |
| 113 | self.assertEqual(1, buildset0['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 114 | self.assertEqual('SUCCESS', buildset0['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 115 | self.assertEqual('Build succeeded.', buildset0['message']) |
Tristan Cacqueray | 6467520 | 2017-07-17 06:14:07 +0000 | [diff] [blame] | 116 | self.assertEqual('tenant-one', buildset0['tenant']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 117 | |
| 118 | buildset0_builds = conn.execute( |
| 119 | sa.sql.select([reporter.connection.zuul_build_table]). |
| 120 | where( |
| 121 | reporter.connection.zuul_build_table.c.buildset_id == |
| 122 | buildset0['id'] |
| 123 | ) |
| 124 | ).fetchall() |
| 125 | |
| 126 | # Check the first result, which should be the project-merge job |
| 127 | self.assertEqual('project-merge', buildset0_builds[0]['job_name']) |
| 128 | self.assertEqual("SUCCESS", buildset0_builds[0]['result']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 129 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 130 | 'finger://{hostname}/{uuid}'.format( |
| 131 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 132 | uuid=buildset0_builds[0]['uuid']), |
| 133 | buildset0_builds[0]['log_url']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 134 | self.assertEqual('check', buildset1['pipeline']) |
| 135 | self.assertEqual('org/project', buildset1['project']) |
| 136 | self.assertEqual(2, buildset1['change']) |
| 137 | self.assertEqual(1, buildset1['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 138 | self.assertEqual('FAILURE', buildset1['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 139 | self.assertEqual('Build failed.', buildset1['message']) |
| 140 | |
| 141 | buildset1_builds = conn.execute( |
| 142 | sa.sql.select([reporter.connection.zuul_build_table]). |
| 143 | where( |
| 144 | reporter.connection.zuul_build_table.c.buildset_id == |
| 145 | buildset1['id'] |
| 146 | ) |
| 147 | ).fetchall() |
| 148 | |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 149 | # Check the second result, which should be the project-test1 job |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 150 | # which failed |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 151 | self.assertEqual('project-test1', buildset1_builds[1]['job_name']) |
| 152 | self.assertEqual("FAILURE", buildset1_builds[1]['result']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 153 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 154 | 'finger://{hostname}/{uuid}'.format( |
| 155 | hostname=self.executor_server.hostname, |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 156 | uuid=buildset1_builds[1]['uuid']), |
| 157 | buildset1_builds[1]['log_url']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 158 | |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 159 | def test_multiple_sql_connections(self): |
| 160 | "Test putting results in different databases" |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 161 | # Add a successful result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 162 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 163 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 164 | self.waitUntilSettled() |
| 165 | |
| 166 | # Add a failed result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 167 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 168 | self.executor_server.failJob('project-test1', B) |
| 169 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 170 | self.waitUntilSettled() |
| 171 | |
| 172 | # Grab the sa tables for resultsdb |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 173 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 174 | reporter1 = _get_reporter_from_connection_name( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 175 | tenant.layout.pipelines['check'].success_actions, |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 176 | 'resultsdb' |
| 177 | ) |
| 178 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 179 | conn = self.connections.connections['resultsdb'].engine.connect() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 180 | buildsets_resultsdb = conn.execute(sa.sql.select( |
| 181 | [reporter1.connection.zuul_buildset_table])).fetchall() |
| 182 | # Should have been 2 buildset reported to the resultsdb (both success |
| 183 | # and failure report) |
| 184 | self.assertEqual(2, len(buildsets_resultsdb)) |
| 185 | |
| 186 | # The first one should have passed |
| 187 | self.assertEqual('check', buildsets_resultsdb[0]['pipeline']) |
| 188 | self.assertEqual('org/project', buildsets_resultsdb[0]['project']) |
| 189 | self.assertEqual(1, buildsets_resultsdb[0]['change']) |
| 190 | self.assertEqual(1, buildsets_resultsdb[0]['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 191 | self.assertEqual('SUCCESS', buildsets_resultsdb[0]['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 192 | self.assertEqual('Build succeeded.', buildsets_resultsdb[0]['message']) |
| 193 | |
| 194 | # Grab the sa tables for resultsdb_failures |
| 195 | reporter2 = _get_reporter_from_connection_name( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 196 | tenant.layout.pipelines['check'].failure_actions, |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 197 | 'resultsdb_failures' |
| 198 | ) |
| 199 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 200 | conn = self.connections.connections['resultsdb_failures'].\ |
| 201 | engine.connect() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 202 | buildsets_resultsdb_failures = conn.execute(sa.sql.select( |
| 203 | [reporter2.connection.zuul_buildset_table])).fetchall() |
| 204 | # The failure db should only have 1 buildset failed |
| 205 | self.assertEqual(1, len(buildsets_resultsdb_failures)) |
| 206 | |
| 207 | self.assertEqual('check', buildsets_resultsdb_failures[0]['pipeline']) |
| 208 | self.assertEqual( |
| 209 | 'org/project', buildsets_resultsdb_failures[0]['project']) |
| 210 | self.assertEqual(2, buildsets_resultsdb_failures[0]['change']) |
| 211 | self.assertEqual(1, buildsets_resultsdb_failures[0]['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 212 | self.assertEqual('FAILURE', buildsets_resultsdb_failures[0]['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 213 | self.assertEqual( |
| 214 | 'Build failed.', buildsets_resultsdb_failures[0]['message']) |
| 215 | |
| 216 | |
| 217 | class TestConnectionsBadSQL(ZuulDBTestCase): |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 218 | config_file = 'zuul-sql-driver-bad.conf' |
| 219 | tenant_config_file = 'config/sql-driver/main.yaml' |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 220 | |
| 221 | def test_unable_to_connect(self): |
| 222 | "Test the SQL reporter fails gracefully when unable to connect" |
| 223 | self.config.set('zuul', 'layout_config', |
| 224 | 'tests/fixtures/layout-sql-reporter.yaml') |
| 225 | self.sched.reconfigure(self.config) |
| 226 | |
| 227 | # Trigger a reporter. If no errors are raised, the reporter has been |
| 228 | # disabled correctly |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 229 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 230 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 231 | self.waitUntilSettled() |
| 232 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 233 | |
| 234 | class TestMultipleGerrits(ZuulTestCase): |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 235 | config_file = 'zuul-connections-multiple-gerrits.conf' |
| 236 | tenant_config_file = 'config/zuul-connections-multiple-gerrits/main.yaml' |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 237 | |
| 238 | def test_multiple_project_separate_gerrits(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 239 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 240 | |
| 241 | A = self.fake_another_gerrit.addFakeChange( |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 242 | 'org/project1', 'master', 'A') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 243 | self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 244 | |
| 245 | self.waitUntilSettled() |
| 246 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 247 | self.assertBuilds([dict(name='project-test2', |
| 248 | changes='1,1', |
| 249 | project='org/project1', |
| 250 | pipeline='another_check')]) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 251 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 252 | # NOTE(jamielennox): the tests back the git repo for both connections |
| 253 | # onto the same git repo on the file system. If we just create another |
| 254 | # fake change the fake_review_gerrit will try to create another 1,1 |
| 255 | # change and git will fail to create the ref. Arbitrarily set it to get |
| 256 | # around the problem. |
| 257 | self.fake_review_gerrit.change_number = 50 |
| 258 | |
| 259 | B = self.fake_review_gerrit.addFakeChange( |
| 260 | 'org/project1', 'master', 'B') |
| 261 | self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 262 | |
| 263 | self.waitUntilSettled() |
| 264 | |
| 265 | self.assertBuilds([ |
| 266 | dict(name='project-test2', |
| 267 | changes='1,1', |
| 268 | project='org/project1', |
| 269 | pipeline='another_check'), |
| 270 | dict(name='project-test1', |
| 271 | changes='51,1', |
| 272 | project='org/project1', |
| 273 | pipeline='review_check'), |
| 274 | ]) |
| 275 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 276 | self.executor_server.hold_jobs_in_build = False |
| 277 | self.executor_server.release() |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 278 | self.waitUntilSettled() |
Tobias Henkel | 7df274b | 2017-05-26 17:41:11 +0200 | [diff] [blame] | 279 | |
Jamie Lennox | b09f421 | 2017-05-03 13:51:38 +1000 | [diff] [blame] | 280 | def test_multiple_project_separate_gerrits_common_pipeline(self): |
| 281 | self.executor_server.hold_jobs_in_build = True |
| 282 | |
| 283 | A = self.fake_another_gerrit.addFakeChange( |
| 284 | 'org/project2', 'master', 'A') |
| 285 | self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 286 | |
| 287 | self.waitUntilSettled() |
| 288 | |
| 289 | self.assertBuilds([dict(name='project-test2', |
| 290 | changes='1,1', |
| 291 | project='org/project2', |
| 292 | pipeline='common_check')]) |
| 293 | |
| 294 | # NOTE(jamielennox): the tests back the git repo for both connections |
| 295 | # onto the same git repo on the file system. If we just create another |
| 296 | # fake change the fake_review_gerrit will try to create another 1,1 |
| 297 | # change and git will fail to create the ref. Arbitrarily set it to get |
| 298 | # around the problem. |
| 299 | self.fake_review_gerrit.change_number = 50 |
| 300 | |
| 301 | B = self.fake_review_gerrit.addFakeChange( |
| 302 | 'org/project2', 'master', 'B') |
| 303 | self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 304 | |
| 305 | self.waitUntilSettled() |
| 306 | |
| 307 | self.assertBuilds([ |
| 308 | dict(name='project-test2', |
| 309 | changes='1,1', |
| 310 | project='org/project2', |
| 311 | pipeline='common_check'), |
| 312 | dict(name='project-test1', |
| 313 | changes='51,1', |
| 314 | project='org/project2', |
| 315 | pipeline='common_check'), |
| 316 | ]) |
| 317 | |
| 318 | self.executor_server.hold_jobs_in_build = False |
| 319 | self.executor_server.release() |
| 320 | self.waitUntilSettled() |
| 321 | |
Tobias Henkel | 7df274b | 2017-05-26 17:41:11 +0200 | [diff] [blame] | 322 | |
| 323 | class TestConnectionsMerger(ZuulTestCase): |
| 324 | config_file = 'zuul-connections-merger.conf' |
| 325 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 326 | |
| 327 | def configure_connections(self): |
| 328 | super(TestConnectionsMerger, self).configure_connections(True) |
| 329 | |
| 330 | def test_connections_merger(self): |
| 331 | "Test merger only configures source connections" |
| 332 | |
| 333 | self.assertIn("gerrit", self.connections.connections) |
| 334 | self.assertIn("github", self.connections.connections) |
| 335 | self.assertNotIn("smtp", self.connections.connections) |
| 336 | self.assertNotIn("sql", self.connections.connections) |
| 337 | self.assertNotIn("timer", self.connections.connections) |
| 338 | self.assertNotIn("zuul", self.connections.connections) |