From 6d65ae5c5fd545f02a92582b3ff8d961b46da0d4 Mon Sep 17 00:00:00 2001 From: Faiyaz Ahmed Date: Thu, 6 Aug 2009 20:21:20 +0000 Subject: [PATCH] loop on authcheck code in case session is wrong AND api is unavailable. --- nm.py | 2 ++ plcapi.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nm.py b/nm.py index ed5309e..85c9004 100755 --- a/nm.py +++ b/nm.py @@ -134,6 +134,7 @@ def run(): plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2) #check auth + logger.log("Checking Auth.") while plc.check_authentication() != True: try: plc.update_session() @@ -141,6 +142,7 @@ def run(): except: logger.log("Retry Failed. Waiting") time.sleep(iperiod) + logger.log("Authentication Succeeded!") while True: diff --git a/plcapi.py b/plcapi.py index 2ef5dc1..be77171 100644 --- a/plcapi.py +++ b/plcapi.py @@ -50,8 +50,13 @@ class PLCAPI: def check_authentication(self): - # just a simple call to check authentication - return self.AuthCheck(self) + authstatus = False + if self.key or self.session: + try: + authstatus = self.AuthCheck() + except: + logger.log_exc() + return authstatus def add_auth(self, function): -- 2.43.0