Merge pull request #9049 from LabNConsulting/chopps/improve-frr-reload-delta

tools: improve frr-reload.py delta file creation
This commit is contained in:
Mark Stapp 2021-07-16 08:21:57 -04:00 committed by GitHub
commit 65574cda3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 41 deletions

View File

@ -497,7 +497,7 @@ def reset_config_on_routers(tgen, routerName=None):
f.close() f.close()
run_cfg_file = "{}/{}/frr.sav".format(TMPDIR, rname) run_cfg_file = "{}/{}/frr.sav".format(TMPDIR, rname)
init_cfg_file = "{}/{}/frr_json_initial.conf".format(TMPDIR, rname) init_cfg_file = "{}/{}/frr_json_initial.conf".format(TMPDIR, rname)
command = "/usr/lib/frr/frr-reload.py --input {} --test {} > {}".format( command = "/usr/lib/frr/frr-reload.py --test --test-reset --input {} {} > {}".format(
run_cfg_file, init_cfg_file, dname run_cfg_file, init_cfg_file, dname
) )
result = call(command, shell=True, stderr=SUB_STDOUT, stdout=SUB_PIPE) result = call(command, shell=True, stderr=SUB_STDOUT, stdout=SUB_PIPE)
@ -527,37 +527,9 @@ def reset_config_on_routers(tgen, routerName=None):
raise InvalidCLIError(out_data) raise InvalidCLIError(out_data)
raise InvalidCLIError("Unknown error in %s", output) raise InvalidCLIError("Unknown error in %s", output)
f = open(dname, "r")
delta = StringIO() delta = StringIO()
delta.write("configure terminal\n") with open(dname, "r") as f:
t_delta = f.read() delta.write(f.read())
# Don't disable debugs
check_debug = True
for line in t_delta.split("\n"):
line = line.strip()
if line == "Lines To Delete" or line == "===============" or not line:
continue
if line == "Lines To Add":
check_debug = False
continue
if line == "============" or not line:
continue
# Leave debugs and log output alone
if check_debug:
if "debug" in line or "log file" in line:
continue
delta.write(line)
delta.write("\n")
f.close()
delta.write("end\n")
output = router.vtysh_multicmd(delta.getvalue(), pretty_output=False) output = router.vtysh_multicmd(delta.getvalue(), pretty_output=False)

View File

@ -2012,6 +2012,11 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"--daemon", help="daemon for which want to replace the config", default="" "--daemon", help="daemon for which want to replace the config", default=""
) )
parser.add_argument(
"--test-reset",
action="store_true",
help="Used by topotest to not delete debug or log file commands",
)
args = parser.parse_args() args = parser.parse_args()
@ -2125,7 +2130,7 @@ if __name__ == "__main__":
service_integrated_vtysh_config = False service_integrated_vtysh_config = False
break break
if not service_integrated_vtysh_config and not args.daemon: if not args.test and not service_integrated_vtysh_config and not args.daemon:
log.error( log.error(
"'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'" "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'"
) )
@ -2153,9 +2158,9 @@ if __name__ == "__main__":
running.load_from_show_running(args.daemon) running.load_from_show_running(args.daemon)
(lines_to_add, lines_to_del) = compare_context_objects(newconf, running) (lines_to_add, lines_to_del) = compare_context_objects(newconf, running)
lines_to_configure = []
if lines_to_del: if lines_to_del:
if not args.test_reset:
print("\nLines To Delete") print("\nLines To Delete")
print("===============") print("===============")
@ -2164,11 +2169,23 @@ if __name__ == "__main__":
if line == "!": if line == "!":
continue continue
cmd = "\n".join(lines_to_config(ctx_keys, line, True)) nolines = lines_to_config(ctx_keys, line, True)
lines_to_configure.append(cmd)
if args.test_reset:
# For topotests the original code stripped the lines, and ommitted blank lines
# after, do that here
nolines = [x.strip() for x in nolines]
# For topotests leave these lines in (don't delete them)
# [chopps: why is "log file" more special than other "log" commands?]
nolines = [x for x in nolines if "debug" not in x and "log file" not in x]
if not nolines:
continue
cmd = "\n".join(nolines)
print(cmd) print(cmd)
if lines_to_add: if lines_to_add:
if not args.test_reset:
print("\nLines To Add") print("\nLines To Add")
print("============") print("============")
@ -2177,11 +2194,20 @@ if __name__ == "__main__":
if line == "!": if line == "!":
continue continue
cmd = "\n".join(lines_to_config(ctx_keys, line, False)) lines = lines_to_config(ctx_keys, line, False)
lines_to_configure.append(cmd)
if args.test_reset:
# For topotests the original code stripped the lines, and ommitted blank lines
# after, do that here
lines = [x.strip() for x in lines if x.strip()]
if not lines:
continue
cmd = "\n".join(lines)
print(cmd) print(cmd)
elif args.reload: elif args.reload:
lines_to_configure = []
# We will not be able to do anything, go ahead and exit(1) # We will not be able to do anything, go ahead and exit(1)
if not vtysh.is_config_available(): if not vtysh.is_config_available():