From fd3e94da9f84f72f9474eeacaa6419329544917e Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 24 Jun 2022 01:09:30 +0100 Subject: [PATCH] Comment out bridge and config pickle Reset bridges on logout. --- bridge_master.py | 65 ++++++++++++++++++++++++++---------------------- hblink.py | 2 ++ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index fee93d1..630ca17 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -757,6 +757,10 @@ def ident(): def options_config(): logger.debug('(OPTIONS) Running options parser') for _system in CONFIG['SYSTEMS']: + if '_reset' in CONFIG['SYSTEMS'][_system] and CONFIG['SYSTEMS'][_system]['_reset']: + logger.debug('(OPTIONS) Bridge reset for %s - no peers'._system) + remove_bridge_system(_system) + CONFIG['SYSTEMS'][_system]['_reset'] = False try: if CONFIG['SYSTEMS'][_system]['MODE'] != 'MASTER': continue @@ -2846,22 +2850,22 @@ if __name__ == '__main__': if not cli_args.CONFIG_FILE: cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' - configP = False - file_exists = os.path.isfile('config.pkl') == True - if file_exists: - if os.path.getmtime('config.pkl') > (time() - 25): - try: - with open('config.pkl','rb') as _fh: - CONFIG = pickle.load(_fh) - print('(CONFIG) loaded config .pkl from previous shutdown') - configP = True - except: - print('(CONFIG) Cannot load config.pkl file') - CONFIG = config.build_config(cli_args.CONFIG_FILE) - else: - os.unlink("config.pkl") - else: - CONFIG = config.build_config(cli_args.CONFIG_FILE) + #configP = False + #if os.path.isfile('config.pkl'): + #if os.path.getmtime('config.pkl') > (time() - 25): + #try: + #with open('config.pkl','rb') as _fh: + #CONFIG = pickle.load(_fh) + #print('(CONFIG) loaded config .pkl from previous shutdown') + #configP = True + #except: + #print('(CONFIG) Cannot load config.pkl file') + #CONFIG = config.build_config(cli_args.CONFIG_FILE) + #else: + #os.unlink("config.pkl") + #else: + + CONFIG = config.build_config(cli_args.CONFIG_FILE) # Ensure we have a path for the rules file, if one wasn't specified, then use the default (top of file) if not cli_args.RULES_FILE: @@ -2948,20 +2952,21 @@ if __name__ == '__main__': sys.exit('(ROUTER) TERMINATING: Routing bridges file not found or invalid: {}'.format(cli_args.RULES_FILE)) #Load pickle of bridges if it's less than 25 seconds old - if os.path.isfile('bridge.pkl'): - if os.path.getmtime('config.pkl') > (time() - 25): - try: - with open('bridge.pkl','rb') as _fh: - BRIDGES = pickle.load(_fh) - logger.info('(BRIDGE) loaded bridge.pkl from previous shutdown') - except: - logger.warning('(BRIDGE) Cannot load bridge.pkl file') - BRIDGES = make_bridges(rules_module.BRIDGES) - else: - BRIDGES = make_bridges(rules_module.BRIDGES) - os.unlink("bridge.pkl") - else: - BRIDGES = make_bridges(rules_module.BRIDGES) + #if os.path.isfile('bridge.pkl'): + #if os.path.getmtime('config.pkl') > (time() - 25): + #try: + #with open('bridge.pkl','rb') as _fh: + #BRIDGES = pickle.load(_fh) + #logger.info('(BRIDGE) loaded bridge.pkl from previous shutdown') + #except: + #logger.warning('(BRIDGE) Cannot load bridge.pkl file') + #BRIDGES = make_bridges(rules_module.BRIDGES) + #else: + #BRIDGES = make_bridges(rules_module.BRIDGES) + #os.unlink("bridge.pkl") + #else: + + BRIDGES = make_bridges(rules_module.BRIDGES) #Subscriber map for unit calls - complete with test entry diff --git a/hblink.py b/hblink.py index ce58794..c4b27b7 100755 --- a/hblink.py +++ b/hblink.py @@ -776,8 +776,10 @@ class HBSYSTEM(DatagramProtocol): if '_default_options' in self._CONFIG['SYSTEMS'][self._system]: logger.info('(%s) Setting default Options: %s',self._system, self._CONFIG['SYSTEMS'][self._system]['_default_options']) self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] = self._CONFIG['SYSTEMS'][self._system]['_default_options'] + self._CONFIG['SYSTEMS'][self._system]['_reset'] = True else: del self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] + self._CONFIG['SYSTEMS'][self._system]['_reset'] = True logger.info('(%s) Deleting HBP Options',self._system) # Aliased in __init__ to maintenance_loop if system is a peer