ReconnectLDAPObject doesn't reconnect after main failure
Alain Spineux
aspineux at gmail.com
Sat Jan 27 12:59:58 CET 2007
Yes, we did it !
My test case is working with your CVS !
I put it at the end.
And what about the idea to put the
try:
except ldap.SERVER_DOWN,e:
SimpleLDAPObject.unbind_s(self)
in the function _ldap_call too ?
This will correct also SimpleLDAPObject ?
import sys, os, time
import ldap, ldapurl
host='localhost'
port=389
who='cn=nobody,cn=internal,dc=asxnet,dc=loc'
cred='iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc'
dn='dc=asxnet,dc=loc'
def ldap_service(action):
os.system('/kolab/bin/openpkg rc openldap %s' % action)
if action.endswith('start'):
time.sleep(1)
def check_connection():
whoami=l.whoami_s()
print 'whoami', whoami
# this search dont give any result as anonymous, but well if
loggged as nobody
#result=l.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE,
"(member=cn=domain.maintainer
mydomain.loc,cn=internal,dc=asxnet,dc=loc)")
#print 'search', result
ldap_url=ldapurl.LDAPUrl('ldap://%s:%d/%s' % (host, port, dn))
ldap_url.applyDefaults({
'who': who,
'cred' : cred, })
# to be sure the server is up
ldap_service('stop')
ldap_service('start')
l=ldap.ldapobject.ReconnectLDAPObject(ldap_url.initializeUrl(),1) # I
dont use ReconnectLDAPObject !
l.simple_bind_s(ldap_url.who, ldap_url.cred)
check_connection()
print 'Wait 120s'
time.sleep(120)
check_connection()
print 'restart service'
ldap_service('stop')
ldap_service('start')
check_connection()
print 'stop service'
ldap_service('stop')
try:
check_connection()
except ldap.SERVER_DOWN:
print 'check failed, OK'
print 'restart service'
ldap_service('start')
check_connection()
On 1/27/07, Michael Ströder <michael at stroeder.com> wrote:
> Alain Spineux wrote:
> >
> > The problem is the failed statement has initiated a new connection
> > (when the server is down)
> > calling initialize (that doesn't fail) and bind that fail but is in a
> > try: except: block in ReconnectLDAPObject.reconnect() !
> > Then the server restart and the next statement get advantages of the
> > work done initialize
>
> Yes. Inspired by you mentioning libldap I remembered that unbind_s()
> should be called when handling ldap.SERVER_DOWN exception to completely
> drop the whole connection context.
>
> Please test the version I've committed some minutes ago.
> Thanks again.
>
> Ciao, Michael.
>
--
--
Alain Spineux
aspineux gmail com
May the sources be with you
More information about the python-ldap
mailing list