|
From: Alain S. <asp...@gm...> - 2007-01-27 11:59:58
|
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=3D'localhost'
port=3D389
who=3D'cn=3Dnobody,cn=3Dinternal,dc=3Dasxnet,dc=3Dloc'
cred=3D'iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc'
dn=3D'dc=3Dasxnet,dc=3Dloc'
def ldap_service(action):
os.system('/kolab/bin/openpkg rc openldap %s' % action)
if action.endswith('start'):
time.sleep(1)
def check_connection():
whoami=3Dl.whoami_s()
print 'whoami', whoami
# this search dont give any result as anonymous, but well if
loggged as nobody
#result=3Dl.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE,
"(member=3Dcn=3Ddomain.maintainer
mydomain.loc,cn=3Dinternal,dc=3Dasxnet,dc=3Dloc)")
#print 'search', result
ldap_url=3Dldapurl.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=3Dldap.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=F6der <mi...@st...> 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.
>
--=20
--
Alain Spineux
aspineux gmail com
May the sources be with you
|