From 025f0609cea8591e93b8cb4a7d0256e43e23323b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 5 Dec 2021 21:23:23 +0100 Subject: vrrp: T4041: bugfix sync-group transition-scripts not executed While mangling the config dict retrieved via get_config_dict() into a private representation of a configuration dictionary sync-groups were never accounted for. Instead everything always ended up in the regular vrrp transition-script section. The implementation has been changed to directly work on the content of get_config_dict() to stop any confusion and making redundant data copies obsolete. --- src/system/keepalived-fifo.py | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) (limited to 'src/system/keepalived-fifo.py') diff --git a/src/system/keepalived-fifo.py b/src/system/keepalived-fifo.py index 1fba0d75b..b1fe7e43f 100755 --- a/src/system/keepalived-fifo.py +++ b/src/system/keepalived-fifo.py @@ -29,6 +29,7 @@ from logging.handlers import SysLogHandler from vyos.ifconfig.vrrp import VRRP from vyos.configquery import ConfigTreeQuery from vyos.util import cmd +from vyos.util import dict_search # configure logging logger = logging.getLogger(__name__) @@ -69,22 +70,10 @@ class KeepalivedFifo: raise ValueError() # Read VRRP configuration directly from CLI - vrrp_config_dict = conf.get_config_dict(base, key_mangling=('-', '_'), - get_first_key=True) - self.vrrp_config = {'vrrp_groups': {}, 'sync_groups': {}} - for key in ['group', 'sync_group']: - if key not in vrrp_config_dict: - continue - for group, group_config in vrrp_config_dict[key].items(): - if 'transition_script' not in group_config: - continue - self.vrrp_config['vrrp_groups'][group] = { - 'STOP': group_config['transition_script'].get('stop'), - 'FAULT': group_config['transition_script'].get('fault'), - 'BACKUP': group_config['transition_script'].get('backup'), - 'MASTER': group_config['transition_script'].get('master'), - } - logger.info(f'Loaded configuration: {self.vrrp_config}') + self.vrrp_config_dict = conf.get_config_dict(base, + key_mangling=('-', '_'), get_first_key=True) + + logger.debug(f'Loaded configuration: {self.vrrp_config_dict}') except Exception as err: logger.error(f'Unable to load configuration: {err}') @@ -129,20 +118,17 @@ class KeepalivedFifo: if os.path.exists(mdns_running_file): cmd(mdns_update_command) - if n_name in self.vrrp_config['vrrp_groups'] and n_state in self.vrrp_config['vrrp_groups'][n_name]: - n_script = self.vrrp_config['vrrp_groups'][n_name].get(n_state) - if n_script: - self._run_command(n_script) + tmp = dict_search(f'group.{n_name}.transition_script.{n_state.lower()}', self.vrrp_config_dict) + if tmp != None: + self._run_command(tmp) # check and run commands for VRRP sync groups - # currently, this is not available in VyOS CLI - if n_type == 'GROUP': + elif n_type == 'GROUP': if os.path.exists(mdns_running_file): cmd(mdns_update_command) - if n_name in self.vrrp_config['sync_groups'] and n_state in self.vrrp_config['sync_groups'][n_name]: - n_script = self.vrrp_config['sync_groups'][n_name].get(n_state) - if n_script: - self._run_command(n_script) + tmp = dict_search(f'sync_group.{n_name}.transition_script.{n_state.lower()}', self.vrrp_config_dict) + if tmp != None: + self._run_command(tmp) # mark task in queue as done self.message_queue.task_done() except Exception as err: -- cgit v1.2.3 From bcfe967f607a83192d75c01e7f414655891eec60 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 8 Dec 2021 10:03:43 +0100 Subject: vrrp: T4059: do "late" read of the CLI configuration as this fails in __init__ ... thus we simply read the configuration the first time it really becomes necessary and a message requireing the data needs it actually. --- src/system/keepalived-fifo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/system/keepalived-fifo.py') diff --git a/src/system/keepalived-fifo.py b/src/system/keepalived-fifo.py index b1fe7e43f..cde0c6cc5 100755 --- a/src/system/keepalived-fifo.py +++ b/src/system/keepalived-fifo.py @@ -53,7 +53,7 @@ class KeepalivedFifo: # parse arguments cmd_args = cmd_args_parser.parse_args() - self._config_load() + self.vrrp_config_dict = None self.pipe_path = cmd_args.PIPE # create queue for messages and events for syncronization @@ -97,6 +97,11 @@ class KeepalivedFifo: logger.debug('Message processing start') regex_notify = re.compile(r'^(?P\w+) "(?P[\w-]+)" (?P\w+) (?P\d+)$', re.MULTILINE) while self.stopme.is_set() is False: + # XXX: T4059 - do a "late" read of the CLI configuration as this would fail in __init__. + # Thus we simply read the configuration the first time it really becomes necessary + # and a message requireing the data needs it actually. + if self.vrrp_config_dict == None: + self._config_load() # wait for a new message event from pipe_wait self.message_event.wait() try: -- cgit v1.2.3 From afa50e9d39d7e2599719c411f523d9205c33ad3b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 9 Dec 2021 22:38:45 +0100 Subject: Revert "vrrp: T4059: do "late" read of the CLI configuration as this fails in __init__" This reverts commit bcfe967f607a83192d75c01e7f414655891eec60. --- src/system/keepalived-fifo.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/system/keepalived-fifo.py') diff --git a/src/system/keepalived-fifo.py b/src/system/keepalived-fifo.py index cde0c6cc5..b1fe7e43f 100755 --- a/src/system/keepalived-fifo.py +++ b/src/system/keepalived-fifo.py @@ -53,7 +53,7 @@ class KeepalivedFifo: # parse arguments cmd_args = cmd_args_parser.parse_args() - self.vrrp_config_dict = None + self._config_load() self.pipe_path = cmd_args.PIPE # create queue for messages and events for syncronization @@ -97,11 +97,6 @@ class KeepalivedFifo: logger.debug('Message processing start') regex_notify = re.compile(r'^(?P\w+) "(?P[\w-]+)" (?P\w+) (?P\d+)$', re.MULTILINE) while self.stopme.is_set() is False: - # XXX: T4059 - do a "late" read of the CLI configuration as this would fail in __init__. - # Thus we simply read the configuration the first time it really becomes necessary - # and a message requireing the data needs it actually. - if self.vrrp_config_dict == None: - self._config_load() # wait for a new message event from pipe_wait self.message_event.wait() try: -- cgit v1.2.3