summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/man/ipa.14
-rw-r--r--ipalib/config.py12
-rw-r--r--ipalib/plugable.py9
-rw-r--r--ipatests/test_ipalib/test_plugable.py40
-rw-r--r--ipatests/util.py6
5 files changed, 68 insertions, 3 deletions
diff --git a/client/man/ipa.1 b/client/man/ipa.1
index 9194ca071..b843e7ba7 100644
--- a/client/man/ipa.1
+++ b/client/man/ipa.1
@@ -186,6 +186,10 @@ The ipa client will determine which server to connect to in this order:
.TP
If a kerberos error is raised by any of the requests then it will stop processing and display the error message.
+.SH "ENVIRONMENT VARIABLES"
+.TP
+\fBIPA_CONFDIR\fR
+Override path to confdir (default: \fB/etc/ipa\fR).
.SH "FILES"
.TP
\fB/etc/ipa/default.conf\fR
diff --git a/ipalib/config.py b/ipalib/config.py
index 1075d627a..9d877828f 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -43,6 +43,7 @@ from ipapython.dn import DN
from ipalib.base import check_name
from ipalib.constants import CONFIG_SECTION
from ipalib.constants import OVERRIDE_ERROR, SET_ERROR, DEL_ERROR
+from ipapython.admintool import ScriptError
if six.PY3:
unicode = str
@@ -460,8 +461,17 @@ class Env(object):
self.context = 'default'
# Set confdir:
+ self.env_confdir = os.environ.get('IPA_CONFDIR')
if 'confdir' not in self:
- if self.in_tree:
+ if self.env_confdir is not None:
+ if (not path.isabs(self.env_confdir)
+ or not path.isdir(self.env_confdir)):
+ raise ScriptError(
+ "IPA_CONFDIR env var must be an absolute path to an "
+ "existing directory, got '{}'.".format(
+ self.env_confdir))
+ self.confdir = self.env_confdir
+ elif self.in_tree:
self.confdir = self.dot_ipa
else:
self.confdir = path.join('/', 'etc', 'ipa')
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 503534f9f..142b3e60d 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -713,6 +713,15 @@ class API(ReadOnly):
self.__doing('finalize')
self.__do_if_not_done('load_plugins')
+ if self.env.env_confdir is not None:
+ if self.env.env_confdir == self.env.confdir:
+ self.log.info(
+ "IPA_CONFDIR env sets confdir to '%s'.", self.env.confdir)
+ else:
+ self.log.warn(
+ "IPA_CONFDIR env is overridden by an explicit confdir "
+ "argument.")
+
for plugin in self.__plugins:
if not self.env.validate_api:
if plugin.full_name not in DEFAULT_PLUGINS:
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):