summaryrefslogtreecommitdiffstats
path: root/ipatests/test_integration/tasks.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-07-17 14:28:05 +0200
committerPetr Viktorin <pviktori@redhat.com>2013-07-25 12:41:26 +0200
commit2f80855e156fe5966ee33d486aa25f49637dd3e0 (patch)
tree4ef4d196021e2f40f084a8b2d229009f36a15b4c /ipatests/test_integration/tasks.py
parent15e83befaf9e3db0806960ba8bcef339b8e39ff7 (diff)
downloadfreeipa-2f80855e156fe5966ee33d486aa25f49637dd3e0.tar.gz
freeipa-2f80855e156fe5966ee33d486aa25f49637dd3e0.tar.xz
freeipa-2f80855e156fe5966ee33d486aa25f49637dd3e0.zip
test_simple_replication: Wait for replication to finish before checking
Add ldap_connect() method to Host to allow executing querying LDAP from tests. Use information in the mapping tree to poll until all replication is finished (or failing) before checking that entries replicated successfully.
Diffstat (limited to 'ipatests/test_integration/tasks.py')
-rw-r--r--ipatests/test_integration/tasks.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py
index 609df8130..69a34a287 100644
--- a/ipatests/test_integration/tasks.py
+++ b/ipatests/test_integration/tasks.py
@@ -24,8 +24,13 @@ import textwrap
import re
import collections
import itertools
+import time
+import StringIO
+
+from ldif import LDIFWriter
from ipapython import ipautil
+from ipapython.dn import DN
from ipapython.ipa_log_manager import log_mgr
from ipatests.test_integration.config import env_to_script
@@ -379,3 +384,48 @@ def install_clients(servers, clients):
for server, client in itertools.izip(itertools.cycle(servers), clients):
log.info('Installing client %s on %s' % (server, client))
install_client(server, client)
+
+
+def _entries_to_ldif(entries):
+ """Format LDAP entries as LDIF"""
+ lines = []
+ io = StringIO.StringIO()
+ writer = LDIFWriter(io)
+ for entry in entries:
+ writer.unparse(str(entry.dn), entry)
+ return io.getvalue()
+
+
+def wait_for_replication(ldap, timeout=30):
+ """Wait until updates on all replication agreements are done (or failed)
+
+ :param ldap: LDAP client
+ autenticated with necessary rights to read the mapping tree
+ :param timeout: Maximum time to wait, in seconds
+
+ Note that this waits for updates originating on this host, not those
+ coming from other hosts.
+ """
+ log.debug('Waiting for replication to finish')
+ for i in range(timeout):
+ time.sleep(1)
+ status_attr = 'nsds5replicaLastUpdateStatus'
+ progress_attr = 'nsds5replicaUpdateInProgress'
+ entries = ldap.get_entries(
+ DN(('cn', 'mapping tree'), ('cn', 'config')),
+ filter='(objectclass=nsds5replicationagreement)',
+ attrs_list=[status_attr, progress_attr])
+ log.debug('Replication agreements: \n%s', _entries_to_ldif(entries))
+ if any(not e.single_value(status_attr).startswith('0 ')
+ for e in entries):
+ log.error('Replication error')
+ break
+ in_progress = []
+ if any(e.single_value(progress_attr) == 'TRUE' for e in entries):
+ log.debug('Replication in progress (waited %s/%ss)',
+ i, timeout)
+ else:
+ log.debug('Replication finished')
+ break
+ else:
+ log.error('Giving up wait for replication to finish')