From a17c70449a766dbc00a7ab8438c13a2a12745614 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 8 Dec 2021 09:51:27 +0100 Subject: mpls: T4024: use FRRConfig() class for config reloading --- src/conf_mode/protocols_mpls.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/conf_mode/protocols_mpls.py b/src/conf_mode/protocols_mpls.py index 3b27608da..d424338d8 100755 --- a/src/conf_mode/protocols_mpls.py +++ b/src/conf_mode/protocols_mpls.py @@ -74,28 +74,15 @@ def generate(mpls): return None def apply(mpls): - # Define dictionary that will load FRR config - frr_cfg = {} + ldpd_damon = 'ldpd' # Save original configuration prior to starting any commit actions - frr_cfg['original_config'] = frr.get_configuration(daemon='ldpd') - frr_cfg['modified_config'] = frr.replace_section(frr_cfg['original_config'], mpls['new_frr_config'], from_re='mpls.*') - - # If FRR config is blank, rerun the blank commit three times due to frr-reload - # behavior/bug not properly clearing out on one commit. - if mpls['new_frr_config'] == '': - for x in range(3): - frr.reload_configuration(frr_cfg['modified_config'], daemon='ldpd') - elif not 'ldp' in mpls: - for x in range(3): - frr.reload_configuration(frr_cfg['modified_config'], daemon='ldpd') - else: - # FRR mark configuration will test for syntax errors and throws an - # exception if any syntax errors is detected - frr.mark_configuration(frr_cfg['modified_config']) + frr_cfg = frr.FRRConfig() - # Commit resulting configuration to FRR, this will throw CommitError - # on failure - frr.reload_configuration(frr_cfg['modified_config'], daemon='ldpd') + frr_cfg.load_configuration(ldpd_damon) + frr_cfg.modify_section(f'^mpls ldp') + frr_cfg.add_before(r'(ip prefix-list .*|route-map .*|line vty|end)', mpls['new_frr_config']) + for x in range(3): + frr_cfg.commit_configuration(ldpd_damon) # Set number of entries in the platform label tables labels = '0' -- cgit v1.2.3