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' |
Tobias Henkel | 94a1d08 | 2017-12-09 12:24:52 +0100 | [diff] [blame] | 63 | expected_table_prefix = '' |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 64 | |
Tobias Henkel | 94a1d08 | 2017-12-09 12:24:52 +0100 | [diff] [blame] | 65 | def test_sql_tables_created(self): |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 66 | "Test the tables for storing results are created properly" |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 67 | |
Tobias Henkel | 94a1d08 | 2017-12-09 12:24:52 +0100 | [diff] [blame] | 68 | connection = self.connections.connections['resultsdb'] |
| 69 | insp = sa.engine.reflection.Inspector(connection.engine) |
| 70 | |
| 71 | table_prefix = connection.table_prefix |
| 72 | self.assertEqual(self.expected_table_prefix, table_prefix) |
| 73 | |
| 74 | buildset_table = table_prefix + 'zuul_buildset' |
| 75 | build_table = table_prefix + 'zuul_build' |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 76 | |
Tristan Cacqueray | 8198c0e | 2017-09-27 19:01:18 +0000 | [diff] [blame] | 77 | self.assertEqual(13, len(insp.get_columns(buildset_table))) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 78 | self.assertEqual(10, len(insp.get_columns(build_table))) |
| 79 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 80 | def test_sql_results(self): |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 81 | "Test results are entered into an sql table" |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 82 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 83 | # Grab the sa tables |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 84 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 85 | reporter = _get_reporter_from_connection_name( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 86 | tenant.layout.pipelines['check'].success_actions, |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 87 | 'resultsdb' |
| 88 | ) |
| 89 | |
| 90 | # Add a success result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 91 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 92 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 93 | self.waitUntilSettled() |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 94 | self.orderedRelease() |
| 95 | self.waitUntilSettled() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 96 | |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 97 | # Add a failed result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 98 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 99 | |
| 100 | self.executor_server.failJob('project-test1', B) |
| 101 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 102 | self.waitUntilSettled() |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 103 | self.orderedRelease() |
| 104 | self.waitUntilSettled() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 105 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 106 | conn = self.connections.connections['resultsdb'].engine.connect() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 107 | result = conn.execute( |
| 108 | sa.sql.select([reporter.connection.zuul_buildset_table])) |
| 109 | |
| 110 | buildsets = result.fetchall() |
| 111 | self.assertEqual(2, len(buildsets)) |
| 112 | buildset0 = buildsets[0] |
| 113 | buildset1 = buildsets[1] |
| 114 | |
| 115 | self.assertEqual('check', buildset0['pipeline']) |
| 116 | self.assertEqual('org/project', buildset0['project']) |
| 117 | self.assertEqual(1, buildset0['change']) |
| 118 | self.assertEqual(1, buildset0['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 119 | self.assertEqual('SUCCESS', buildset0['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 120 | self.assertEqual('Build succeeded.', buildset0['message']) |
Tristan Cacqueray | 6467520 | 2017-07-17 06:14:07 +0000 | [diff] [blame] | 121 | self.assertEqual('tenant-one', buildset0['tenant']) |
Tristan Cacqueray | 305a215 | 2017-09-12 23:09:34 +0000 | [diff] [blame] | 122 | self.assertEqual('https://hostname/%d' % buildset0['change'], |
| 123 | buildset0['ref_url']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 124 | |
| 125 | buildset0_builds = conn.execute( |
| 126 | sa.sql.select([reporter.connection.zuul_build_table]). |
| 127 | where( |
| 128 | reporter.connection.zuul_build_table.c.buildset_id == |
| 129 | buildset0['id'] |
| 130 | ) |
| 131 | ).fetchall() |
| 132 | |
| 133 | # Check the first result, which should be the project-merge job |
| 134 | self.assertEqual('project-merge', buildset0_builds[0]['job_name']) |
| 135 | self.assertEqual("SUCCESS", buildset0_builds[0]['result']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 136 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 137 | 'finger://{hostname}/{uuid}'.format( |
| 138 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 139 | uuid=buildset0_builds[0]['uuid']), |
| 140 | buildset0_builds[0]['log_url']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 141 | self.assertEqual('check', buildset1['pipeline']) |
| 142 | self.assertEqual('org/project', buildset1['project']) |
| 143 | self.assertEqual(2, buildset1['change']) |
| 144 | self.assertEqual(1, buildset1['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 145 | self.assertEqual('FAILURE', buildset1['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 146 | self.assertEqual('Build failed.', buildset1['message']) |
| 147 | |
| 148 | buildset1_builds = conn.execute( |
| 149 | sa.sql.select([reporter.connection.zuul_build_table]). |
| 150 | where( |
| 151 | reporter.connection.zuul_build_table.c.buildset_id == |
| 152 | buildset1['id'] |
| 153 | ) |
| 154 | ).fetchall() |
| 155 | |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 156 | # Check the second result, which should be the project-test1 job |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 157 | # which failed |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 158 | self.assertEqual('project-test1', buildset1_builds[1]['job_name']) |
| 159 | self.assertEqual("FAILURE", buildset1_builds[1]['result']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 160 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 161 | 'finger://{hostname}/{uuid}'.format( |
| 162 | hostname=self.executor_server.hostname, |
James E. Blair | 66e0413 | 2017-09-28 17:10:25 -0700 | [diff] [blame] | 163 | uuid=buildset1_builds[1]['uuid']), |
| 164 | buildset1_builds[1]['log_url']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 165 | |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 166 | def test_multiple_sql_connections(self): |
| 167 | "Test putting results in different databases" |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 168 | # Add a successful result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 169 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 170 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 171 | self.waitUntilSettled() |
| 172 | |
| 173 | # Add a failed result |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 174 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 175 | self.executor_server.failJob('project-test1', B) |
| 176 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 177 | self.waitUntilSettled() |
| 178 | |
| 179 | # Grab the sa tables for resultsdb |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 180 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 181 | reporter1 = _get_reporter_from_connection_name( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 182 | tenant.layout.pipelines['check'].success_actions, |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 183 | 'resultsdb' |
| 184 | ) |
| 185 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 186 | conn = self.connections.connections['resultsdb'].engine.connect() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 187 | buildsets_resultsdb = conn.execute(sa.sql.select( |
| 188 | [reporter1.connection.zuul_buildset_table])).fetchall() |
| 189 | # Should have been 2 buildset reported to the resultsdb (both success |
| 190 | # and failure report) |
| 191 | self.assertEqual(2, len(buildsets_resultsdb)) |
| 192 | |
| 193 | # The first one should have passed |
| 194 | self.assertEqual('check', buildsets_resultsdb[0]['pipeline']) |
| 195 | self.assertEqual('org/project', buildsets_resultsdb[0]['project']) |
| 196 | self.assertEqual(1, buildsets_resultsdb[0]['change']) |
| 197 | self.assertEqual(1, buildsets_resultsdb[0]['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 198 | self.assertEqual('SUCCESS', buildsets_resultsdb[0]['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 199 | self.assertEqual('Build succeeded.', buildsets_resultsdb[0]['message']) |
| 200 | |
| 201 | # Grab the sa tables for resultsdb_failures |
| 202 | reporter2 = _get_reporter_from_connection_name( |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 203 | tenant.layout.pipelines['check'].failure_actions, |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 204 | 'resultsdb_failures' |
| 205 | ) |
| 206 | |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 207 | conn = self.connections.connections['resultsdb_failures'].\ |
| 208 | engine.connect() |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 209 | buildsets_resultsdb_failures = conn.execute(sa.sql.select( |
| 210 | [reporter2.connection.zuul_buildset_table])).fetchall() |
| 211 | # The failure db should only have 1 buildset failed |
| 212 | self.assertEqual(1, len(buildsets_resultsdb_failures)) |
| 213 | |
| 214 | self.assertEqual('check', buildsets_resultsdb_failures[0]['pipeline']) |
| 215 | self.assertEqual( |
| 216 | 'org/project', buildsets_resultsdb_failures[0]['project']) |
| 217 | self.assertEqual(2, buildsets_resultsdb_failures[0]['change']) |
| 218 | self.assertEqual(1, buildsets_resultsdb_failures[0]['patchset']) |
Monty Taylor | 40f7f4d | 2017-07-27 17:27:43 -0500 | [diff] [blame] | 219 | self.assertEqual('FAILURE', buildsets_resultsdb_failures[0]['result']) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 220 | self.assertEqual( |
| 221 | 'Build failed.', buildsets_resultsdb_failures[0]['message']) |
| 222 | |
| 223 | |
Tobias Henkel | 94a1d08 | 2017-12-09 12:24:52 +0100 | [diff] [blame] | 224 | class TestSQLConnectionPrefix(TestSQLConnection): |
| 225 | config_file = 'zuul-sql-driver-prefix.conf' |
| 226 | expected_table_prefix = 'prefix_' |
| 227 | |
| 228 | |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 229 | class TestConnectionsBadSQL(ZuulDBTestCase): |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 230 | config_file = 'zuul-sql-driver-bad.conf' |
| 231 | tenant_config_file = 'config/sql-driver/main.yaml' |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 232 | |
| 233 | def test_unable_to_connect(self): |
| 234 | "Test the SQL reporter fails gracefully when unable to connect" |
| 235 | self.config.set('zuul', 'layout_config', |
| 236 | 'tests/fixtures/layout-sql-reporter.yaml') |
| 237 | self.sched.reconfigure(self.config) |
| 238 | |
| 239 | # Trigger a reporter. If no errors are raised, the reporter has been |
| 240 | # disabled correctly |
James E. Blair | 8284489 | 2017-03-06 10:55:26 -0800 | [diff] [blame] | 241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 242 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | d78b448 | 2015-09-14 16:56:34 -0600 | [diff] [blame] | 243 | self.waitUntilSettled() |
| 244 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 245 | |
| 246 | class TestMultipleGerrits(ZuulTestCase): |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 247 | config_file = 'zuul-connections-multiple-gerrits.conf' |
| 248 | tenant_config_file = 'config/zuul-connections-multiple-gerrits/main.yaml' |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 249 | |
| 250 | def test_multiple_project_separate_gerrits(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 251 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 252 | |
| 253 | A = self.fake_another_gerrit.addFakeChange( |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 254 | 'org/project1', 'master', 'A') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 255 | self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 256 | |
| 257 | self.waitUntilSettled() |
| 258 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 259 | self.assertBuilds([dict(name='project-test2', |
| 260 | changes='1,1', |
| 261 | project='org/project1', |
| 262 | pipeline='another_check')]) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 263 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 264 | # NOTE(jamielennox): the tests back the git repo for both connections |
| 265 | # onto the same git repo on the file system. If we just create another |
| 266 | # fake change the fake_review_gerrit will try to create another 1,1 |
| 267 | # change and git will fail to create the ref. Arbitrarily set it to get |
| 268 | # around the problem. |
| 269 | self.fake_review_gerrit.change_number = 50 |
| 270 | |
| 271 | B = self.fake_review_gerrit.addFakeChange( |
| 272 | 'org/project1', 'master', 'B') |
| 273 | self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 274 | |
| 275 | self.waitUntilSettled() |
| 276 | |
| 277 | self.assertBuilds([ |
| 278 | dict(name='project-test2', |
| 279 | changes='1,1', |
| 280 | project='org/project1', |
| 281 | pipeline='another_check'), |
| 282 | dict(name='project-test1', |
| 283 | changes='51,1', |
| 284 | project='org/project1', |
| 285 | pipeline='review_check'), |
| 286 | ]) |
| 287 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 288 | self.executor_server.hold_jobs_in_build = False |
| 289 | self.executor_server.release() |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 290 | self.waitUntilSettled() |
Tobias Henkel | 7df274b | 2017-05-26 17:41:11 +0200 | [diff] [blame] | 291 | |
Jamie Lennox | b09f421 | 2017-05-03 13:51:38 +1000 | [diff] [blame] | 292 | def test_multiple_project_separate_gerrits_common_pipeline(self): |
| 293 | self.executor_server.hold_jobs_in_build = True |
| 294 | |
| 295 | A = self.fake_another_gerrit.addFakeChange( |
| 296 | 'org/project2', 'master', 'A') |
| 297 | self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 298 | |
| 299 | self.waitUntilSettled() |
| 300 | |
| 301 | self.assertBuilds([dict(name='project-test2', |
| 302 | changes='1,1', |
| 303 | project='org/project2', |
| 304 | pipeline='common_check')]) |
| 305 | |
| 306 | # NOTE(jamielennox): the tests back the git repo for both connections |
| 307 | # onto the same git repo on the file system. If we just create another |
| 308 | # fake change the fake_review_gerrit will try to create another 1,1 |
| 309 | # change and git will fail to create the ref. Arbitrarily set it to get |
| 310 | # around the problem. |
| 311 | self.fake_review_gerrit.change_number = 50 |
| 312 | |
| 313 | B = self.fake_review_gerrit.addFakeChange( |
| 314 | 'org/project2', 'master', 'B') |
| 315 | self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 316 | |
| 317 | self.waitUntilSettled() |
| 318 | |
| 319 | self.assertBuilds([ |
| 320 | dict(name='project-test2', |
| 321 | changes='1,1', |
| 322 | project='org/project2', |
| 323 | pipeline='common_check'), |
| 324 | dict(name='project-test1', |
| 325 | changes='51,1', |
| 326 | project='org/project2', |
| 327 | pipeline='common_check'), |
| 328 | ]) |
| 329 | |
| 330 | self.executor_server.hold_jobs_in_build = False |
| 331 | self.executor_server.release() |
| 332 | self.waitUntilSettled() |
| 333 | |
Tobias Henkel | 7df274b | 2017-05-26 17:41:11 +0200 | [diff] [blame] | 334 | |
| 335 | class TestConnectionsMerger(ZuulTestCase): |
| 336 | config_file = 'zuul-connections-merger.conf' |
| 337 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 338 | |
| 339 | def configure_connections(self): |
| 340 | super(TestConnectionsMerger, self).configure_connections(True) |
| 341 | |
| 342 | def test_connections_merger(self): |
| 343 | "Test merger only configures source connections" |
| 344 | |
| 345 | self.assertIn("gerrit", self.connections.connections) |
| 346 | self.assertIn("github", self.connections.connections) |
| 347 | self.assertNotIn("smtp", self.connections.connections) |
| 348 | self.assertNotIn("sql", self.connections.connections) |
| 349 | self.assertNotIn("timer", self.connections.connections) |
| 350 | self.assertNotIn("zuul", self.connections.connections) |
Clark Boylan | a7f724c | 2017-10-25 11:35:19 -0700 | [diff] [blame] | 351 | |
| 352 | |
| 353 | class TestConnectionsCgit(ZuulTestCase): |
| 354 | config_file = 'zuul-connections-cgit.conf' |
| 355 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 356 | |
| 357 | def test_cgit_web_url(self): |
| 358 | self.assertIn("gerrit", self.connections.connections) |
| 359 | conn = self.connections.connections['gerrit'] |
| 360 | source = conn.source |
| 361 | proj = source.getProject('foo/bar') |
| 362 | url = conn._getWebUrl(proj, '1') |
| 363 | self.assertEqual(url, |
| 364 | 'https://cgit.example.com/cgit/foo/bar/commit/?id=1') |
| 365 | |
| 366 | |
| 367 | class TestConnectionsGitweb(ZuulTestCase): |
| 368 | config_file = 'zuul-connections-gitweb.conf' |
| 369 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 370 | |
| 371 | def test_gitweb_url(self): |
| 372 | self.assertIn("gerrit", self.connections.connections) |
| 373 | conn = self.connections.connections['gerrit'] |
| 374 | source = conn.source |
| 375 | proj = source.getProject('foo/bar') |
| 376 | url = conn._getWebUrl(proj, '1') |
| 377 | url_should_be = 'https://review.example.com/' \ |
| 378 | 'gitweb?p=foo/bar.git;a=commitdiff;h=1' |
| 379 | self.assertEqual(url, url_should_be) |