summaryrefslogtreecommitdiff
path: root/tests/base.py
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-08-23 12:10:32 +0000
committerGerrit Code Review <review@openstack.org>2017-08-23 12:10:32 +0000
commitc79dcb03b18c8dad36fca029a8ea2239cb6e0867 (patch)
treeaff68bacd605685949f09110632543b0652bd59b /tests/base.py
parentc7b3d71ce2a49b0096b80b2e05866f08d4cd451e (diff)
parent627ba361d1e5faca6af0de472550c8aeb8291a7b (diff)
downloadzuul-c79dcb03b18c8dad36fca029a8ea2239cb6e0867.tar.gz
Merge "Re-enable test_delayed_repo_init" into feature/zuulv3
Diffstat (limited to 'tests/base.py')
-rwxr-xr-xtests/base.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/base.py b/tests/base.py
index 680c2a7bb..357dd7a51 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -2811,6 +2811,41 @@ class ZuulTestCase(BaseTestCase):
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.