diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-02-09 21:16:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 21:16:03 +0100 |
commit | a88f543c734548e6924aee9f26268241c948a241 (patch) | |
tree | dd2455777b8dc8c64335b341ed4275c822ab9761 /python/vyos/frr.py | |
parent | e84dece28a7f3e46235f178eec5622547cb2eab6 (diff) | |
parent | 015651a8f6de4cb12614e16d6212142b7985f98f (diff) | |
download | vyos-1x-a88f543c734548e6924aee9f26268241c948a241.tar.gz vyos-1x-a88f543c734548e6924aee9f26268241c948a241.zip |
Merge pull request #726 from runborg/frrdebugging
T2638: Enable more debugging in the FRR library
Diffstat (limited to 'python/vyos/frr.py')
-rw-r--r-- | python/vyos/frr.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/python/vyos/frr.py b/python/vyos/frr.py index 76e204ab3..69c7a14ce 100644 --- a/python/vyos/frr.py +++ b/python/vyos/frr.py @@ -69,8 +69,17 @@ import tempfile import re from vyos import util import logging +from logging.handlers import SysLogHandler +import os LOG = logging.getLogger(__name__) +DEBUG = os.path.exists('/tmp/vyos.frr.debug') +if DEBUG: + LOG.setLevel(logging.DEBUG) + ch = SysLogHandler(address='/dev/log') + ch2 = logging.StreamHandler() + LOG.addHandler(ch) + LOG.addHandler(ch2) _frr_daemons = ['zebra', 'bgpd', 'fabricd', 'isisd', 'ospf6d', 'ospfd', 'pbrd', 'pimd', 'ripd', 'ripngd', 'sharpd', 'staticd', 'vrrpd', 'ldpd'] @@ -175,15 +184,23 @@ def reload_configuration(config, daemon=None): f.write(config) f.flush() + LOG.debug(f'reload_configuration: Reloading config using temporary file: {f.name}') cmd = f'{path_frr_reload} --reload' if daemon: cmd += f' --daemon {daemon}' + + if DEBUG: + cmd += f' --debug --stdout' + cmd += f' {f.name}' + LOG.debug(f'reload_configuration: Executing command against frr-reload: "{cmd}"') output, code = util.popen(cmd, stderr=util.STDOUT) f.close() + for i, e in enumerate(output.split('\n')): + LOG.debug(f'frr-reload output: {i:3} {e}') if code == 1: - raise CommitError(f'Configuration FRR failed while commiting code: {repr(output)}') + raise CommitError(f'Configuration FRR failed while commiting code, please enabling debugging to examine logs') elif code: raise OSError(code, output) @@ -382,6 +399,11 @@ class FRRConfig: raise ValueError( 'The config element needs to be a string or list type object') + if config: + LOG.debug(f'__init__: frr library initiated with initial config') + for i, e in enumerate(self.config): + LOG.debug(f'__init__: initial {i:3} {e}') + def load_configuration(self, daemon=None): '''Load the running configuration from FRR into the config object daemon: str with name of the FRR Daemon to load configuration from or @@ -390,9 +412,16 @@ class FRRConfig: Using this overwrites the current loaded config objects and replaces the original loaded config ''' self.imported_config = get_configuration(daemon=daemon) - LOG.debug(f'load_configuration: Configuration loaded from FRR: {self.imported_config}') + if daemon: + LOG.debug(f'load_configuration: Configuration loaded from FRR daemon {daemon}') + else: + LOG.debug(f'load_configuration: Configuration loaded from FRR integrated config') + self.original_config = self.imported_config.split('\n') self.config = self.original_config.copy() + + for i, e in enumerate(self.imported_config.split('\n')): + LOG.debug(f'load_configuration: loaded {i:3} {e}') return def test_configuration(self): @@ -408,6 +437,8 @@ class FRRConfig: None to use the consolidated config ''' LOG.debug('commit_configuration: Commiting configuration') + for i, e in enumerate(self.config): + LOG.debug(f'commit_configuration: new_config {i:3} {e}') reload_configuration('\n'.join(self.config), daemon=daemon) def modify_section(self, start_pattern, replacement=[], stop_pattern=r'\S+', remove_stop_mark=False, count=0): |