From ed955d14d3bc79dbbb90590d87f7e38777602808 Mon Sep 17 00:00:00 2001 From: Stanislav Laznicka Date: Mon, 19 Feb 2018 10:36:08 +0100 Subject: [PATCH] Move lib389 imports to module scope Reviewed-By: Alexander Bokovoy --- freeipa.spec.in | 10 +++++----- ipaplatform/base/paths.py | 2 -- ipaserver/install/dsinstance.py | 34 ++++++++++++++++----------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/freeipa.spec.in b/freeipa.spec.in index 45d6405f3..2e31aec62 100644 --- a/freeipa.spec.in +++ b/freeipa.spec.in @@ -48,9 +48,11 @@ %global selinux_policy_version 3.14.1-14 %global slapi_nis_version 0.56.1-4 %global python_ldap_version 3.1.0-1 +# python3-lib389 # Fix for "Installation fails: Replica Busy" -# https://bugzilla.redhat.com/show_bug.cgi?id=1598478 -%global ds_version 1.3.8.4-15 +# https://pagure.io/389-ds-base/issue/49818 +%global ds_version 1.4.0.16-1 + %else # Fedora %global package_name freeipa @@ -67,9 +69,7 @@ # fix for segfault in python3-ldap, https://pagure.io/freeipa/issue/7324 %global python_ldap_version 3.1.0-1 - -# Fix for "Crash when failing to read from SASL connection" -# https://pagure.io/389-ds-base/issue/49639 +# python3-lib389 # Fix for "Installation fails: Replica Busy" # https://pagure.io/389-ds-base/issue/49818 %global ds_version 1.4.0.16-1 diff --git a/ipaplatform/base/paths.py b/ipaplatform/base/paths.py index 76f19c82c..8d56abc16 100644 --- a/ipaplatform/base/paths.py +++ b/ipaplatform/base/paths.py @@ -386,8 +386,6 @@ class BasePathNamespace: DB2LDIF = '/usr/sbin/db2ldif' BAK2DB = '/usr/sbin/bak2db' DB2BAK = '/usr/sbin/db2bak' - SETUP_DS_PL = "/usr/sbin/setup-ds.pl" - REMOVE_DS_PL = "/usr/sbin/remove-ds.pl" IPA_SERVER_UPGRADE = '/usr/sbin/ipa-server-upgrade' KEYCTL = '/usr/bin/keyctl' GETENT = '/usr/bin/getent' diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py index 3aa8e07fc..19b498c0a 100644 --- a/ipaserver/install/dsinstance.py +++ b/ipaserver/install/dsinstance.py @@ -31,6 +31,12 @@ import fnmatch import ldap +from lib389 import DirSrv +from lib389.idm.ipadomain import IpaDomain +from lib389.instance.options import General2Base, Slapd2Base +from lib389.instance.remove import remove_ds_instance as lib389_remove_ds +from lib389.instance.setup import SetupDs + from ipalib import x509 from ipalib.install import certmonger, certstore from ipapython.certdb import (IPA_CA_TRUST_FLAGS, @@ -103,16 +109,13 @@ def remove_ds_instance(serverid): you even need multiple times ....) """ - from lib389.instance.remove import remove_ds_instance - from lib389 import DirSrv - logger.debug("Attempting to remove instance %s", serverid) # Alloc the local instance by name (no creds needed!) ds = DirSrv(verbose=True, external_log=logger) ds.local_simple_allocate(serverid) # Remove it - remove_ds_instance(ds) + lib389_remove_ds(ds) logger.debug("Instance removed correctly.") @@ -548,13 +551,6 @@ class DsInstance(service.Service): ) def __create_instance(self): - # We only import lib389 now, we can't always guarantee its presence - # yet. After f28, this can be made a dependency proper. - from lib389.instance.setup import SetupDs - from lib389.instance.options import General2Base, Slapd2Base - from lib389.idm.ipadomain import IpaDomain - from lib389 import DirSrv - # The new installer is api driven. We can pass it a log function # and it will use it. Because of this, we can pass verbose true, # and allow our logger to control the display based on level. @@ -581,7 +577,7 @@ class DsInstance(service.Service): 'nsslapd-suffix': self.suffix.ldap_text() } - backends = [userroot, ] + backends = [userroot] sds.create_from_args(general, slapd, backends, None) @@ -595,11 +591,15 @@ class DsInstance(service.Service): # This actually opens the conn and binds. inst.open() - ipadomain = IpaDomain(inst, dn=self.suffix.ldap_text()) - ipadomain.create(properties={ - 'dc': self.realm.split('.')[0].lower(), - 'info': 'IPA V2.0', - }) + try: + ipadomain = IpaDomain(inst, dn=self.suffix.ldap_text()) + ipadomain.create(properties={ + 'dc': self.realm.split('.')[0].lower(), + 'info': 'IPA V2.0', + }) + finally: + inst.close() + # Done! logger.debug("completed creating DS instance")