Re-enable test_delayed_repo_init
Porting this test needed some fundamental help because we haven't had
any tests that required changing the tenant config before.
Change-Id: Ife0bf391340d24f33b516afdb24626415ad7d65f
Story: 2001134
Task: 4847
diff --git a/tests/base.py b/tests/base.py
index 480db83..f6982f5 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -2791,6 +2791,41 @@
files)
return before
+ def newTenantConfig(self, source_name):
+ """ Use this to update the tenant config file in tests
+
+ This will update self.tenant_config_file to point to a temporary file
+ for the duration of this particular test. The content of that file will
+ be taken from FIXTURE_DIR/source_name
+
+ After the test the original value of self.tenant_config_file will be
+ restored.
+
+ :arg str source_name: The path of the file under
+ FIXTURE_DIR that will be used to populate the new tenant
+ config file.
+ """
+ source_path = os.path.join(FIXTURE_DIR, source_name)
+ orig_tenant_config_file = self.tenant_config_file
+ with tempfile.NamedTemporaryFile(
+ delete=False, mode='wb') as new_tenant_config:
+ self.tenant_config_file = new_tenant_config.name
+ with open(source_path, mode='rb') as source_tenant_config:
+ new_tenant_config.write(source_tenant_config.read())
+ self.config['scheduler']['tenant_config'] = self.tenant_config_file
+ self.setupAllProjectKeys()
+ self.log.debug(
+ 'tenant_config_file = {}'.format(self.tenant_config_file))
+
+ def _restoreTenantConfig():
+ self.log.debug(
+ 'restoring tenant_config_file = {}'.format(
+ orig_tenant_config_file))
+ os.unlink(self.tenant_config_file)
+ self.tenant_config_file = orig_tenant_config_file
+ self.config['scheduler']['tenant_config'] = orig_tenant_config_file
+ self.addCleanup(_restoreTenantConfig)
+
def addEvent(self, connection, event):
"""Inject a Fake (Gerrit) event.
diff --git a/tests/fixtures/layout-delayed-repo-init.yaml b/tests/fixtures/layout-delayed-repo-init.yaml
deleted file mode 100644
index 04dc010..0000000
--- a/tests/fixtures/layout-delayed-repo-init.yaml
+++ /dev/null
@@ -1,52 +0,0 @@
-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/new-project
- check:
- - project-merge:
- - project-test1
- - project-test2
- gate:
- - project-merge:
- - project-test1
- - project-test2
- post:
- - project-post
diff --git a/tests/fixtures/layouts/delayed-repo-init.yaml b/tests/fixtures/layouts/delayed-repo-init.yaml
new file mode 100644
index 0000000..e97d37a
--- /dev/null
+++ b/tests/fixtures/layouts/delayed-repo-init.yaml
@@ -0,0 +1,77 @@
+- pipeline:
+ name: check
+ manager: independent
+ trigger:
+ gerrit:
+ - event: patchset-created
+ success:
+ gerrit:
+ Verified: 1
+ failure:
+ gerrit:
+ Verified: -1
+
+- pipeline:
+ name: post
+ manager: independent
+ trigger:
+ gerrit:
+ - event: ref-updated
+ ref: ^(?!refs/).*$
+
+- pipeline:
+ name: gate
+ manager: dependent
+ 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
+
+- job:
+ name: base
+ parent: null
+
+- job:
+ name: project-merge
+
+- job:
+ name: project-test1
+
+- job:
+ name: project-test2
+
+- job:
+ name: project-post
+
+- project:
+ name: org/new-project
+ check:
+ jobs:
+ - project-merge
+ - project-test1:
+ dependencies: project-merge
+ - project-test2:
+ dependencies: project-merge
+ gate:
+ jobs:
+ - project-merge:
+ - project-test1:
+ dependencies: project-merge
+ - project-test2:
+ dependencies: project-merge
+ post:
+ jobs:
+ - project-post
diff --git a/tests/fixtures/tenants/delayed-repo-init.yaml b/tests/fixtures/tenants/delayed-repo-init.yaml
new file mode 100644
index 0000000..433e6f7
--- /dev/null
+++ b/tests/fixtures/tenants/delayed-repo-init.yaml
@@ -0,0 +1,11 @@
+- tenant:
+ name: tenant-one
+ source:
+ gerrit:
+ config-projects:
+ - common-config
+ untrusted-projects:
+ - org/project
+ - org/project1
+ - org/project2
+ - org/new-project
diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py
index 97d53e0..70f3fb7 100755
--- a/tests/unit/test_scheduler.py
+++ b/tests/unit/test_scheduler.py
@@ -2759,13 +2759,18 @@
self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
self.assertIn('Build succeeded', A.messages[0])
- @skip("Disabled for early v3 development")
def test_delayed_repo_init(self):
- self.updateConfigLayout(
- 'tests/fixtures/layout-delayed-repo-init.yaml')
- self.sched.reconfigure(self.config)
-
self.init_repo("org/new-project")
+ files = {'README': ''}
+ self.addCommitToRepo("org/new-project", 'Initial commit',
+ files=files, tag='init')
+ self.newTenantConfig('tenants/delayed-repo-init.yaml')
+ self.commitConfigUpdate(
+ 'common-config',
+ 'layouts/delayed-repo-init.yaml')
+ self.sched.reconfigure(self.config)
+ self.waitUntilSettled()
+
A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
A.addApproval('Code-Review', 2)