Only report to gerrit if the action is from gerrit

When we have multiple sources in the same pipeline we can end up with a
pipeline trying to report to gerrit when the result came from a
different source. Only report to gerrit when the source came from
gerrit.

Change-Id: I26e92002517a86af0d5482fbc73c5dd5b308b363
Signed-off-by: Jamie Lennox <jamielennox@gmail.com>
Co-Authored-By: Tobias Henkel <tobias.henkel@bmw.de>
This commit is contained in:
Jamie Lennox 2017-05-03 13:51:38 +10:00 committed by Tobias Henkel
parent 168bc8fb49
commit b09f421fd0
5 changed files with 89 additions and 1 deletions

View File

@ -24,6 +24,25 @@
another_gerrit:
verified: -1
- pipeline:
name: common_check
manager: independent
trigger:
another_gerrit:
- event: patchset-created
review_gerrit:
- event: patchset-created
success:
review_gerrit:
verified: 1
another_gerrit:
verified: 1
failure:
review_gerrit:
verified: -1
another_gerrit:
verified: -1
- job:
name: project-test1
@ -41,3 +60,16 @@
another_check:
jobs:
- project-test2
- project:
name: review.example.com/org/project2
common_check:
jobs:
- project-test1
- project:
name: another.example.com/org/project2
common_check:
jobs:
- project-test2

View File

@ -0,0 +1 @@
test

View File

@ -6,6 +6,8 @@
- common-config
untrusted-projects:
- org/project1
- org/project2
another_gerrit:
untrusted-projects:
- org/project1
- org/project2

View File

@ -266,6 +266,48 @@ class TestMultipleGerrits(ZuulTestCase):
self.executor_server.release()
self.waitUntilSettled()
def test_multiple_project_separate_gerrits_common_pipeline(self):
self.executor_server.hold_jobs_in_build = True
A = self.fake_another_gerrit.addFakeChange(
'org/project2', 'master', 'A')
self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertBuilds([dict(name='project-test2',
changes='1,1',
project='org/project2',
pipeline='common_check')])
# NOTE(jamielennox): the tests back the git repo for both connections
# onto the same git repo on the file system. If we just create another
# fake change the fake_review_gerrit will try to create another 1,1
# change and git will fail to create the ref. Arbitrarily set it to get
# around the problem.
self.fake_review_gerrit.change_number = 50
B = self.fake_review_gerrit.addFakeChange(
'org/project2', 'master', 'B')
self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertBuilds([
dict(name='project-test2',
changes='1,1',
project='org/project2',
pipeline='common_check'),
dict(name='project-test1',
changes='51,1',
project='org/project2',
pipeline='common_check'),
])
self.executor_server.hold_jobs_in_build = False
self.executor_server.release()
self.waitUntilSettled()
class TestConnectionsMerger(ZuulTestCase):
config_file = 'zuul-connections-merger.conf'

View File

@ -15,7 +15,7 @@
import logging
import voluptuous as v
from zuul.driver.gerrit.gerritsource import GerritSource
from zuul.reporter import BaseReporter
@ -27,6 +27,17 @@ class GerritReporter(BaseReporter):
def report(self, pipeline, item):
"""Send a message to gerrit."""
# If the source is no GerritSource we cannot report anything here.
if not isinstance(item.change.project.source, GerritSource):
return
# For supporting several Gerrit connections we also must filter by
# the canonical hostname.
if item.change.project.source.connection.canonical_hostname != \
self.connection.canonical_hostname:
return
message = self._formatItemReport(pipeline, item)
self.log.debug("Report change %s, params %s, message: %s" %