Skip to content
Snippets Groups Projects
Commit e3a52914 authored by Fabrice Le Goff's avatar Fabrice Le Goff
Browse files

do not crash when klist fails

parent 01a0f534
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -353,16 +353,24 @@ def krb_tokenexpiration(logger): ...@@ -353,16 +353,24 @@ def krb_tokenexpiration(logger):
klist = subprocess.Popen(['klist',], env = envm, stdout=subprocess.PIPE, klist = subprocess.Popen(['klist',], env = envm, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
ret = klist.wait() ret = klist.wait()
out = klist.stdout.read() out = klist.stdout.read()
logger.debug('klist done. Return code: %d Output: %s' % (ret,out)) logger.debug('klist done. Return code: %d Output: %s' % (ret,out))
if ret:
self.logger.critical('klist failed: retcode=%s, output=%s', str(ret), out)
return datetime.datetime(1970, 1, 1)
ticket = None
out = out.split('\n') out = out.split('\n')
for idx,l in enumerate(out): for idx,l in enumerate(out):
if 'Valid' in l: if 'Valid' in l:
ticket = out[idx+1] ticket = out[idx+1]
break break
if ticket is None:
self.logger.critical('error parsing klist output: output=%s', out)
return datetime.datetime(1970, 1, 1)
ticket = ticket.split() ticket = ticket.split()
logger.debug('Ticket expiration: %s' % ticket) logger.debug('Ticket expiration: %s' % ticket)
return datetime.datetime.strptime(' '.join(ticket[2:4]), \ return datetime.datetime.strptime(' '.join(ticket[2:4]), \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment