From eb9113dfe3888556554eefa3bc3ef75cb4734d2b Mon Sep 17 00:00:00 2001 From: Don Slice Date: Tue, 14 Jul 2020 14:39:06 +0000 Subject: [PATCH] tools: fix more frr-reload vrf static errors Reported that in certain config changes, a static intended for the default table would be duplicated into a vrf context. Determined that we still weren't keeping or adding the exit-vrf command when necessary to keep the contexts straight. Added logic to look for the failing circumstances and add or remove the delete of the exit-vrf command as needed. Signed-off-by: Don Slice --- tools/frr-reload.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 9e86cf2156..4c637d84bc 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -729,6 +729,36 @@ def line_exist(lines, target_ctx_keys, target_line, exact_match=True): return True return False +def check_for_exit_vrf(lines_to_add, lines_to_del): + + # exit-vrf is a bit tricky. If the new config is missing it but we + # have configs under a vrf, we need to add it at the end to do the + # right context changes. If exit-vrf exists in both the running and + # new config, we cannot delete it or it will break context changes. + add_exit_vrf = False + index = 0 + + for (ctx_keys, line) in lines_to_add: + if add_exit_vrf == True: + if ctx_keys[0] != prior_ctx_key: + insert_key=(prior_ctx_key), + lines_to_add.insert(index, ((insert_key, "exit-vrf"))) + add_exit_vrf = False + + if ctx_keys[0].startswith('vrf') and line: + if line is not "exit-vrf": + add_exit_vrf = True + prior_ctx_key = (ctx_keys[0]) + else: + add_exit_vrf = False + index+=1 + + for (ctx_keys, line) in lines_to_del: + if line == "exit-vrf": + if (line_exist(lines_to_add, ctx_keys, line)): + lines_to_del.remove((ctx_keys, line)) + + return (lines_to_add, lines_to_del) def ignore_delete_re_add_lines(lines_to_add, lines_to_del): @@ -1156,6 +1186,7 @@ def compare_context_objects(newconf, running): for line in newconf_ctx.lines: lines_to_add.append((newconf_ctx_keys, line)) + (lines_to_add, lines_to_del) = check_for_exit_vrf(lines_to_add, lines_to_del) (lines_to_add, lines_to_del) = ignore_delete_re_add_lines(lines_to_add, lines_to_del) (lines_to_add, lines_to_del) = ignore_unconfigurable_lines(lines_to_add, lines_to_del) -- 2.39.5