URL: https://github.com/freeipa/freeipa/pull/301
Author: jcholast
 Title: #301: scripts, tests: explicitly set confdir in the rest of server code
Action: opened

PR body:
"""
Commit 1e6a204b4372bbbfb722a00370a5ce4e34406b9f added explicit confdir
setting to api.bootstrap() calls of a randomly selected portion of
server-side scripts and tests. This commit adds it to the rest of
server-side code for consistency.

https://fedorahosted.org/freeipa/ticket/6389
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/301/head:pr301
git checkout pr301
From 23f6d46675b9614cc654bd17c1cc3377d2539211 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Fri, 2 Dec 2016 09:10:41 +0100
Subject: [PATCH] scripts, tests: explicitly set confdir in the rest of server
 code

Commit 1e6a204b4372bbbfb722a00370a5ce4e34406b9f added explicit confdir
setting to api.bootstrap() calls of a randomly selected portion of
server-side scripts and tests. This commit adds it to the rest of
server-side code for consistency.

https://fedorahosted.org/freeipa/ticket/6389
---
 doc/guide/wsgi.py.txt                       | 6 ++++--
 install/tools/ipa-compat-manage             | 5 ++++-
 install/tools/ipa-csreplica-manage          | 6 +++++-
 install/tools/ipa-managed-entries           | 3 ++-
 ipaserver/advise/base.py                    | 9 +++++++--
 ipaserver/dnssec/ldapkeydb.py               | 4 +++-
 ipaserver/install/ipa_cacert_manage.py      | 2 +-
 ipaserver/install/ipa_kra_install.py        | 2 +-
 ipaserver/install/ipa_otptoken_import.py    | 3 ++-
 ipaserver/install/ipa_replica_prepare.py    | 2 +-
 ipaserver/install/ipa_server_certinstall.py | 2 +-
 ipatests/test_ipaserver/test_ldap.py        | 3 ++-
 ipatests/test_ipaserver/test_serverroles.py | 5 ++++-
 13 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/doc/guide/wsgi.py.txt b/doc/guide/wsgi.py.txt
index 8566a25..1b72516 100644
--- a/doc/guide/wsgi.py.txt
+++ b/doc/guide/wsgi.py.txt
@@ -1,3 +1,4 @@
+from ipaplatform.paths import paths
 from ipalib import api
 from ipalib.config import Env
 from ipalib.constants import DEFAULT_CONFIG
@@ -6,11 +7,12 @@ from ipalib.constants import DEFAULT_CONFIG
 # by reading in the configuration file(s). The server always reads
 # default.conf and will also read in `context'.conf.
 env = Env()
-env._bootstrap(context='server', log=None)
+env._bootstrap(context='server', log=None, confdir=paths.ETC_IPA)
 env._finalize_core(**dict(DEFAULT_CONFIG))
 
 # Initialize the API with the proper debug level
-api.bootstrap(context='server', debug=env.debug, log=None) (ref:wsgi-app-bootstrap)
+api.bootstrap(context='server', confdir=paths.ETC_IPA,
+              debug=env.debug, log=None) (ref:wsgi-app-bootstrap)
 try:
     api.finalize() (ref:wsgi-app-finalize)
 except Exception as e:
diff --git a/install/tools/ipa-compat-manage b/install/tools/ipa-compat-manage
index 77468b4..a29a92f 100755
--- a/install/tools/ipa-compat-manage
+++ b/install/tools/ipa-compat-manage
@@ -100,7 +100,10 @@ def main():
         if dirman_password is None:
             sys.exit("Directory Manager password required")
 
-    api.bootstrap(context='cli', in_server=True, debug=options.debug)
+    api.bootstrap(context='cli',
+                  in_server=True,
+                  debug=options.debug,
+                  confdir=paths.ETC_IPA)
     api.finalize()
     api.Backend.ldap2.connect()
 
diff --git a/install/tools/ipa-csreplica-manage b/install/tools/ipa-csreplica-manage
index f494380..990ec38 100755
--- a/install/tools/ipa-csreplica-manage
+++ b/install/tools/ipa-csreplica-manage
@@ -413,7 +413,11 @@ def main():
         api_env['log'] = None # turn off logging for non-root
 
     api.bootstrap(
-        context='cli', in_server=True, verbose=options.verbose, **api_env
+        context='cli',
+        in_server=True,
+        verbose=options.verbose,
+        confdir=paths.ETC_IPA,
+        **api_env
     )
     api.finalize()
 
diff --git a/install/tools/ipa-managed-entries b/install/tools/ipa-managed-entries
index 59f14fc..efcf3ec 100755
--- a/install/tools/ipa-managed-entries
+++ b/install/tools/ipa-managed-entries
@@ -24,6 +24,7 @@ import re
 import sys
 from optparse import OptionParser  # pylint: disable=deprecated-module
 
+from ipaplatform.paths import paths
 from ipapython import config
 from ipaserver.install import installutils
 from ipalib import api, errors
@@ -72,7 +73,7 @@ def main():
         sys.exit("Unrecognized action [" + args[0] + "]")
     standard_logging_setup(None, debug=options.debug)
 
-    api.bootstrap(context='cli', debug=options.debug)
+    api.bootstrap(context='cli', debug=options.debug, confdir=paths.ETC_IPA)
     api.finalize()
     api.Backend.ldap2.connect(bind_pw=options.dirman_password)
 
diff --git a/ipaserver/advise/base.py b/ipaserver/advise/base.py
index f7e8ef5..40dabd0 100644
--- a/ipaserver/advise/base.py
+++ b/ipaserver/advise/base.py
@@ -25,6 +25,7 @@
 from ipalib import api
 from ipalib.plugable import Plugin, API
 from ipalib.errors import ValidationError
+from ipaplatform.paths import paths
 from ipapython import admintool
 from ipapython.ipa_log_manager import log_mgr
 
@@ -235,9 +236,13 @@ def print_advice(self, keyword):
     def run(self):
         super(IpaAdvise, self).run()
 
-        api.bootstrap(in_server=False, context='cli')
+        api.bootstrap(in_server=False,
+                      context='cli',
+                      confdir=paths.ETC_IPA)
         api.finalize()
-        advise_api.bootstrap(in_server=False, context='cli')
+        advise_api.bootstrap(in_server=False,
+                             context='cli',
+                             confdir=paths.ETC_IPA)
         advise_api.finalize()
         if not self.options.verbose:
             # Do not print connection information by default
diff --git a/ipaserver/dnssec/ldapkeydb.py b/ipaserver/dnssec/ldapkeydb.py
index 98e150d..0b6824c 100644
--- a/ipaserver/dnssec/ldapkeydb.py
+++ b/ipaserver/dnssec/ldapkeydb.py
@@ -9,6 +9,7 @@
 from pprint import pprint
 
 import ipalib
+from ipaplatform.paths import paths
 from ipapython.dn import DN
 from ipapython import ipaldap
 from ipapython import ipa_log_manager
@@ -414,7 +415,8 @@ def zone_keypairs(self):
     log = ipa_log_manager.root_logger
 
     # IPA framework initialization
-    ipalib.api.bootstrap(in_server=True, log=None)  # no logging to file
+    # no logging to file
+    ipalib.api.bootstrap(in_server=True, log=None, confdir=paths.ETC_IPA)
     ipalib.api.finalize()
 
     # LDAP initialization
diff --git a/ipaserver/install/ipa_cacert_manage.py b/ipaserver/install/ipa_cacert_manage.py
index 5a278f4..d3951e4 100644
--- a/ipaserver/install/ipa_cacert_manage.py
+++ b/ipaserver/install/ipa_cacert_manage.py
@@ -97,7 +97,7 @@ def validate_options(self):
     def run(self):
         command = self.command
 
-        api.bootstrap(in_server=True)
+        api.bootstrap(in_server=True, confdir=paths.ETC_IPA)
         api.finalize()
 
         self.ldap_connect()
diff --git a/ipaserver/install/ipa_kra_install.py b/ipaserver/install/ipa_kra_install.py
index a545f2b..2f36d2e 100644
--- a/ipaserver/install/ipa_kra_install.py
+++ b/ipaserver/install/ipa_kra_install.py
@@ -77,7 +77,7 @@ def validate_options(self, needs_root=True):
 
         installutils.check_server_configuration()
 
-        api.bootstrap(in_server=True)
+        api.bootstrap(in_server=True, confdir=paths.ETC_IPA)
         api.finalize()
 
     @classmethod
diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py
index 00939e0..552fdfb 100644
--- a/ipaserver/install/ipa_otptoken_import.py
+++ b/ipaserver/install/ipa_otptoken_import.py
@@ -34,6 +34,7 @@
 import six
 from six.moves import xrange
 
+from ipaplatform.paths import paths
 from ipapython import admintool
 from ipalib import api, errors
 from ipaserver.plugins.ldap2 import AUTOBIND_DISABLED
@@ -509,7 +510,7 @@ def validate_options(self):
                 self.doc.setKey(f.read())
 
     def run(self):
-        api.bootstrap(in_server=True)
+        api.bootstrap(in_server=True, confdir=paths.ETC_IPA)
         api.finalize()
 
         try:
diff --git a/ipaserver/install/ipa_replica_prepare.py b/ipaserver/install/ipa_replica_prepare.py
index e7070b6..7fa63c5 100644
--- a/ipaserver/install/ipa_replica_prepare.py
+++ b/ipaserver/install/ipa_replica_prepare.py
@@ -180,7 +180,7 @@ def validate_options(self):
         else:
             [self.replica_fqdn] = self.args
 
-        api.bootstrap(in_server=True)
+        api.bootstrap(in_server=True, confdir=paths.ETC_IPA)
         api.finalize()
         # Connect to LDAP, connection is closed at the end of run()
         api.Backend.ldap2.connect()
diff --git a/ipaserver/install/ipa_server_certinstall.py b/ipaserver/install/ipa_server_certinstall.py
index 8ef25ee..83ab4a2 100644
--- a/ipaserver/install/ipa_server_certinstall.py
+++ b/ipaserver/install/ipa_server_certinstall.py
@@ -98,7 +98,7 @@ def ask_for_options(self):
                     "Private key unlock password required")
 
     def run(self):
-        api.bootstrap(in_server=True)
+        api.bootstrap(in_server=True, confdir=paths.ETC_IPA)
         api.finalize()
         api.Backend.ldap2.connect(bind_pw=self.options.dirman_password)
 
diff --git a/ipatests/test_ipaserver/test_ldap.py b/ipatests/test_ipaserver/test_ldap.py
index 1ea9959..1cd6543 100644
--- a/ipatests/test_ipaserver/test_ldap.py
+++ b/ipatests/test_ipaserver/test_ldap.py
@@ -34,6 +34,7 @@
 import nss.nss as nss
 import six
 
+from ipaplatform.paths import paths
 from ipaserver.plugins.ldap2 import ldap2
 from ipalib import api, x509, create_api, errors
 from ipapython import ipautil
@@ -111,7 +112,7 @@ def test_Backend(self):
         # a client-only api. Then we register in the commands and objects
         # we need for the test.
         myapi = create_api(mode=None)
-        myapi.bootstrap(context='cli', in_server=True)
+        myapi.bootstrap(context='cli', in_server=True, confdir=paths.ETC_IPA)
         myapi.finalize()
 
         pwfile = api.env.dot_ipa + os.sep + ".dmpw"
diff --git a/ipatests/test_ipaserver/test_serverroles.py b/ipatests/test_ipaserver/test_serverroles.py
index 0118105..d8844df 100644
--- a/ipatests/test_ipaserver/test_serverroles.py
+++ b/ipatests/test_ipaserver/test_serverroles.py
@@ -11,6 +11,7 @@
 import ldap
 import pytest
 
+from ipaplatform.paths import paths
 from ipalib import api, create_api, errors
 from ipapython.dn import DN
 from ipatests.util import MockLDAP
@@ -469,7 +470,9 @@ def teardown_data(self):
 @pytest.fixture(scope='module')
 def mock_api(request):
     test_api = create_api(mode=None)
-    test_api.bootstrap(in_server=True, ldap_uri=api.env.ldap_uri)
+    test_api.bootstrap(in_server=True,
+                       ldap_uri=api.env.ldap_uri,
+                       confdir=paths.ETC_IPA)
     test_api.finalize()
 
     if not test_api.Backend.ldap2.isconnected():
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to