From 485b01418acded85b8668410d2acf043f97f1542 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Tue, 30 Aug 2022 14:00:59 -0700 Subject: [PATCH] tools: fix reload script for bgp graceful-shutdown Global BGP configuration knob like 'bgp graceful-shutdown' is not rendered properly via frr-reload script. when the config line is rendered if happened to be post router bgp config lines, frr end up rendering bgp gr-shut under bgp instance config though global config knob is set. Two fixes: 1) Move bgp global config line at the beginning of pending config lines to add. 2) Skip adding bgp global config line in second pass of frr-reload script run. The second fix is required to avoid following scenario: 2022-08-30 20:40:53,397 DEBUG: Running Frr Config (Pass #0) ['bgp graceful-shutdown\n', 'router bgp 65564\n timers bgp 3 9\n', 'router bgp 65564\n bgp deterministic-med\n', 2022-08-30 20:40:54,042 DEBUG: Running Frr Config (Pass #1) 'vrf mgmt\n', 'router bgp 65564 vrf sym_1\n address-family l2vpn evpn\n', 'bgp graceful-shutdown\n', <<<<<<< reapp %Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown line 97: Failure to communicate[13] to bgpd, line: bgp graceful-shutdown [8816|bgpd] Configuration file[/etc/frr/frr.conf] processing failure: 13 Ticket: #3187405 Testing Done: Add and remove 'bgp graceful-shutdown' config in frr.conf and perform frr-reload. Signed-off-by: Chirag Shah --- tools/frr-reload.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index ac51132f0ff9..dd340040c92c 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -804,6 +804,30 @@ def bgp_delete_inst_move_line(lines_to_del): lines_to_del.append((ctx_keys, line)) +def bgp_move_global_cfg_line_to_add(lines_to_add): + + # Move global bgp config lines like 'bgp graceful-shutdown' + # at the begining of the config line so they do not appear + # after router bgp sets of config lines as it may turn out + # the config line is applied at bgp instance level. + + index = 0 + lines_to_insert = [] + + for ctx_keys, line in lines_to_add: + if ( + ctx_keys[0].startswith("bgp graceful-shutdown") + and not line + ): + lines_to_add.remove((ctx_keys, line)) + lines_to_insert.append((ctx_keys, line)) + + for ctx_keys, line in lines_to_insert: + lines_to_add.insert(index, ((ctx_keys, line))) + + return lines_to_add + + def bgp_delete_nbr_remote_as_line(lines_to_add): # Handle deletion of neighbor remote-as line from # lines_to_add if the nbr is configured with peer-group and @@ -922,6 +946,7 @@ def bgp_delete_move_lines(lines_to_add, lines_to_del): # config line to the end of the lines_to_del list. bgp_delete_nbr_remote_as_line(lines_to_add) + bgp_move_global_cfg_line_to_add(lines_to_add) del_dict = dict() del_nbr_dict = dict() @@ -2454,6 +2479,13 @@ def is_evpn_enabled(): if x == 1 and ctx_keys[0].startswith("no "): continue + # Also, do not run bgp global config knob in second run + # as it may end being in different vtysh context. + if x == 1: + if ctx_keys[0].startswith("no ") or \ + ctx_keys[0].startswith("bgp graceful-shutdown"): + continue + cmd = "\n".join(lines_to_config(ctx_keys, line, False)) + "\n" lines_to_configure.append(cmd)