Добавлены повторные соединения с необходимыми задержками в случае невозможности соединиться с LDAP сервером после его перезагрузки.

git-svn-id: http://svn.calculate.ru/calculate2/calculate-server/trunk@1305 c91db197-33c1-4113-bf15-f8a5c547ca64
develop
asamoukin 15 years ago
parent d98765d2e9
commit 4cf003d159

@ -270,6 +270,13 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
'901',
'Admin samba user')}
def genSleep(self):
"""Генератор задержек"""
timeSleep = (0.2, 0.4, 0.8)
for t in timeSleep:
time.sleep(t)
yield(t)
def reloadDefaultVar(self, nameVar):
"""При получениии значения переменной снова
@ -279,14 +286,6 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
self.clVars.__getattribute__(nameVar).fillStart = True
return True
def genSleep(self):
"""Генератор задержек"""
deltaTime = (0.2, 0.4, 0.8)
for t in deltaTime:
time.sleep(t)
yield t
def addInfoGroup(self, name, gid, comment):
"""Добавляем информацию о группе"""
class group():
@ -519,8 +518,6 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
textLines = self.execProg("/etc/init.d/slapd start", False, False)
if textLines and type(textLines) == types.ListType and\
"ok" in textLines[-1] or textLines and "ok" in textLines:
# Задержка нужная для виртуальной машины
time.sleep(0.5)
return True
else:
self.printNotOK(_("Starting LDAP")+ " ...")
@ -531,8 +528,6 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
textLines = self.execProg("/etc/init.d/slapd restart", False, False)
if textLines and type(textLines) == types.ListType and\
"ok" in textLines[-1] or textLines and "ok" in textLines:
# Задержка нужная для виртуальной машины
time.sleep(0.5)
return True
else:
self.printNotOK(_("Restarting LDAP")+ " ...")
@ -1488,6 +1483,11 @@ This command is not allowed."))
В выходном объекте есть соединение с LDAP сервером: self.conLdap
"""
# Если раннее была ошибка то выходим
if self.getError():
self.printERROR (_("ERROR") + ": " +\
self.getError().strip())
return False
ldapParser = iniLdapParser()
adminDn = ldapParser.getVar(part,"DN")
adminPw = ldapParser.getVar(part,"PASS")
@ -1501,13 +1501,24 @@ This command is not allowed."))
" ...")
return False
ldapObj = ldapFunction(adminDn, adminPw)
# Генератор задержек
wait = self.genSleep()
while ldapObj.getError():
try:
# Задержка
wait.next()
except StopIteration:
break
# Очистка ошибки
cl_profile._error.error = []
ldapObj = ldapFunction(adminDn, adminPw)
if ldapObj.getError():
# Удаляем одинаковые ошибки
listError = []
for e in ldapObj.error:
if not e in listError:
listError.append(e)
ldapObj.error = listError
cl_profile._error.error = listError
self.printERROR (_("LDAP connect error") + ": " +\
ldapObj.getError().strip())
return False
@ -7124,13 +7135,35 @@ for running replication")%bFile)
"""Соединяемся с LDAP сервером
используем DN и пароль временного админстратора
"""
"""
# Если раннее была ошибка то выходим
if self.getError():
self.printERROR (_("ERROR") + ": " +\
self.getError().strip())
return False
tmpDn = self.clVars.Get("ld_temp_dn")
tmpPw = self.clVars.Get("ld_temp_pw")
ldapObj = ldapFunction(tmpDn, tmpPw)
# Генератор задержек
wait = self.genSleep()
while ldapObj.getError():
try:
# Задержка
wait.next()
except StopIteration:
break
# Очистка ошибки
cl_profile._error.error = []
ldapObj = ldapFunction(tmpDn, tmpPw)
self.ldapObj = ldapObj
self.conLdap = ldapObj.conLdap
if self.ldapObj.getError():
if ldapObj.getError():
# Удаляем одинаковые ошибки
listError = []
for e in ldapObj.error:
if not e in listError:
listError.append(e)
cl_profile._error.error = listError
self.printERROR(_("Can not connected to LDAP server") + " ...")
return False
return True

Loading…
Cancel
Save