From a41ee5aef75e47667defc7b01b89a25309bd4c8d Mon Sep 17 00:00:00 2001 From: Martin Babinsky Date: Thu, 19 Nov 2015 14:33:49 +0100 Subject: [PATCH] suppress errors arising from adding existing LDAP entries during KRA install https://fedorahosted.org/freeipa/ticket/5346 Reviewed-By: Jan Cholasta --- ipaserver/install/krainstance.py | 16 ++++++++++++++-- ipaserver/install/service.py | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ipaserver/install/krainstance.py b/ipaserver/install/krainstance.py index 0000192745b6d7f9f402267e435f7223f1bf8849..a2514debae600bdc46afb92e426a5f616529fde2 100644 --- a/ipaserver/install/krainstance.py +++ b/ipaserver/install/krainstance.py @@ -47,6 +47,8 @@ from ipapython.ipa_log_manager import log_mgr IPA_KRA_RECORD = "ipa-kra" +LDAPMOD_ERR_ALREADY_EXISTS = 68 + class KRAInstance(DogtagInstance): """ We assume that the CA has already been installed, and we use the @@ -308,8 +310,18 @@ class KRAInstance(DogtagInstance): conn.disconnect() def __add_vault_container(self): - self._ldap_mod('vault.ldif', {'SUFFIX': self.suffix}) - self.ldap_disconnect() + try: + self._ldap_mod('vault.ldif', {'SUFFIX': self.suffix}, + raise_on_err=True) + except ipautil.CalledProcessError as e: + if e.returncode == LDAPMOD_ERR_ALREADY_EXISTS: + self.log.debug("Vault container already exists") + else: + self.log.error("Failed to add vault container: {0}".format(e)) + finally: + # we need to disconnect from LDAP, because _ldap_mod() makes the + # connection without actually using it + self.ldap_disconnect() def __apply_updates(self): sub_dict = { diff --git a/ipaserver/install/service.py b/ipaserver/install/service.py index 2f5f565b16b42bf82889f9d32b80cf6fa584d438..597c20a60c712a6e521a7b9471f6732cceb27fe7 100644 --- a/ipaserver/install/service.py +++ b/ipaserver/install/service.py @@ -155,7 +155,7 @@ class Service(object): self.admin_conn.unbind() self.admin_conn = None - def _ldap_mod(self, ldif, sub_dict=None): + def _ldap_mod(self, ldif, sub_dict=None, raise_on_err=False): pw_name = None fd = None path = ipautil.SHARE_DIR + ldif @@ -199,6 +199,8 @@ class Service(object): try: ipautil.run(args, nolog=nologlist) except ipautil.CalledProcessError, e: + if raise_on_err: + raise root_logger.critical("Failed to load %s: %s" % (ldif, str(e))) finally: if pw_name: -- 2.4.3