Delay initialization of local repos
Now that live reconfiguration is an option, we sometimes load the
Zuul config before the remote repo is created. To handle that,
gracefully handle that case when the Repo object is created by the
Merger. Keep track of whether the initial clone has happened, and
check for that before every local Repo operation. If we get an
event that involves a repo before it exists (unlikely!) that will
still error and raise an exception (that should be caught higher
up in the stack).
Add a test for this case.
In the test suite, when adding a fake change to the upstream repo,
always reset it so that HEAD is master so that new repos clone
from a consistent state.
Also remove an errant assertEmptyQueues because it's handled by
assertFinalState.
Change-Id: Ic6eec83e3faa2a15be4b23d4cfcfbddcac82983c
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index 4e59db8..85eb8ad 100644
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -148,7 +148,11 @@
f.close()
repo.index.add([fn])
- return repo.index.commit(msg)
+ r = repo.index.commit(msg)
+ repo.head.reference = 'master'
+ repo.head.reset(index=True, working_tree=True)
+ repo.git.clean('-x', '-f', '-d')
+ return r
def addPatchset(self, files=[], large=False):
self.latest_patchset += 1
@@ -2445,4 +2449,23 @@
'SUCCESS')
self.assertEqual(A.data['status'], 'MERGED')
self.assertEqual(A.reported, 2)
- self.assertEmptyQueues()
+
+ def test_delayed_repo_init(self):
+ self.config.set('zuul', 'layout_config',
+ 'tests/fixtures/layout-delayed-repo-init.yaml')
+ self.sched.reconfigure(self.config)
+
+ self.init_repo("org/new-project")
+ A = self.fake_gerrit.addFakeChange('org/new-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)