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