Browse Source

Add in extra connections tests

Test reporting back to gerrit as a different user.
Test multiple gerrit instances.

Squashed with: Assign fake connections to test class dynamically

As multiple connections can be configured for testing purposes, it makes
more sense to be able to access them all comfortably.

Drawback of this change is, that the dynamicism makes the code less
readable and less obvious.
Previously: If50567dd5a087e9fe46cd4e30f9e0562cda794d7

Co-Authored-By: Jan Hruban <jan.hruban@gooddata.com>

Change-Id: I4652799c8b9a626bd2f7f6996d09c95da2953936
changes/00/169300/31
Joshua Hesketh 7 years ago
parent
commit
acccffce61
  1. 24
      tests/base.py
  2. 37
      tests/fixtures/layout-connections-multiple-gerrits.yaml
  3. 20
      tests/fixtures/layout-connections-multiple-voters.yaml
  4. 42
      tests/fixtures/zuul-connections-multiple-gerrits.conf
  5. 42
      tests/fixtures/zuul-connections-same-gerrit.conf
  6. 59
      tests/test_connection.py

24
tests/base.py

@ -884,7 +884,8 @@ class ZuulTestCase(BaseTestCase):
# Make per test copy of Configuration.
self.setup_config()
self.config.set('zuul', 'layout_config',
os.path.join(FIXTURE_DIR, "layout.yaml"))
os.path.join(FIXTURE_DIR,
self.config.get('zuul', 'layout_config')))
self.config.set('merger', 'git_dir', self.git_root)
# For each project in config:
@ -938,10 +939,8 @@ class ZuulTestCase(BaseTestCase):
self.sched.trigger_event_queue
]
# Set up connections and give out the default gerrit for testing
self.configure_connections()
self.sched.registerConnections(self.connections)
self.fake_gerrit = self.connections['gerrit']
def URLOpenerFactory(*args, **kw):
if isinstance(args[0], urllib2.Request):
@ -1011,15 +1010,20 @@ class ZuulTestCase(BaseTestCase):
# TODO(jhesketh): load the required class automatically
if con_driver == 'gerrit':
self.gerrit_changes_dbs[con_name] = {}
self.gerrit_queues_dbs[con_name] = Queue.Queue()
self.event_queues.append(self.gerrit_queues_dbs['gerrit'])
if con_config['server'] not in self.gerrit_changes_dbs.keys():
self.gerrit_changes_dbs[con_config['server']] = {}
if con_config['server'] not in self.gerrit_queues_dbs.keys():
self.gerrit_queues_dbs[con_config['server']] = \
Queue.Queue()
self.event_queues.append(
self.gerrit_queues_dbs[con_config['server']])
self.connections[con_name] = FakeGerritConnection(
con_name, con_config,
changes_db=self.gerrit_changes_dbs[con_name],
queues_db=self.gerrit_queues_dbs[con_name],
changes_db=self.gerrit_changes_dbs[con_config['server']],
queues_db=self.gerrit_queues_dbs[con_config['server']],
upstream_root=self.upstream_root
)
setattr(self, 'fake_' + con_name, self.connections[con_name])
elif con_driver == 'smtp':
self.connections[con_name] = \
zuul.connection.smtp.SMTPConnection(con_name, con_config)
@ -1044,10 +1048,10 @@ class ZuulTestCase(BaseTestCase):
zuul.connection.smtp.SMTPConnection(
'_legacy_smtp', dict(self.config.items('smtp')))
def setup_config(self):
def setup_config(self, config_file='zuul.conf'):
"""Per test config object. Override to set different config."""
self.config = ConfigParser.ConfigParser()
self.config.read(os.path.join(FIXTURE_DIR, "zuul.conf"))
self.config.read(os.path.join(FIXTURE_DIR, config_file))
def assertFinalState(self):
# Make sure that git.Repo objects have been garbage collected.

37
tests/fixtures/layout-connections-multiple-gerrits.yaml

@ -0,0 +1,37 @@
pipelines:
- name: check
manager: IndependentPipelineManager
source: review_gerrit
trigger:
review_gerrit:
- event: patchset-created
success:
review_gerrit:
VRFY: 1
failure:
review_gerrit:
VRFY: -1
- name: another_check
manager: IndependentPipelineManager
source: another_gerrit
trigger:
another_gerrit:
- event: patchset-created
success:
another_gerrit:
VRFY: 1
failure:
another_gerrit:
VRFY: -1
projects:
- name: org/project
check:
- project-review-gerrit
another_check:
- project-another-gerrit
- name: org/project1
another_check:
- project1-another-gerrit

20
tests/fixtures/layout-connections-multiple-voters.yaml

