diff --git a/tests/base.py b/tests/base.py index 0f8b3af6eb..2bcd1ca19a 100755 --- a/tests/base.py +++ b/tests/base.py @@ -1928,7 +1928,7 @@ class ZuulTestCase(BaseTestCase): self.sched.reconfigure(self.config) self.sched.resume() - def configure_connections(self): + def configure_connections(self, source_only=False): # Set up gerrit related fakes # Set a changes database so multiple FakeGerrit's can report back to # a virtual canonical database given by the configured hostname @@ -1971,7 +1971,7 @@ class ZuulTestCase(BaseTestCase): # Register connections from the config using fakes self.connections = zuul.lib.connections.ConnectionRegistry() - self.connections.configure(self.config) + self.connections.configure(self.config, source_only=source_only) def setup_config(self): # This creates the per-test configuration object. It can be diff --git a/tests/fixtures/zuul-connections-merger.conf b/tests/fixtures/zuul-connections-merger.conf new file mode 100644 index 0000000000..7a1bc42b2a --- /dev/null +++ b/tests/fixtures/zuul-connections-merger.conf @@ -0,0 +1,35 @@ +[gearman] +server=127.0.0.1 + +[zuul] +job_name_in_report=true +status_url=http://zuul.example.com/status + +[merger] +git_dir=/tmp/zuul-test/git +git_user_email=zuul@example.com +git_user_name=zuul +zuul_url=http://zuul.example.com/p + +[executor] +git_dir=/tmp/zuul-test/executor-git + +[connection github] +driver=github + +[connection gerrit] +driver=gerrit +server=review.example.com +user=jenkins +sshkey=fake_id_rsa1 + +[connection resultsdb] +driver=sql +dburi=$MYSQL_FIXTURE_DBURI$ + +[connection smtp] +driver=smtp +server=localhost +port=25 +default_from=zuul@example.com +default_to=you@example.com diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py index db32938281..92270b7320 100644 --- a/tests/unit/test_connection.py +++ b/tests/unit/test_connection.py @@ -265,3 +265,21 @@ class TestMultipleGerrits(ZuulTestCase): self.executor_server.hold_jobs_in_build = False self.executor_server.release() self.waitUntilSettled() + + +class TestConnectionsMerger(ZuulTestCase): + config_file = 'zuul-connections-merger.conf' + tenant_config_file = 'config/single-tenant/main.yaml' + + def configure_connections(self): + super(TestConnectionsMerger, self).configure_connections(True) + + def test_connections_merger(self): + "Test merger only configures source connections" + + self.assertIn("gerrit", self.connections.connections) + self.assertIn("github", self.connections.connections) + self.assertNotIn("smtp", self.connections.connections) + self.assertNotIn("sql", self.connections.connections) + self.assertNotIn("timer", self.connections.connections) + self.assertNotIn("zuul", self.connections.connections) diff --git a/zuul/lib/connections.py b/zuul/lib/connections.py index 720299a0ca..9908fff9e8 100644 --- a/zuul/lib/connections.py +++ b/zuul/lib/connections.py @@ -105,7 +105,7 @@ class ConnectionRegistry(object): # The merger and the reporter only needs source driver. # This makes sure Reporter like the SQLDriver are only created by # the scheduler process - if source_only and not issubclass(driver, SourceInterface): + if source_only and not isinstance(driver, SourceInterface): continue connection = driver.getConnection(con_name, con_config) @@ -138,10 +138,11 @@ class ConnectionRegistry(object): # Create default connections for drivers which need no # connection information (e.g., 'timer' or 'zuul'). - for driver in self.drivers.values(): - if not hasattr(driver, 'getConnection'): - connections[driver.name] = DefaultConnection( - driver, driver.name, {}) + if not source_only: + for driver in self.drivers.values(): + if not hasattr(driver, 'getConnection'): + connections[driver.name] = DefaultConnection( + driver, driver.name, {}) self.connections = connections