diff options
author | James E. Blair <jeblair@hp.com> | 2015-01-08 16:25:28 -0800 |
---|---|---|
committer | James E. Blair <jeblair@hp.com> | 2015-01-08 16:25:28 -0800 |
commit | 217b10d6eb6d449be5338fcd3c5c329403b3e308 (patch) | |
tree | 148a67aea7dfc31871301852d3a4bb416cf3317b | |
parent | 2b4890fa7c299c010ec47ae8441985fd4b530eea (diff) | |
download | zuul-217b10d6eb6d449be5338fcd3c5c329403b3e308.tar.gz |
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
-rw-r--r-- | tests/test_cloner.py | 65 | ||||
-rw-r--r-- | zuul/lib/cloner.py | 4 |
2 files changed, 67 insertions, 2 deletions
diff --git a/tests/test_cloner.py b/tests/test_cloner.py index ab2683d81..a639a52f4 100644 --- a/tests/test_cloner.py +++ b/tests/test_cloner.py @@ -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() diff --git a/zuul/lib/cloner.py b/zuul/lib/cloner.py index 89ebada0e..e0f704b67 100644 --- a/zuul/lib/cloner.py +++ b/zuul/lib/cloner.py @@ -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 {} |