diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-12-05 21:23:23 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-12-05 21:25:58 +0100 |
commit | ec13cac66ba612ecc36053158c7517c8fe993547 (patch) | |
tree | b23d5262a1b546bc826b9459709c674713acfa46 /src | |
parent | 55f6c1352fc5b2b8d051497e7fe97a4e62caf1fe (diff) | |
download | vyos-1x-ec13cac66ba612ecc36053158c7517c8fe993547.tar.gz vyos-1x-ec13cac66ba612ecc36053158c7517c8fe993547.zip |
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.
(cherry picked from commit 025f0609cea8591e93b8cb4a7d0256e43e23323b)
Diffstat (limited to 'src')
-rwxr-xr-x | src/system/keepalived-fifo.py | 38 |
1 files changed, 12 insertions, 26 deletions
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: |