From 7aa5872239d04b2d0a7cb3b00a9c14b5ea18d013 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 28 Jan 2010 17:24:03 +0000 Subject: [PATCH] logs for when PLC is unreachable --- conf_files.py | 3 ++- logger.py | 6 ++++++ plugins/codemux.py | 3 +++ plugins/rawdisk.py | 2 +- plugins/sliverauth.py | 2 +- plugins/specialaccounts.py | 2 +- plugins/vsys.py | 3 +++ plugins/vsys_privs.py | 3 +++ sm.py | 3 +++ 9 files changed, 23 insertions(+), 4 deletions(-) diff --git a/conf_files.py b/conf_files.py index bccf20a..9e2c257 100644 --- a/conf_files.py +++ b/conf_files.py @@ -79,7 +79,8 @@ class conf_files: for f in data['conf_files']: try: self.update_conf_file(f) except: logger.log_exc("failed to update conf_file") - else: logger.log("conf_files: No conf_files found or API failure. Skipping") + else: + logger.log_missing_data("conf_files.run_once",'conf_files') def start(options, config): pass diff --git a/logger.py b/logger.py index 7dff05e..eff93e6 100644 --- a/logger.py +++ b/logger.py @@ -58,6 +58,12 @@ def log_exc(msg="",name=None): else: log("EXCEPTION caught <%s> \n %s" %(msg, traceback.format_exc())) +# for some reason the various modules are still triggered even when the +# data from PLC cannot be reached +# we show this message instead of the exception stack instead in this case +def log_missing_data (msg,key): + log("%s: could not find the %s key in data (PLC connection down?) - IGNORED"%(msg,key)) + def log_data_in_file (data, file, message=""): import pprint, time try: diff --git a/plugins/codemux.py b/plugins/codemux.py index 84b0f4e..731b74d 100644 --- a/plugins/codemux.py +++ b/plugins/codemux.py @@ -36,6 +36,9 @@ def GetSlivers(data, config, plc = None): else: _writeconf = True # Parse attributes and update dict of scripts + if 'slivers' not in data: + logger.log_missing_data("codemux.GetSlivers", 'slivers') + return for sliver in data['slivers']: for attribute in sliver['attributes']: if attribute['tagname'] == 'codemux': diff --git a/plugins/rawdisk.py b/plugins/rawdisk.py index ad84761..641bc69 100644 --- a/plugins/rawdisk.py +++ b/plugins/rawdisk.py @@ -51,7 +51,7 @@ def get_unused_devices(): def GetSlivers(data, config=None, plc=None): if 'slivers' not in data: - logger.log("sliverauth: getslivers data lack's sliver information. IGNORING!") + logger.log_missing_data("rawdisk.GetSlivers",'slivers') return devices = get_unused_devices() diff --git a/plugins/sliverauth.py b/plugins/sliverauth.py index ad813b8..bf35830 100644 --- a/plugins/sliverauth.py +++ b/plugins/sliverauth.py @@ -46,7 +46,7 @@ def GetSlivers(data, config, plc): return if 'slivers' not in data: - logger.log("sliverauth: getslivers data lack's sliver information. IGNORING!") + logger.log_missing_data("sliverauth.GetSlivers", 'slivers') return for sliver in data['slivers']: diff --git a/plugins/specialaccounts.py b/plugins/specialaccounts.py index 9396062..cef877e 100644 --- a/plugins/specialaccounts.py +++ b/plugins/specialaccounts.py @@ -27,7 +27,7 @@ def start(options, conf): def GetSlivers(data, conf = None, plc = None): if 'accounts' not in data: - logger.log("specialaccounts: No account information found. DISABLED!") + logger.log_missing_data("specialaccounts.GetSlivers",'accounts') return for account in data['accounts']: diff --git a/plugins/vsys.py b/plugins/vsys.py index f33d11b..05b87cd 100644 --- a/plugins/vsys.py +++ b/plugins/vsys.py @@ -22,6 +22,9 @@ def GetSlivers(data, config=None, plc=None): slices = [] _restart = False # Parse attributes and update dict of scripts + if 'slivers' not in data: + logger.log_missing_data("vsys.GetSlivers",'slivers') + return for sliver in data['slivers']: for attribute in sliver['attributes']: if attribute['tagname'] == 'vsys': diff --git a/plugins/vsys_privs.py b/plugins/vsys_privs.py index f30012d..5cd40a2 100755 --- a/plugins/vsys_privs.py +++ b/plugins/vsys_privs.py @@ -23,6 +23,9 @@ def GetSlivers(data, config=None, plc=None): privs = {} # Parse attributes and update dict of scripts + if 'slivers' not in data: + logger.log_missing_data("vsys_privs.GetSlivers",'slivers') + return for sliver in data['slivers']: slice = sliver['name'] for attribute in sliver['attributes']: diff --git a/sm.py b/sm.py index 25b5e87..8c04760 100644 --- a/sm.py +++ b/sm.py @@ -82,6 +82,9 @@ def GetSlivers(data, config = None, plc=None, fullupdate=True): DEFAULT_ALLOCATION['net_max_rate'] = network['bwlimit'] / 1000 # Take intscripts (global) returned by API, make dict + if 'initscripts' not in data: + logger.log_missing_data("sm.GetSlivers",'initscripts') + return initscripts = {} for is_rec in data['initscripts']: logger.verbose("initscript: %s" % is_rec['name']) -- 2.43.0