Fix missing source connections on merger

Change I453754052b75de3d4fac266dc73921c7ce9c075f had the effect that
no source connection was configured in the merger. This can be fixed
by changing the type check from issubclass to isinstance. Further also
the zuul and timer drivers don't need to be configured by the merger.

This also adds a test case for that.

Change-Id: If437123c3e8a0d63c5f852619e214cefa0892ce3
This commit is contained in:
Tobias Henkel 2017-05-26 17:41:11 +02:00
parent 932575741e
commit 7df274be76
4 changed files with 61 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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