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.