Browse Source

Merge "Clone repo if it is not on disk"

changes/96/54196/16
Jenkins 9 years ago committed by Gerrit Code Review
parent
commit
f5267baa0f
  1. 52
      tests/fixtures/layout-repo-deleted.yaml
  2. 37
      tests/test_scheduler.py
  3. 6
      zuul/merger.py

52
tests/fixtures/layout-repo-deleted.yaml vendored

@ -0,0 +1,52 @@
pipelines:
- name: check
manager: IndependentPipelineManager
trigger:
gerrit:
- event: patchset-created
success:
gerrit:
verified: 1
failure:
gerrit:
verified: -1
- name: post
manager: IndependentPipelineManager
trigger:
gerrit:
- event: ref-updated
ref: ^(?!refs/).*$
- name: gate
manager: DependentPipelineManager
failure-message: Build failed. For information on how to proceed, see http://wiki.example.org/Test_Failures
trigger:
gerrit:
- event: comment-added
approval:
- approved: 1
success:
gerrit:
verified: 2
submit: true
failure:
gerrit:
verified: -2
start:
gerrit:
verified: 0
precedence: high
projects:
- name: org/delete-project
check:
- project-merge:
- project-test1
- project-test2
gate:
- project-merge:
- project-test1
- project-test2
post:
- project-post

37
tests/test_scheduler.py

@ -2807,6 +2807,43 @@ class TestScheduler(testtools.TestCase):
self.assertEqual(A.data['status'], 'MERGED')
self.assertEqual(A.reported, 2)
def test_repo_deleted(self):
self.config.set('zuul', 'layout_config',
'tests/fixtures/layout-repo-deleted.yaml')
self.sched.reconfigure(self.config)
self.init_repo("org/delete-project")
A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
A.addApproval('CRVW', 2)
self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
self.waitUntilSettled()
self.assertEqual(self.getJobFromHistory('project-merge').result,
'SUCCESS')
self.assertEqual(self.getJobFromHistory('project-test1').result,
'SUCCESS')
self.assertEqual(self.getJobFromHistory('project-test2').result,
'SUCCESS')
self.assertEqual(A.data['status'], 'MERGED')
self.assertEqual(A.reported, 2)
# Delete org/new-project zuul repo. Should be recloned.
shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
B.addApproval('CRVW', 2)
self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
self.waitUntilSettled()
self.assertEqual(self.getJobFromHistory('project-merge').result,
'SUCCESS')
self.assertEqual(self.getJobFromHistory('project-test1').result,
'SUCCESS')
self.assertEqual(self.getJobFromHistory('project-test2').result,
'SUCCESS')
self.assertEqual(B.data['status'], 'MERGED')
self.assertEqual(B.reported, 2)
def test_timer(self):
"Test that a periodic job is triggered"
self.worker.hold_jobs_in_build = True

6
zuul/merger.py

@ -38,9 +38,11 @@ class Repo(object):
self.log.exception("Unable to initialize repo for %s" % remote)
def _ensure_cloned(self):
if self._initialized:
repo_is_cloned = os.path.exists(self.local_path)
if self._initialized and repo_is_cloned:
return
if not os.path.exists(self.local_path):
# If the repo does not exist, clone the repo.
if not repo_is_cloned:
self.log.debug("Cloning from %s to %s" % (self.remote_url,
self.local_path))
git.Repo.clone_from(self.remote_url, self.local_path)

Loading…
Cancel
Save