From e3a52914e39b51a26125a57ada70520a2a2a246f Mon Sep 17 00:00:00 2001
From: Fabrice Le Goff <fabrice.le.goff@cern.ch>
Date: Fri, 4 May 2018 17:44:16 +0200
Subject: [PATCH] do not crash when klist fails

---
 Script/CastorScript.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Script/CastorScript.py b/Script/CastorScript.py
index 7177157..06e8fc5 100644
--- a/Script/CastorScript.py
+++ b/Script/CastorScript.py
@@ -353,16 +353,24 @@ def krb_tokenexpiration(logger):
     klist = subprocess.Popen(['klist',], env = envm, stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
     ret = klist.wait()
-
     out = klist.stdout.read()
     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')
     for idx,l in enumerate(out):
         if 'Valid' in l:
             ticket = out[idx+1]
             break
 
+    if ticket is None:
+        self.logger.critical('error parsing klist output: output=%s', out)
+        return datetime.datetime(1970, 1, 1)
+
     ticket = ticket.split()
     logger.debug('Ticket expiration: %s' % ticket)
     return datetime.datetime.strptime(' '.join(ticket[2:4]), \
-- 
GitLab