95ea96
From 08d27e373976f82e054d17a76b8653221c56225c Mon Sep 17 00:00:00 2001
2737e7
From: Christian Heimes <cheimes@redhat.com>
2737e7
Date: Fri, 22 Jun 2018 10:00:24 +0200
2737e7
Subject: [PATCH] Use common replication wait timeout of 5min
2737e7
2737e7
Instead of multiple timeout values all over the code base, all
2737e7
replication waits now use a common timeout value from api.env of 5
2737e7
minutes. Waiting for HTTP/replica principal takes 90 to 120 seconds, so
2737e7
5 minutes seem like a sufficient value for slow setups.
2737e7
2737e7
Fixes: https://pagure.io/freeipa/issue/7595
2737e7
Signed-off-by: Christian Heimes <cheimes@redhat.com>
2737e7
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
2737e7
---
2737e7
 ipalib/constants.py                   |  2 ++
2737e7
 ipaserver/install/custodiainstance.py |  4 +++-
2737e7
 ipaserver/install/httpinstance.py     |  6 +++++-
2737e7
 ipaserver/install/krbinstance.py      | 13 ++++++++-----
2737e7
 ipaserver/install/replication.py      |  6 ++++--
2737e7
 5 files changed, 22 insertions(+), 9 deletions(-)
2737e7
2737e7
diff --git a/ipalib/constants.py b/ipalib/constants.py
95ea96
index 9ae6e0aaaee0577372fe458feb7660e05c7fed4d..38ed57b3cc35afe536f90b1f4245fd73ad4d3740 100644
2737e7
--- a/ipalib/constants.py
2737e7
+++ b/ipalib/constants.py
95ea96
@@ -149,6 +149,8 @@ DEFAULT_CONFIG = (
2737e7
     ('startup_timeout', 300),
2737e7
     # How long http connection should wait for reply [seconds].
2737e7
     ('http_timeout', 30),
2737e7
+    # How long to wait for an entry to appear on a replica
2737e7
+    ('replication_wait_timeout', 300),
2737e7
 
2737e7
     # Web Application mount points
2737e7
     ('mount_ipa', '/ipa/'),
2737e7
diff --git a/ipaserver/install/custodiainstance.py b/ipaserver/install/custodiainstance.py
95ea96
index c87306d2f48367031e888613b07c1091fc1a70f4..fcfe0908426bf71243974c384b0147eb763ad32f 100644
2737e7
--- a/ipaserver/install/custodiainstance.py
2737e7
+++ b/ipaserver/install/custodiainstance.py
95ea96
@@ -5,6 +5,7 @@ from __future__ import print_function, absolute_import
2737e7
 import enum
95ea96
 import logging
2737e7
 
2737e7
+from ipalib import api
2737e7
 from ipaserver.secrets.kem import IPAKEMKeys, KEMLdap
2737e7
 from ipaserver.secrets.client import CustodiaClient
2737e7
 from ipaplatform.paths import paths
95ea96
@@ -214,7 +215,8 @@ class CustodiaInstance(SimpleServiceInstance):
2737e7
         cli = self._get_custodia_client()
2737e7
         cli.fetch_key('dm/DMHash')
2737e7
 
2737e7
-    def _wait_keys(self, timeout=300):
2737e7
+    def _wait_keys(self):
2737e7
+        timeout = api.env.replication_wait_timeout
2737e7
         deadline = int(time.time()) + timeout
95ea96
         logger.info("Waiting up to %s seconds to see our keys "
95ea96
                     "appear on host %s", timeout, self.ldap_uri)
2737e7
diff --git a/ipaserver/install/httpinstance.py b/ipaserver/install/httpinstance.py
95ea96
index 3764870ee77f2ba0da18ec004664e6f66c13bba1..bdd79b1dafda7de664eed664a18bf36c541212bc 100644
2737e7
--- a/ipaserver/install/httpinstance.py
2737e7
+++ b/ipaserver/install/httpinstance.py
95ea96
@@ -644,4 +644,8 @@ class HTTPInstance(service.Service):
2737e7
                 else:
2737e7
                     remote_ldap.simple_bind(ipaldap.DIRMAN_DN,
2737e7
                                             self.dm_password)
2737e7
-                replication.wait_for_entry(remote_ldap, service_dn, timeout=60)
2737e7
+                replication.wait_for_entry(
2737e7
+                    remote_ldap,
2737e7
+                    service_dn,
2737e7
+                    timeout=api.env.replication_wait_timeout
2737e7
+                )
2737e7
diff --git a/ipaserver/install/krbinstance.py b/ipaserver/install/krbinstance.py
95ea96
index 4a5a52dcc831c4edfe0cd52c44fb18bcb6adaef7..a356d5e0c1b96dc6511c335fc22a326a2133bdd8 100644
2737e7
--- a/ipaserver/install/krbinstance.py
2737e7
+++ b/ipaserver/install/krbinstance.py
95ea96
@@ -399,13 +399,16 @@ class KrbInstance(service.Service):
2737e7
     def _wait_for_replica_kdc_entry(self):
2737e7
         master_dn = self.api.Object.server.get_dn(self.fqdn)
2737e7
         kdc_dn = DN(('cn', 'KDC'), master_dn)
2737e7
-
2737e7
-        ldap_uri = 'ldap://{}'.format(self.master_fqdn)
2737e7
-
2737e7
+        ldap_uri = ipaldap.get_ldap_uri(self.master_fqdn)
2737e7
         with ipaldap.LDAPClient(
2737e7
-                ldap_uri, cacert=paths.IPA_CA_CRT) as remote_ldap:
2737e7
+                ldap_uri, cacert=paths.IPA_CA_CRT, start_tls=True
2737e7
+        ) as remote_ldap:
2737e7
             remote_ldap.gssapi_bind()
2737e7
-            replication.wait_for_entry(remote_ldap, kdc_dn, timeout=60)
2737e7
+            replication.wait_for_entry(
2737e7
+                remote_ldap,
2737e7
+                kdc_dn,
2737e7
+                timeout=api.env.replication_wait_timeout
2737e7
+            )
2737e7
 
2737e7
     def _call_certmonger(self, certmonger_ca='IPA'):
2737e7
         subject = str(DN(('cn', self.fqdn), self.subject_base))
2737e7
diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
95ea96
index 6d9878e16faab1b88a5ab79649571de6802c8536..5ce8fa689c1a6fd3b9d4cbddbd5454d36334b729 100644
2737e7
--- a/ipaserver/install/replication.py
2737e7
+++ b/ipaserver/install/replication.py
95ea96
@@ -161,7 +161,7 @@ def wait_for_task(conn, dn):
2737e7
     return exit_code
2737e7
 
2737e7
 
2737e7
-def wait_for_entry(connection, dn, timeout=7200, attr=None, attrvalue='*',
2737e7
+def wait_for_entry(connection, dn, timeout, attr=None, attrvalue='*',
2737e7
                    quiet=True):
2737e7
     """Wait for entry and/or attr to show up
2737e7
     """
95ea96
@@ -751,7 +751,9 @@ class ReplicationManager(object):
2737e7
             # that we will have to set the memberof fixup task
2737e7
             self.need_memberof_fixup = True
2737e7
 
2737e7
-        wait_for_entry(a_conn, entry.dn)
2737e7
+        wait_for_entry(
2737e7
+            a_conn, entry.dn, timeout=api.env.replication_wait_timeout
2737e7
+        )
2737e7
 
2737e7
     def needs_memberof_fixup(self):
2737e7
         return self.need_memberof_fixup
2737e7
-- 
95ea96
2.14.4
2737e7