@ -0,0 +1,20 @@
pipelines:
- name: check
manager: IndependentPipelineManager
source: review_gerrit
trigger:
review_gerrit:
- event: patchset-created
success:
review_gerrit:
VRFY: 1
failure:
alt_voting_gerrit:
VRFY: -1
projects:
- name: org/project
check:
- project-merge:
- project-test1
- project-test2

42
tests/fixtures/zuul-connections-multiple-gerrits.conf

@ -0,0 +1,42 @@
[gearman]
server=127.0.0.1
[zuul]
layout_config=layout-connections-multiple-voters.yaml
url_pattern=http://logs.example.com/{change.number}/{change.patchset}/{pipeline.name}/{job.name}/{build.number}
job_name_in_report=true
[merger]
git_dir=/tmp/zuul-test/git
git_user_email=zuul@example.com
git_user_name=zuul
zuul_url=http://zuul.example.com/p
[swift]
authurl=https://identity.api.example.org/v2.0/
user=username
key=password
tenant_name=" "
default_container=logs
region_name=EXP
logserver_prefix=http://logs.example.org/server.app/
[connection review_gerrit]
driver=gerrit
server=review.example.com
user=jenkins
sshkey=none
[connection another_gerrit]
driver=gerrit
server=another.example.com
user=jenkins
sshkey=none
[connection outgoing_smtp]
driver=smtp
server=localhost
port=25
default_from=zuul@example.com
default_to=you@example.com

42
tests/fixtures/zuul-connections-same-gerrit.conf

@ -0,0 +1,42 @@
[gearman]
server=127.0.0.1
[zuul]
layout_config=layout-connections-multiple-voters.yaml
url_pattern=http://logs.example.com/{change.number}/{change.patchset}/{pipeline.name}/{job.name}/{build.number}
job_name_in_report=true
[merger]
git_dir=/tmp/zuul-test/git
git_user_email=zuul@example.com
git_user_name=zuul
zuul_url=http://zuul.example.com/p
[swift]
authurl=https://identity.api.example.org/v2.0/
user=username
key=password
tenant_name=" "
default_container=logs
region_name=EXP
logserver_prefix=http://logs.example.org/server.app/
[connection review_gerrit]
driver=gerrit
server=review.example.com
user=jenkins
sshkey=none
[connection alt_voting_gerrit]
driver=gerrit
server=review.example.com
user=civoter
sshkey=none
[connection outgoing_smtp]
driver=smtp
server=localhost
port=25
default_from=zuul@example.com
default_to=you@example.com

59
tests/test_connection.py

@ -17,6 +17,8 @@ import testtools
import zuul.connection.gerrit
from tests.base import ZuulTestCase
class TestGerritConnection(testtools.TestCase):
log = logging.getLogger("zuul.test_connection")
@ -24,3 +26,60 @@ class TestGerritConnection(testtools.TestCase):
def test_driver_name(self):
self.assertEqual('gerrit',
zuul.connection.gerrit.GerritConnection.driver_name)
class TestConnections(ZuulTestCase):
def setup_config(self, config_file='zuul-connections-same-gerrit.conf'):
super(TestConnections, self).setup_config(config_file)
def test_multiple_connections(self):
"Test multiple connections to the one gerrit"
A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A')
self.fake_review_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertEqual(len(A.patchsets[-1]['approvals']), 1)
self.assertEqual(A.patchsets[-1]['approvals'][0]['type'], 'VRFY')
self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1')
self.assertEqual(A.patchsets[-1]['approvals'][0]['by']['username'],
'jenkins')
B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B')
self.worker.addFailTest('project-test2', B)
self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertEqual(len(B.patchsets[-1]['approvals']), 1)
self.assertEqual(B.patchsets[-1]['approvals'][0]['type'], 'VRFY')
self.assertEqual(B.patchsets[-1]['approvals'][0]['value'], '-1')
self.assertEqual(B.patchsets[-1]['approvals'][0]['by']['username'],
'civoter')
class TestMultipleGerrits(ZuulTestCase):
def setup_config(self,
config_file='zuul-connections-multiple-gerrits.conf'):
super(TestMultipleGerrits, self).setup_config(config_file)
self.config.set(
'zuul', 'layout_config',
'layout-connections-multiple-gerrits.yaml')
def test_multiple_project_separate_gerrits(self):
self.worker.hold_jobs_in_build = True
A = self.fake_another_gerrit.addFakeChange(
'org/project', 'master', 'A')
self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertEqual(1, len(self.builds))
self.assertEqual('project-another-gerrit', self.builds[0].name)
self.assertTrue(self.job_has_changes(self.builds[0], A))
self.worker.hold_jobs_in_build = False
self.worker.release()
self.waitUntilSettled()
Loading…
Cancel
Save