summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-01-21 07:23:20 -0500
committerMartin Kosek <mkosek@redhat.com>2013-03-01 16:59:45 +0100
commit5271eb217c4227a83ac99f9c8daa7e853871523a (patch)
treedf833ba7f8a740b2675433a76cf59720c963fb9e
parentb69f6983e4bb01e2af63c4b02a0ab79b24e59569 (diff)
downloadfreeipa-5271eb217c4227a83ac99f9c8daa7e853871523a.tar.gz
freeipa-5271eb217c4227a83ac99f9c8daa7e853871523a.tar.xz
freeipa-5271eb217c4227a83ac99f9c8daa7e853871523a.zip
Replace IPAdmin.checkTask by replication.wait_for_task
The method was only used for waiting, not actual checking. Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
-rw-r--r--ipaserver/install/dsinstance.py2
-rw-r--r--ipaserver/install/replication.py25
-rw-r--r--ipaserver/ipaldap.py24
3 files changed, 24 insertions, 27 deletions
diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py
index 9eca4b50e..8ee492c4c 100644
--- a/ipaserver/install/dsinstance.py
+++ b/ipaserver/install/dsinstance.py
@@ -466,7 +466,7 @@ class DsInstance(service.Service):
conn.simple_bind_s(DN(('cn', 'directory manager')), self.dm_password)
else:
conn.do_sasl_gssapi_bind()
- conn.checkTask(dn, dowait=True)
+ replication.wait_for_task(conn, dn)
conn.unbind()
def apply_updates(self):
diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
index d604cf7b3..eaf4c4950 100644
--- a/ipaserver/install/replication.py
+++ b/ipaserver/install/replication.py
@@ -110,6 +110,27 @@ def enable_replication_version_checking(hostname, realm, dirman_passwd):
else:
conn.unbind()
+
+def wait_for_task(conn, dn):
+ """Check task status
+
+ Task is complete when the nsTaskExitCode attr is set.
+
+ :return: the task's return code
+ """
+ assert isinstance(dn, DN)
+ attrlist = [
+ 'nsTaskLog', 'nsTaskStatus', 'nsTaskExitCode', 'nsTaskCurrentItem',
+ 'nsTaskTotalItems']
+ while True:
+ entry = conn.get_entry(dn, attrlist)
+ if entry.getValue('nsTaskExitCode'):
+ exit_code = int(entry.getValue('nsTaskExitCode'))
+ break
+ time.sleep(1)
+ return exit_code
+
+
class ReplicationManager(object):
"""Manage replication agreements between DS servers, and sync
agreements with Windows servers"""
@@ -1206,7 +1227,7 @@ class ReplicationManager(object):
print "This may be safely interrupted with Ctrl+C"
- self.conn.checkTask(dn, dowait=True)
+ wait_for_task(self.conn, dn)
def abortcleanallruv(self, replicaId):
"""
@@ -1233,4 +1254,4 @@ class ReplicationManager(object):
print "This may be safely interrupted with Ctrl+C"
- self.conn.checkTask(dn, dowait=True)
+ wait_for_task(self.conn, dn)
diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py
index 7253bc1f7..544982504 100644
--- a/ipaserver/ipaldap.py
+++ b/ipaserver/ipaldap.py
@@ -1770,30 +1770,6 @@ class IPAdmin(LDAPConnection):
return entry
- def checkTask(self, dn, dowait=False, verbose=False):
- """check task status - task is complete when the nsTaskExitCode attr
- is set return a 2 tuple (true/false,code) first is false if task is
- running, true if done - if true, second is the exit code - if dowait
- is True, this function will block until the task is complete
- """
- assert isinstance(dn, DN)
- attrlist = ['nsTaskLog', 'nsTaskStatus', 'nsTaskExitCode', 'nsTaskCurrentItem', 'nsTaskTotalItems']
- done = False
- exitCode = 0
- while not done:
- try:
- entry = self.getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)", attrlist)
- except errors.NotFound:
- break
- if verbose:
- print entry
- if entry.getValue('nsTaskExitCode'):
- exitCode = int(entry.getValue('nsTaskExitCode'))
- done = True
- if dowait: time.sleep(1)
- else: break
- return (done, exitCode)
-
def __getattr__(self, attrname):
# This makes IPAdmin classes look like IPASimpleLDAPObjects
# FIXME: for backwards compatibility only