Merge "scheduler: Fix event process abide hasUnparsedBranchCache argument"
This commit is contained in:
commit
8a4f99fe57
|
@ -2262,7 +2262,14 @@ class FakeGithubConnection(githubconnection.GithubConnection):
|
|||
return pull_request
|
||||
|
||||
def getPushEvent(self, project, ref, old_rev=None, new_rev=None,
|
||||
added_files=[], removed_files=[], modified_files=[]):
|
||||
added_files=None, removed_files=None,
|
||||
modified_files=None):
|
||||
if added_files is None:
|
||||
added_files = []
|
||||
if removed_files is None:
|
||||
removed_files = []
|
||||
if modified_files is None:
|
||||
modified_files = []
|
||||
if not old_rev:
|
||||
old_rev = '0' * 40
|
||||
if not new_rev:
|
||||
|
|
|
@ -952,13 +952,15 @@ class TestGithubDriver(ZuulTestCase):
|
|||
expect_reconfigure=False,
|
||||
old_sha=None, new_sha=None,
|
||||
modified_files=None,
|
||||
removed_files=None,
|
||||
expected_cat_jobs=None):
|
||||
pevent = self.fake_github.getPushEvent(
|
||||
project=project,
|
||||
ref='refs/heads/%s' % branch,
|
||||
old_rev=old_sha,
|
||||
new_rev=new_sha,
|
||||
modified_files=modified_files)
|
||||
modified_files=modified_files,
|
||||
removed_files=removed_files)
|
||||
|
||||
# record previous tenant reconfiguration time, which may not be set
|
||||
old = self.scheds.first.sched.tenant_last_reconfigured\
|
||||
|
@ -1019,22 +1021,24 @@ class TestGithubDriver(ZuulTestCase):
|
|||
A = self.fake_github.openFakePullRequest(project, branch, 'A')
|
||||
old_sha = A.head_sha
|
||||
A.setMerged("merging A")
|
||||
new_sha = random_sha1()
|
||||
|
||||
self._test_push_event_reconfigure(project, branch,
|
||||
expect_reconfigure=True,
|
||||
old_sha=old_sha,
|
||||
new_sha=new_sha,
|
||||
modified_files=['zuul.yaml'],
|
||||
expected_cat_jobs=1)
|
||||
|
||||
# Check if deleting that branch will not lead to a reconfiguration as
|
||||
# this branch is not protected
|
||||
# there are no exclude-unprotected-branches in the test class, so a
|
||||
# reconfigure shall occur
|
||||
repo._delete_branch(branch)
|
||||
|
||||
self._test_push_event_reconfigure(project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=old_sha,
|
||||
expect_reconfigure=True,
|
||||
old_sha=new_sha,
|
||||
new_sha='0' * 40,
|
||||
modified_files=[])
|
||||
removed_files=['zuul.yaml'])
|
||||
|
||||
# TODO(jlk): Make this a more generic test for unknown project
|
||||
@skip("Skipped for rewrite of webhook handler")
|
||||
|
@ -1113,10 +1117,12 @@ class TestGithubDriver(ZuulTestCase):
|
|||
A = self.fake_github.openFakePullRequest(project, branch, 'A')
|
||||
old_sha = A.head_sha
|
||||
A.setMerged("merging A")
|
||||
new_sha = random_sha1()
|
||||
|
||||
self._test_push_event_reconfigure(project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=old_sha,
|
||||
new_sha=new_sha,
|
||||
modified_files=['README.md'])
|
||||
|
||||
# Check if deleting that branch is ignored as well
|
||||
|
@ -1124,7 +1130,7 @@ class TestGithubDriver(ZuulTestCase):
|
|||
|
||||
self._test_push_event_reconfigure(project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=old_sha,
|
||||
old_sha=new_sha,
|
||||
new_sha='0' * 40,
|
||||
modified_files=['README.md'])
|
||||
|
||||
|
@ -1509,6 +1515,89 @@ class TestGithubUnprotectedBranches(ZuulTestCase):
|
|||
|
||||
self.assertEqual(1, len(self.history))
|
||||
|
||||
def _test_push_event_reconfigure(self, project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=None, new_sha=None,
|
||||
modified_files=None,
|
||||
removed_files=None,
|
||||
expected_cat_jobs=None):
|
||||
pevent = self.fake_github.getPushEvent(
|
||||
project=project,
|
||||
ref='refs/heads/%s' % branch,
|
||||
old_rev=old_sha,
|
||||
new_rev=new_sha,
|
||||
modified_files=modified_files,
|
||||
removed_files=removed_files)
|
||||
|
||||
# record previous tenant reconfiguration time, which may not be set
|
||||
old = self.scheds.first.sched.tenant_last_reconfigured\
|
||||
.get('tenant-one', 0)
|
||||
self.waitUntilSettled()
|
||||
|
||||
if expected_cat_jobs is not None:
|
||||
# clear the gearman jobs history so we can count the cat jobs
|
||||
# issued during reconfiguration
|
||||
self.gearman_server.jobs_history.clear()
|
||||
|
||||
self.fake_github.emitEvent(pevent)
|
||||
self.waitUntilSettled()
|
||||
new = self.scheds.first.sched.tenant_last_reconfigured\
|
||||
.get('tenant-one', 0)
|
||||
|
||||
if expect_reconfigure:
|
||||
# New timestamp should be greater than the old timestamp
|
||||
self.assertLess(old, new)
|
||||
else:
|
||||
# Timestamps should be equal as no reconfiguration shall happen
|
||||
self.assertEqual(old, new)
|
||||
|
||||
if expected_cat_jobs is not None:
|
||||
# Check the expected number of cat jobs here as the (empty) config
|
||||
# of org/project should be cached.
|
||||
cat_jobs = set([job for job in self.gearman_server.jobs_history
|
||||
if job.name == b'merger:cat'])
|
||||
self.assertEqual(expected_cat_jobs, len(cat_jobs), cat_jobs)
|
||||
|
||||
def test_push_event_reconfigure_complex_branch(self):
|
||||
|
||||
branch = 'feature/somefeature'
|
||||
project = 'org/project2'
|
||||
|
||||
# prepare an existing branch
|
||||
self.create_branch(project, branch)
|
||||
|
||||
github = self.fake_github.getGithubClient()
|
||||
repo = github.repo_from_project(project)
|
||||
repo._create_branch(branch)
|
||||
|
||||
self.fake_github.emitEvent(
|
||||
self.fake_github.getPushEvent(
|
||||
project,
|
||||
ref='refs/heads/%s' % branch))
|
||||
self.waitUntilSettled()
|
||||
|
||||
A = self.fake_github.openFakePullRequest(project, branch, 'A')
|
||||
old_sha = A.head_sha
|
||||
A.setMerged("merging A")
|
||||
new_sha = random_sha1()
|
||||
|
||||
# branch is not protected, no reconfiguration even if config file
|
||||
self._test_push_event_reconfigure(project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=old_sha,
|
||||
new_sha=new_sha,
|
||||
modified_files=['zuul.yaml'],
|
||||
expected_cat_jobs=0)
|
||||
|
||||
# branch is not protected: no reconfiguration
|
||||
repo._delete_branch(branch)
|
||||
|
||||
self._test_push_event_reconfigure(project, branch,
|
||||
expect_reconfigure=False,
|
||||
old_sha=new_sha,
|
||||
new_sha='0' * 40,
|
||||
removed_files=['zuul.yaml'])
|
||||
|
||||
|
||||
class TestGithubWebhook(ZuulTestCase):
|
||||
config_file = 'zuul-github-driver.conf'
|
||||
|
|
|
@ -6112,20 +6112,33 @@ For CI problems and help debugging, contact ci@example.org"""
|
|||
A.setMerged()
|
||||
self.fake_gerrit.addEvent(A.getRefUpdatedEvent())
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(len(self.scheds.first.sched.merger.jobs), 1)
|
||||
gearJob = next(iter(self.scheds.first.sched.merger.jobs))
|
||||
self.assertEqual(gearJob.complete, False)
|
||||
|
||||
# Reconfigure while we still have an outstanding merge job
|
||||
self.gearman_server.hold_merge_jobs_in_queue = False
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
(trusted, project1) = tenant.getProject('org/project1')
|
||||
self.scheds.first.sched.reconfigureTenant(
|
||||
self.scheds.first.sched.abide.tenants['tenant-one'], None, None)
|
||||
self.scheds.first.sched.abide.tenants['tenant-one'],
|
||||
project1, None)
|
||||
self.waitUntilSettled()
|
||||
|
||||
# Verify the merge job is still running and that the item is
|
||||
# in the pipeline
|
||||
self.assertEqual(gearJob.complete, False)
|
||||
self.assertEqual(len(self.scheds.first.sched.merger.jobs), 1)
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
|
||||
pipeline = tenant.layout.pipelines['post']
|
||||
self.assertEqual(len(pipeline.getAllItems()), 1)
|
||||
self.gearman_server.hold_merge_jobs_in_queue = False
|
||||
self.gearman_server.release()
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(gearJob.complete, True)
|
||||
self.assertEqual(len(self.scheds.first.sched.merger.jobs), 0)
|
||||
|
||||
@simple_layout('layouts/parent-matchers.yaml')
|
||||
def test_parent_matchers(self):
|
||||
"Test that if a job's parent does not match, the job does not run"
|
||||
|
|
|
@ -451,7 +451,6 @@ class GithubEventProcessor(object):
|
|||
event.trigger_name = 'github'
|
||||
event.project_name = base_repo.get('full_name')
|
||||
event.type = 'push'
|
||||
event.branch_updated = True
|
||||
|
||||
event.ref = self.body.get('ref')
|
||||
event.oldrev = self.body.get('before')
|
||||
|
@ -469,8 +468,10 @@ class GithubEventProcessor(object):
|
|||
# project.
|
||||
if event.oldrev == '0' * 40:
|
||||
event.branch_created = True
|
||||
if event.newrev == '0' * 40:
|
||||
elif event.newrev == '0' * 40:
|
||||
event.branch_deleted = True
|
||||
else:
|
||||
event.branch_updated = True
|
||||
|
||||
if event.branch:
|
||||
project = self.connection.source.getProject(event.project_name)
|
||||
|
|
|
@ -1290,7 +1290,7 @@ class Scheduler(threading.Thread):
|
|||
hasattr(change, 'files') and
|
||||
change.updatesConfig(tenant)) or
|
||||
(event.branch_deleted and
|
||||
self.abide.hasUnparsedBranchCache(event.project_name,
|
||||
self.abide.hasUnparsedBranchCache(project.canonical_name,
|
||||
event.branch))):
|
||||
reconfigure_tenant = True
|
||||
|
||||
|
|
Loading…
Reference in New Issue