Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Added line permutation check for file loaded config #17693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tools/frr-reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,26 @@ def ignore_unconfigurable_lines(lines_to_add, lines_to_del):
return (lines_to_add, lines_to_del)


def is_line_permutated(test_line, conf):
"""
Verify if test_line permutations are present in conf
"""

for conf_line in conf:
# If length of both strings is not same,
# then they cannot be Permutation
# Look for the lines with the same length!
if (len(test_line) == len(conf_line)):
# Sort both lines
test_line_sorted = sorted(test_line) # This is not the fastest code, however, this is a rare action :)
conf_line_sorted = sorted(conf_line)
# Compare sorted lines
if (test_line_sorted == conf_line_sorted):
log.info("Skip line %s, because it is a permutation of configuration line %s.", line, conf_line)
return True

return False

def compare_context_objects(newconf, running):
"""
Create a context diff for the two specified contexts
Expand Down Expand Up @@ -1934,7 +1954,8 @@ def compare_context_objects(newconf, running):

for line in running_ctx.lines:
if line not in newconf_ctx.dlines:
lines_to_del.append((newconf_ctx_keys, line))
if (not is_line_permutated(line, newconf_ctx.dlines)):
lines_to_del.append((newconf_ctx_keys, line))

for newconf_ctx_keys, newconf_ctx in iteritems(newconf.contexts):
if newconf_ctx_keys not in running.contexts:
Expand Down
Loading