[Freeipa-devel] [freeipa PR#182][comment] Use env var IPA_CONFDIR to get confdir for 'cli' context

pvoborni freeipa-github-notification at redhat.com
Fri Dec 2 11:25:25 UTC 2016


  URL: https://github.com/freeipa/freeipa/pull/182
Title: #182: Use env var IPA_CONFDIR to get confdir for 'cli' context

pvoborni commented:
"""
Honza,  would this work?

```diff
diff --git a/ipalib/config.py b/ipalib/config.py
index 9d87782..6c3a0b1 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -43,7 +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
+from ipalib.errors import EnvirontmentError
 
 if six.PY3:
     unicode = str
@@ -466,7 +466,7 @@ class Env(object):
             if self.env_confdir is not None:
                 if (not path.isabs(self.env_confdir)
                         or not path.isdir(self.env_confdir)):
-                    raise ScriptError(
+                    raise EnvirontmentError(
                         "IPA_CONFDIR env var must be an absolute path to an "
                         "existing directory, got '{}'.".format(
                             self.env_confdir))
diff --git a/ipalib/errors.py b/ipalib/errors.py
index d1fe5f0..dfd74d7 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -865,6 +865,13 @@ class NotAForestRootError(InvocationError):
     errno = 3016
     format = _("Domain '%(domain)s' is not a root domain for forest '%(forest)s'")
 
+class EnvirontmentError(InvocationError):
+    """
+    **3017** Raised when a command is called with invalid environment settings
+    """
+
+    errno = 3017
+
 ##############################################################################
 # 4000 - 4999: Execution errors
 
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 142b3e6..95e0a8a 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -718,9 +718,9 @@ class API(ReadOnly):
                 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.")
+                raise errors.EnvirontmentError(
+                    "IPA_CONFDIR env cannot be set because explicit confdir is"
+                    "used")
 
         for plugin in self.__plugins:
             if not self.env.validate_api:

```
"""

See the full comment at https://github.com/freeipa/freeipa/pull/182#issuecomment-264433672


More information about the Freeipa-devel mailing list