summaryrefslogtreecommitdiffstats
path: root/ipatests
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2016-10-24 10:35:41 +0200
committerJan Cholasta <jcholast@redhat.com>2016-12-02 15:05:33 +0100
commitd4916254e995be1118ab8dbce5b60091305f97fe (patch)
treeff6daf4da6512d84c135822ec512aedc5021023f /ipatests
parent64a4be26febf19e427760115912a858a804208a0 (diff)
downloadfreeipa-d4916254e995be1118ab8dbce5b60091305f97fe.tar.gz
freeipa-d4916254e995be1118ab8dbce5b60091305f97fe.tar.xz
freeipa-d4916254e995be1118ab8dbce5b60091305f97fe.zip
Use env var IPA_CONFDIR to get confdir
The environment variable IPA_CONFDIR overrides the default confdir path. The value of the environment variable must be an absolute path to an existing directory. The new variable makes it much simpler to use the 'ipa' command and ipalib with a local configuration directory. Some scripts (e.g. servers, installers, and upgrades) set the confdir explicitly and do not support the env var. Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipatests')
-rw-r--r--ipatests/test_ipalib/test_plugable.py40
-rw-r--r--ipatests/util.py6
2 files changed, 44 insertions, 2 deletions
diff --git a/ipatests/test_ipalib/test_plugable.py b/ipatests/test_ipalib/test_plugable.py
index 1ee110250..ff224466e 100644
--- a/ipatests/test_ipalib/test_plugable.py
+++ b/ipatests/test_ipalib/test_plugable.py
@@ -24,9 +24,13 @@ Test the `ipalib.plugable` module.
# FIXME: Pylint errors
# pylint: disable=no-member
+import os
+import textwrap
+
+from ipalib import plugable, errors, create_api
+from ipapython.admintool import ScriptError
from ipatests.util import raises, read_only
-from ipatests.util import ClassChecker, create_test_api
-from ipalib import plugable, errors
+from ipatests.util import ClassChecker, create_test_api, TempHome
import pytest
@@ -272,3 +276,35 @@ class test_API(ClassChecker):
assert o.isdone('load_plugins') is True
e = raises(Exception, o.load_plugins)
assert str(e) == 'API.load_plugins() already called'
+
+ def test_ipaconf_env(self):
+ ipa_confdir = os.environ.get('IPA_CONFDIR', None)
+ try:
+ with TempHome() as home:
+ defaultconf = home.join('default.conf')
+ with open(defaultconf, 'w') as f:
+ f.write(textwrap.dedent("""
+ [global]
+ basedn = dc=ipa,dc=test
+ realm = IPA.TEST
+ domain = ipa.test
+ """)
+ )
+ os.environ['IPA_CONFDIR'] = home.path
+ api = create_api(mode='unit_test')
+ api.bootstrap()
+ api.finalize()
+ assert api.env.confdir == home.path
+ assert api.env.conf_default == defaultconf
+ assert api.env.realm == 'IPA.TEST'
+ assert api.env.domain == 'ipa.test'
+
+ os.environ['IPA_CONFDIR'] = home.join('invalid')
+ api = create_api(mode='unit_test')
+ with pytest.raises(ScriptError):
+ api.bootstrap()
+ finally:
+ if ipa_confdir:
+ os.environ['IPA_CONFDIR'] = ipa_confdir
+ else:
+ os.environ.pop('IPA_CONFDIR')
diff --git a/ipatests/util.py b/ipatests/util.py
index 3f66b595c..7b5e317de 100644
--- a/ipatests/util.py
+++ b/ipatests/util.py
@@ -96,6 +96,12 @@ class TempDir(object):
def __del__(self):
self.rmtree()
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self.rmtree()
+
class TempHome(TempDir):
def __init__(self):