From d2acc328bd776f31638d957444ea610eb7e4d132 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Sat, 4 Dec 2021 13:27:29 -0800 Subject: [PATCH 1/3] tools: fix bgp instances deletion in frr-reload BGPd does not allow default instance deletion in presence of bgp vrf instance; frr-reload script fails if delete list contains default instance followed by vrf instance. Fix: frr-reload scans lines_to_delete to look for 'router bgp' and 'router bgp vrf ...' line. If both are present switch the order to delete bgp vrf instance(s) than default instance at the end. Testing Done: Before: INFO: Loading Config object from file /etc/frr/frr.conf INFO: Loading Config object from vtysh show running INFO: Failed to execute no router bgp 40201 <-- Failed to delete INFO: Failed to execute no router bgp INFO: Failed to execute no router ERROR: "no router" we failed to remove this command ERROR: % Cannot delete default BGP instance. Dependent VRF instances exist INFO: Executed "no router bgp 40201 vrf bgp-test" <-- vrf instance deleted INFO: Loading Config object from vtysh show running After: order of deletion switched INFO: Loading Config object from file /etc/frr/frr.conf INFO: Loading Config object from vtysh show running INFO: Executed "no router bgp 40201 vrf bgp-test" INFO: Executed "no router bgp 40201" INFO: Loading Config object from vtysh show running Signed-off-by: Chirag Shah --- tools/frr-reload.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 4f30f7fbd8..8749215b1e 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -763,6 +763,38 @@ def check_for_exit_vrf(lines_to_add, lines_to_del): return (lines_to_add, lines_to_del) +def bgp_delete_inst_move_line(lines_to_del): + # Deletion of bgp default inst followed by + # bgp vrf inst leads to issue of default + # instance can not be removed. + # Move the bgp default instance line to end. + bgp_defult_inst = False + bgp_vrf_inst = False + + for (ctx_keys, line) in lines_to_del: + # Find bgp default inst + if ( + ctx_keys[0].startswith("router bgp") + and not line + and "vrf" not in ctx_keys[0] + ): + bgp_defult_inst = True + # Find bgp vrf inst + if ctx_keys[0].startswith("router bgp") and not line and "vrf" in ctx_keys[0]: + bgp_vrf_inst = True + + if bgp_defult_inst and bgp_vrf_inst: + for (ctx_keys, line) in lines_to_del: + # move bgp default inst to end + if ( + ctx_keys[0].startswith("router bgp") + and not line + and "vrf" not in ctx_keys[0] + ): + lines_to_del.remove((ctx_keys, line)) + lines_to_del.append((ctx_keys, line)) + + 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 @@ -948,6 +980,7 @@ def delete_move_lines(lines_to_add, lines_to_del): found_pg_del_cmd = True if found_pg_del_cmd == False: + bgp_delete_inst_move_line(lines_to_del) return (lines_to_add, lines_to_del) for (ctx_keys, line) in lines_to_del_to_app: @@ -1001,6 +1034,8 @@ def delete_move_lines(lines_to_add, lines_to_del): lines_to_del.remove((ctx_keys, line)) lines_to_del.append((ctx_keys, line)) + bgp_delete_inst_move_line(lines_to_del) + return (lines_to_add, lines_to_del) From 411d1a2950e9ed21a7d8fb65d8121a39bd01198e Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Fri, 8 Apr 2022 12:59:53 -0700 Subject: [PATCH 2/3] tools: frr-reload fix bgp nbr delete When a bgp neighbor removed from associated to peer-group, the neighbor is fully deleted, subsequent deletion of any configuration related to the neighbor leads to failure in frr-reload. Fix: In frr-reload lines to delete check if any neighbor with peer-group removal line is present, if so then remove any further config deletion associated the neighbor needs to removed from the lines to delete. Ticket:#3032234 Reviewed By: Testing Done: BEFORE FIX: ----------- 2022-04-08 20:03:32,734 INFO: Executed "router bgp 4200000005 no neighbor swp5 interface peer-group UNDERLAY" 2022-04-08 20:03:32,892 INFO: Failed to execute router bgp 4200000005 no neighbor swp5 password SSSS 2022-04-08 20:03:33,050 INFO: Failed to execute router bgp 4200000005 no neighbor swp5 password 2022-04-08 20:03:33,218 INFO: Failed to execute router bgp 4200000005 no neighbor swp5 2022-04-08 20:03:33,354 INFO: Failed to execute router bgp 4200000005 no neighbor 2022-04-08 20:03:33,520 INFO: Failed to execute router bgp 4200000005 no 2022-04-08 20:03:33,521 ERROR: "router bgp 4200000005 -- no" we failed to remove this command 2022-04-08 20:03:33,521 ERROR: % Specify remote-as or peer-group commands first 2022-04-08 20:03:33,691 INFO: Failed to execute router bgp 4200000005 no neighbor swp5 advertisement-interval 0 2022-04-08 20:03:33,853 INFO: Failed to execute router bgp 4200000005 no neighbor swp5 advertisement-interval 2022-04-08 20:03:34,015 INFO: Failed to execute router bgp 4200000005 no neighbor swp5 2022-04-08 20:03:34,145 INFO: Failed to execute router bgp 4200000005 no neighbor 2022-04-08 20:03:34,326 INFO: Failed to execute router bgp 4200000005 no 2022-04-08 20:03:34,327 ERROR: "router bgp 4200000005 -- no" we failed to remove this command 2022-04-08 20:03:34,327 ERROR: % Specify remote-as or peer-group commands first AFTER FIX: ---------- delete of numbered neighbor: 2022-04-08 19:52:17,204 INFO: Executed "router bgp 4200000005 no neighbor 1.2.3.4 peer-group UNDERLAY" 2022-04-08 19:52:17,205 INFO: /var/run/frr/reload-GRFX1M.txt content delete of unnumbered neighbor: 2022-04-08 20:00:02,952 INFO: Executed "router bgp 4200000005 no neighbor swp5 interface peer-group UNDERLAY" 2022-04-08 20:00:02,953 INFO: /var/run/frr/reload-722C3P.txt content Signed-off-by: Chirag Shah --- tools/frr-reload.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 8749215b1e..9b96243d98 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -873,6 +873,34 @@ def bgp_delete_nbr_remote_as_line(lines_to_add): lines_to_add.remove((ctx_keys, line)) +def bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict): + + # This method handles deletion of bgp neighbor configs, + # if there is neighbor to peer-group cmd is in delete list. + # As 'no neighbor .* peer-group' deletes the neighbor, + # subsequent neighbor speciic config line deletion results + # in error. + lines_to_del_to_del = [] + + for (ctx_keys, line) in lines_to_del: + if ( + ctx_keys[0].startswith("router bgp") + and line + and line.startswith("neighbor ") + ): + if ctx_keys[0] in del_nbr_dict: + for nbr in del_nbr_dict[ctx_keys[0]]: + re_nbr_pg = re.search('neighbor (\S+) .*peer-group (\S+)', line) + nb_exp = "neighbor %s .*" % nbr + if not re_nbr_pg: + re_nb = re.search(nb_exp, line) + if re_nb: + lines_to_del_to_del.append((ctx_keys, line)) + + for (ctx_keys, line) in lines_to_del_to_del: + lines_to_del.remove((ctx_keys, line)) + + """ This method handles deletion of bgp peer group config. The objective is to delete config lines related to peers @@ -886,6 +914,7 @@ def delete_move_lines(lines_to_add, lines_to_del): bgp_delete_nbr_remote_as_line(lines_to_add) del_dict = dict() + del_nbr_dict = dict() # Stores the lines to move to the end of the pending list. lines_to_del_to_del = [] # Stores the lines to move to end of the pending list. @@ -969,6 +998,16 @@ def delete_move_lines(lines_to_add, lines_to_del): if re_nb_remoteas: lines_to_del_to_app.append((ctx_keys, line)) + # 'no neighbor peer [interface] peer-group <>' is in lines_to_del + # copy the neighbor and look for all config removal lines associated + # to neighbor and delete them from the lines_to_del + re_nbr_pg = re.search('neighbor (\S+) .*peer-group (\S+)', line) + if re_nbr_pg: + if ctx_keys[0] not in del_nbr_dict: + del_nbr_dict[ctx_keys[0]] = list() + if re_nbr_pg.group(1) not in del_nbr_dict[ctx_keys[0]]: + del_nbr_dict[ctx_keys[0]].append(re_nbr_pg.group(1)) + # {'router bgp 65001': {'PG': [], 'PG1': []}, # 'router bgp 65001 vrf vrf1': {'PG': [], 'PG1': []}} if ctx_keys[0] not in del_dict: @@ -981,6 +1020,8 @@ def delete_move_lines(lines_to_add, lines_to_del): if found_pg_del_cmd == False: bgp_delete_inst_move_line(lines_to_del) + if del_nbr_dict: + bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict) return (lines_to_add, lines_to_del) for (ctx_keys, line) in lines_to_del_to_app: From 2a502f07a8e20ecc3deb409b053bc5e12ceb67f4 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Sun, 24 Apr 2022 11:48:08 -0700 Subject: [PATCH 3/3] tools: string literals -> comments Convert string literals to comment. Signed-off-by: Chirag Shah --- tools/frr-reload.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 9b96243d98..f47f9a7eb0 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -901,15 +901,11 @@ def bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict): lines_to_del.remove((ctx_keys, line)) -""" -This method handles deletion of bgp peer group config. -The objective is to delete config lines related to peers -associated with the peer-group and move the peer-group -config line to the end of the lines_to_del list. -""" - - def delete_move_lines(lines_to_add, lines_to_del): + # This method handles deletion of bgp peer group config. + # The objective is to delete config lines related to peers + # associated with the peer-group and move the peer-group + # config line to the end of the lines_to_del list. bgp_delete_nbr_remote_as_line(lines_to_add)