|
|
|
@ -89,6 +89,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters['ZUUL_BRANCH'],
|
|
|
|
|
zuul_ref=build.parameters['ZUUL_REF'],
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -105,11 +106,34 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
'be correct' % (project, number))
|
|
|
|
|
|
|
|
|
|
work = self.getWorkspaceRepos(projects)
|
|
|
|
|
upstream_repo_path = os.path.join(self.upstream_root, 'org/project1')
|
|
|
|
|
self.assertEquals(
|
|
|
|
|
# project1 is the zuul_project so the origin should be set to the
|
|
|
|
|
# zuul_url since that is the most up to date.
|
|
|
|
|
cache_repo_path = os.path.join(cache_root, 'org/project1')
|
|
|
|
|
self.assertNotEqual(
|
|
|
|
|
work['org/project1'].remotes.origin.url,
|
|
|
|
|
cache_repo_path,
|
|
|
|
|
'workspace repo origin should not be the cache'
|
|
|
|
|
)
|
|
|
|
|
zuul_url_repo_path = os.path.join(self.git_root, 'org/project1')
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
work['org/project1'].remotes.origin.url,
|
|
|
|
|
zuul_url_repo_path,
|
|
|
|
|
'workspace repo origin should be the zuul url'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# project2 is not the zuul_project so the origin should be set
|
|
|
|
|
# to upstream since that is the best we can do
|
|
|
|
|
cache_repo_path = os.path.join(cache_root, 'org/project2')
|
|
|
|
|
self.assertNotEqual(
|
|
|
|
|
work['org/project2'].remotes.origin.url,
|
|
|
|
|
cache_repo_path,
|
|
|
|
|
'workspace repo origin should not be the cache'
|
|
|
|
|
)
|
|
|
|
|
upstream_repo_path = os.path.join(self.upstream_root, 'org/project2')
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
work['org/project2'].remotes.origin.url,
|
|
|
|
|
upstream_repo_path,
|
|
|
|
|
'workspace repo origin should be upstream, not cache'
|
|
|
|
|
'workspace repo origin should be the upstream url'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.worker.hold_jobs_in_build = False
|
|
|
|
@ -147,6 +171,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters['ZUUL_BRANCH'],
|
|
|
|
|
zuul_ref=build.parameters['ZUUL_REF'],
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -217,6 +242,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters['ZUUL_BRANCH'],
|
|
|
|
|
zuul_ref=build.parameters['ZUUL_REF'],
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -331,6 +357,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters['ZUUL_BRANCH'],
|
|
|
|
|
zuul_ref=build.parameters['ZUUL_REF'],
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -393,6 +420,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters['ZUUL_BRANCH'],
|
|
|
|
|
zuul_ref=build.parameters['ZUUL_REF'],
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -479,6 +507,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters['ZUUL_BRANCH'],
|
|
|
|
|
zuul_ref=build.parameters['ZUUL_REF'],
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -544,6 +573,7 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
|
|
|
|
|
zuul_ref=build.parameters.get('ZUUL_REF', None),
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
@ -565,56 +595,158 @@ class TestCloner(ZuulTestCase):
|
|
|
|
|
self.worker.release()
|
|
|
|
|
self.waitUntilSettled()
|
|
|
|
|
|
|
|
|
|
def test_periodic_update(self):
|
|
|
|
|
# Test that the merger correctly updates its local repository
|
|
|
|
|
# before running a periodic job.
|
|
|
|
|
|
|
|
|
|
# Prime the merger with the current state
|
|
|
|
|
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
|
|
|
|
|
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
|
|
|
|
|
self.waitUntilSettled()
|
|
|
|
|
|
|
|
|
|
# Merge a different change
|
|
|
|
|
B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
|
|
|
|
|
B.setMerged()
|
|
|
|
|
|
|
|
|
|
# Start a periodic job
|
|
|
|
|
self.worker.hold_jobs_in_build = True
|
|
|
|
|
self.launcher.negative_function_cache_ttl = 0
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(upstream['org/project'].commit('master').hexsha,
|
|
|
|
|
B.patchsets[0]['revision'])
|
|
|
|
|
states = [
|
|
|
|
|
{'org/project':
|
|
|
|
|
str(upstream['org/project'].commit('master')),
|
|
|
|
|
},
|
|
|
|
|
{'org/project':
|
|
|
|
|
str(upstream['org/project'].commit('master')),
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
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_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
|
|
|
|
|
zuul_ref=build.parameters.get('ZUUL_REF', None),
|
|
|
|
|
zuul_url=self.git_root,
|
|
|
|
|
)
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
def test_post_checkout(self):
|
|
|
|
|
project = "org/project"
|
|
|
|
|
path = os.path.join(self.upstream_root, project)
|
|
|
|
|
repo = git.Repo(path)
|
|
|
|
|
repo.head.reference = repo.heads['master']
|
|
|
|
|
commits = []
|
|
|
|
|
for i in range(0, 3):
|
|
|
|
|
commits.append(self.create_commit(project))
|
|
|
|
|
newRev = commits[1]
|
|
|
|
|
self.worker.hold_jobs_in_build = True
|
|
|
|
|
project = "org/project1"
|
|
|
|
|
|
|
|
|
|
A = self.fake_gerrit.addFakeChange(project, 'master', 'A')
|
|
|
|
|
event = A.getRefUpdatedEvent()
|
|
|
|
|
A.setMerged()
|
|
|
|
|
self.fake_gerrit.addEvent(event)
|
|
|
|
|
self.waitUntilSettled()
|
|
|
|
|
|
|
|
|
|
build = self.builds[0]
|
|
|
|
|
state = {'org/project1': build.parameters['ZUUL_COMMIT']}
|
|
|
|
|
|
|
|
|
|
build.release()
|
|
|
|
|
self.waitUntilSettled()
|
|
|
|
|
|
|
|
|
|
cloner = zuul.lib.cloner.Cloner(
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=[project],
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_branch=None,
|
|
|
|
|
zuul_ref='master',
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
|
zuul_project=project,
|
|
|
|
|
zuul_newrev=newRev,
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
|
|
|
|
|
zuul_ref=build.parameters.get('ZUUL_REF', None),
|
|
|
|
|
zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
|
|
|
|
|
zuul_url=self.git_root,
|
|
|
|
|
)
|
|
|
|
|
cloner.execute()
|
|
|
|
|
repos = self.getWorkspaceRepos([project])
|
|
|
|
|
cloned_sha = repos[project].rev_parse('HEAD').hexsha
|
|
|
|
|
self.assertEqual(newRev, cloned_sha)
|
|
|
|
|
work = self.getWorkspaceRepos([project])
|
|
|
|
|
self.assertEquals(state[project],
|
|
|
|
|
str(work[project].commit('HEAD')),
|
|
|
|
|
'Project %s commit for build %s should '
|
|
|
|
|
'be correct' % (project, 0))
|
|
|
|
|
shutil.rmtree(self.workspace_root)
|
|
|
|
|
|
|
|
|
|
def test_post_and_master_checkout(self):
|
|
|
|
|
project = "org/project1"
|
|
|
|
|
master_project = "org/project2"
|
|
|
|
|
path = os.path.join(self.upstream_root, project)
|
|
|
|
|
repo = git.Repo(path)
|
|
|
|
|
repo.head.reference = repo.heads['master']
|
|
|
|
|
commits = []
|
|
|
|
|
for i in range(0, 3):
|
|
|
|
|
commits.append(self.create_commit(project))
|
|
|
|
|
newRev = commits[1]
|
|
|
|
|
self.worker.hold_jobs_in_build = True
|
|
|
|
|
projects = ["org/project1", "org/project2"]
|
|
|
|
|
|
|
|
|
|
A = self.fake_gerrit.addFakeChange(projects[0], 'master', 'A')
|
|
|
|
|
event = A.getRefUpdatedEvent()
|
|
|
|
|
A.setMerged()
|
|
|
|
|
self.fake_gerrit.addEvent(event)
|
|
|
|
|
self.waitUntilSettled()
|
|
|
|
|
|
|
|
|
|
build = self.builds[0]
|
|
|
|
|
upstream = self.getUpstreamRepos(projects)
|
|
|
|
|
state = {'org/project1':
|
|
|
|
|
build.parameters['ZUUL_COMMIT'],
|
|
|
|
|
'org/project2':
|
|
|
|
|
str(upstream['org/project2'].commit('master')),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build.release()
|
|
|
|
|
self.waitUntilSettled()
|
|
|
|
|
|
|
|
|
|
cloner = zuul.lib.cloner.Cloner(
|
|
|
|
|
git_base_url=self.upstream_root,
|
|
|
|
|
projects=[project, master_project],
|
|
|
|
|
projects=projects,
|
|
|
|
|
workspace=self.workspace_root,
|
|
|
|
|
zuul_branch=None,
|
|
|
|
|
zuul_ref='master',
|
|
|
|
|
zuul_url=self.src_root,
|
|
|
|
|
zuul_project=project,
|
|
|
|
|
zuul_newrev=newRev
|
|
|
|
|
zuul_project=build.parameters.get('ZUUL_PROJECT', None),
|
|
|
|
|
zuul_branch=build.parameters.get('ZUUL_BRANCH', None),
|
|
|
|
|
zuul_ref=build.parameters.get('ZUUL_REF', None),
|
|
|
|
|
zuul_newrev=build.parameters.get('ZUUL_NEWREV', None),
|
|
|
|
|
zuul_url=self.git_root,
|
|
|
|
|
)
|
|
|
|
|
cloner.execute()
|
|
|
|
|
repos = self.getWorkspaceRepos([project, master_project])
|
|
|
|
|
cloned_sha = repos[project].rev_parse('HEAD').hexsha
|
|
|
|
|
self.assertEqual(newRev, cloned_sha)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
repos[master_project].rev_parse('HEAD').hexsha,
|
|
|
|
|
repos[master_project].rev_parse('master').hexsha)
|
|
|
|
|
work = self.getWorkspaceRepos(projects)
|
|
|
|
|
|
|
|
|
|
for project in projects:
|
|
|
|
|
self.assertEquals(state[project],
|
|
|
|
|
str(work[project].commit('HEAD')),
|
|
|
|
|
'Project %s commit for build %s should '
|
|
|
|
|
'be correct' % (project, 0))
|
|
|
|
|
shutil.rmtree(self.workspace_root)
|
|
|
|
|