Auto-reconfigure after change-merged event

Rather than respond to the internal report of a change merging,
respond to the change-merged event from the trigger, that way
we will still reconfigure when a change is merged out-of-band.

Change-Id: I684273cad495da7b937f7b80917c7869a0e173d3
This commit is contained in:
James E. Blair 2017-02-20 14:12:01 -05:00
parent 5ac9384d90
commit c2a5ed7942
4 changed files with 23 additions and 6 deletions

View File

@ -263,6 +263,16 @@ class FakeChange(object):
"comment": "This is a comment"}
return event
def getChangeMergedEvent(self):
event = {"submitter": {"name": "Jenkins",
"username": "jenkins"},
"newRev": "29ed3b5f8f750a225c5be70235230e3a6ccb04d9",
"patchSet": self.patchsets[-1],
"change": self.data,
"type": "change-merged",
"eventCreatedOn": 1487613810}
return event
def addApproval(self, category, value, username='reviewer_john',
granted_on=None, message=''):
if not granted_on:

View File

@ -115,6 +115,8 @@ class TestInRepoConfig(AnsibleZuulTestCase):
self.assertHistory([
dict(name='project-test2', result='SUCCESS', changes='1,1')])
self.fake_gerrit.addEvent(A.getChangeMergedEvent())
# Now that the config change is landed, it should be live for
# subsequent changes.
B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')

View File

@ -689,12 +689,6 @@ class PipelineManager(object):
tenant = self.pipeline.layout.tenant
zuul_driver.onChangeMerged(tenant, item.change,
self.pipeline.source)
if item.change.updatesConfig():
# The change that just landed updates the config.
# Clear out cached data for this project and
# perform a reconfiguration.
item.change.project.unparsed_config = None
self.sched.reconfigureTenant(tenant)
def _reportItem(self, item):
self.log.debug("Reporting change %s" % item.change)

View File

@ -744,6 +744,7 @@ class Scheduler(threading.Thread):
self.log.debug("Processing trigger event %s" % event)
try:
for tenant in self.abide.tenants.values():
reconfigured_tenant = False
for pipeline in tenant.layout.pipelines.values():
# Get the change even if the project is unknown to
# us for the use of updating the cache if there is
@ -757,6 +758,16 @@ class Scheduler(threading.Thread):
"connection trigger)",
e.change, pipeline.source)
continue
if (event.type == 'change-merged' and
hasattr(change, 'files') and
not reconfigured_tenant and
change.updatesConfig()):
# The change that just landed updates the config.
# Clear out cached data for this project and
# perform a reconfiguration.
change.project.unparsed_config = None
self.reconfigureTenant(tenant)
reconfigured_tenant = True
if event.type == 'patchset-created':
pipeline.manager.removeOldVersionsOfChange(change)
elif event.type == 'change-abandoned':