Cloner: handle missing ZUUL_BRANCH/_REF
Periodic jobs currently trigger without a ZUUL_BRANCH or ZUUL_REF variable set. (We should change this, but that's a more complex change). So that the cloner can be used in this situation, set those to the empty string if their value is None (ie, unset). Periodoc jobs can then invoke the cloner as normal, with branch override values set, and those will be used as the selected branch. This is how OpenStack's periodic branch jobs currently work. In the future, if Zuul itself performs branch selection on jobs, this will provide a graceful migration path by allowing the ZUUL_BRANCH values to act as a fallback and then the overrides can be removed. Add a test to validate this usage. Change-Id: Ie680b9c11cebec7410ef7b0edc9d1017ae8b847e
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import git
|
||||
|
||||
@@ -481,3 +482,67 @@ class TestCloner(ZuulTestCase):
|
||||
self.worker.hold_jobs_in_build = False
|
||||
self.worker.release()
|
||||
self.waitUntilSettled()
|
||||
|
||||
def test_periodic(self):
|
||||
self.worker.hold_jobs_in_build = True
|
||||
self.create_branch('org/project', 'stable/havana')
|
||||
self.config.set('zuul', 'layout_config',
|
||||
'tests/fixtures/layout-timer.yaml')
|
||||
self.sched.reconfigure(self.config)
|
||||
self.registerJobs()
|
||||
|
||||
# The pipeline triggers every second, so we should have seen
|
||||
# several by now.
|
||||
time.sleep(5)
|
||||
self.waitUntilSettled()
|
||||
|
||||
builds = self.builds[:]
|
||||
|
||||
self.worker.hold_jobs_in_build = False
|
||||
# Stop queuing timer triggered jobs so that the assertions
|
||||
# below don't race against more jobs being queued.
|
||||
self.config.set('zuul', 'layout_config',
|
||||
'tests/fixtures/layout-no-timer.yaml')
|
||||
self.sched.reconfigure(self.config)
|
||||
self.registerJobs()
|
||||
self.worker.release()
|
||||
self.waitUntilSettled()
|
||||
|
||||
projects = ['org/project']
|
||||
|
||||
self.assertEquals(2, len(builds), "Two builds are running")
|
||||
|
||||
upstream = self.getUpstreamRepos(projects)
|
||||
states = [
|
||||
{'org/project': str(upstream['org/project'].commit('stable/havana')),
|
||||
},
|
||||
{'org/project': str(upstream['org/project'].commit('stable/havana')),
|
||||
},
|
||||
]
|
||||
|
||||
for number, build in enumerate(builds):
|
||||
self.log.debug("Build parameters: %s", build.parameters)
|
||||
cloner = zuul.lib.cloner.Cloner(
|
||||
git_base_url=self.upstream_root,
|
||||
projects=projects,
|
||||
workspace=self.workspace_root,
|
||||
zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
|
||||
zuul_ref=build.parameters.get('ZUUL_REF', None),
|
||||
zuul_url=self.git_root,
|
||||
branch='stable/havana',
|
||||
)
|
||||
cloner.execute()
|
||||
work = self.getWorkspaceRepos(projects)
|
||||
state = states[number]
|
||||
|
||||
for project in projects:
|
||||
self.assertEquals(state[project],
|
||||
str(work[project].commit('HEAD')),
|
||||
'Project %s commit for build %s should '
|
||||
'be correct' % (project, number))
|
||||
|
||||
shutil.rmtree(self.workspace_root)
|
||||
|
||||
self.worker.hold_jobs_in_build = False
|
||||
self.worker.release()
|
||||
self.waitUntilSettled()
|
||||
|
||||
@@ -39,8 +39,8 @@ class Cloner(object):
|
||||
self.cache_dir = cache_dir
|
||||
self.projects = projects
|
||||
self.workspace = workspace
|
||||
self.zuul_branch = zuul_branch
|
||||
self.zuul_ref = zuul_ref
|
||||
self.zuul_branch = zuul_branch or ''
|
||||
self.zuul_ref = zuul_ref or ''
|
||||
self.zuul_url = zuul_url
|
||||
self.project_branches = project_branches or {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user