URL: https://github.com/freeipa/freeipa/pull/402
Author: MartinBasti
 Title: #402: [master] wait_for_entry improvements
Action: opened

PR body:
"""
Backport useful commits from #401 to master
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/402/head:pr402
git checkout pr402
From 3344c7001d68560be2a88daa65396b9d7f8c357c Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Wed, 18 Jan 2017 12:55:13 +0100
Subject: [PATCH 1/2] wait_for_entry: use only DN as parameter

Using the whole entry is not needed as parameter because only DN is used
and it prevents easier usage of this function

https://fedorahosted.org/freeipa/ticket/6588
---
 ipaserver/install/dogtaginstance.py | 2 +-
 ipaserver/install/replication.py    | 6 ++----
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py
index 4c02d73..2ebff6b 100644
--- a/ipaserver/install/dogtaginstance.py
+++ b/ipaserver/install/dogtaginstance.py
@@ -459,7 +459,7 @@ def setup_admin(self):
         ldap_uri = ipaldap.get_ldap_uri(self.master_host)
         master_conn = ipaldap.LDAPClient(ldap_uri)
         master_conn.gssapi_bind()
-        replication.wait_for_entry(master_conn, entry)
+        replication.wait_for_entry(master_conn, entry.dn)
         del master_conn
 
     def __remove_admin_from_group(self, group):
diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
index 9ce93fc..c4260dd 100644
--- a/ipaserver/install/replication.py
+++ b/ipaserver/install/replication.py
@@ -155,7 +155,7 @@ def wait_for_task(conn, dn):
     return exit_code
 
 
-def wait_for_entry(connection, entry, timeout=7200, attr='', quiet=True):
+def wait_for_entry(connection, dn, timeout=7200, attr='', quiet=True):
     """Wait for entry and/or attr to show up"""
 
     filter = "(objectclass=*)"
@@ -165,8 +165,6 @@ def wait_for_entry(connection, entry, timeout=7200, attr='', quiet=True):
         attrlist.append(attr)
     timeout += int(time.time())
 
-    dn = entry.dn
-
     if not quiet:
         sys.stdout.write("Waiting for %s %s:%s " % (connection, dn, attr))
         sys.stdout.flush()
@@ -733,7 +731,7 @@ def setup_agreement(self, a_conn, b_hostname, port=389,
             # that we will have to set the memberof fixup task
             self.need_memberof_fixup = True
 
-        wait_for_entry(a_conn, entry)
+        wait_for_entry(a_conn, entry.dn)
 
     def needs_memberof_fixup(self):
         return self.need_memberof_fixup

From de575f6df7bb0aaf0c0de665f259d51c81636b2f Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Wed, 18 Jan 2017 17:08:19 +0100
Subject: [PATCH 2/2] Use proper logging for error messages

https://fedorahosted.org/freeipa/ticket/6588r
---
 ipaserver/install/replication.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
index c4260dd..1f13783 100644
--- a/ipaserver/install/replication.py
+++ b/ipaserver/install/replication.py
@@ -176,7 +176,7 @@ def wait_for_entry(connection, dn, timeout=7200, attr='', quiet=True):
         except errors.NotFound:
             pass  # no entry yet
         except Exception as e:  # badness
-            print("\nError reading entry", dn, e)
+            root_logger.error("Error reading entry %s: %s", dn, e)
             break
         if not entry:
             if not quiet:
@@ -185,11 +185,13 @@ def wait_for_entry(connection, dn, timeout=7200, attr='', quiet=True):
             time.sleep(1)
 
     if not entry and int(time.time()) > timeout:
-        print("\nwait_for_entry timeout for %s for %s" % (connection, dn))
+        root_logger.error(
+            "wait_for_entry timeout for %s for %s", connection, dn)
     elif entry and not quiet:
-        print("\nThe waited for entry is:", entry)
+        root_logger.error("The waited for entry is: %s", entry)
     elif not entry:
-        print("\nError: could not read entry %s from %s" % (dn, connection))
+        root_logger.error(
+            "Error: could not read entry %s from %s", dn, connection)
 
 
 class ReplicationManager(object):
-- 
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