Skip to content

Commit

Permalink
[route_check] fix IPv6 address handling (#2798)
Browse files Browse the repository at this point in the history
BACKPORT of #2722

What I did
In case user has configured an IPv6 address on an interface in CONFIG DB in non simplified form like 2000:31:0:0::1/64 it is present in a simplified form in ASIC_DB. This leads to route_check failure since it just compares strings.

How I did it
Convert prefix string using ip_network().

How to verify it
UT replicates the issue.
  • Loading branch information
stepanblyschak authored Apr 20, 2023
1 parent e0bafc2 commit 86e3e00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import signal
import traceback

from ipaddress import ip_network
from swsscommon import swsscommon
from utilities_common import chassis

Expand Down Expand Up @@ -141,7 +142,7 @@ def add_prefix(ip):
ip = ip + PREFIX_SEPARATOR + "32"
else:
ip = ip + PREFIX_SEPARATOR + "128"
return ip
return str(ip_network(ip))


def add_prefix_ifnot(ip):
Expand All @@ -150,7 +151,7 @@ def add_prefix_ifnot(ip):
:param ip: IP to add prefix as string.
:return ip with prefix
"""
return ip if ip.find(PREFIX_SEPARATOR) != -1 else add_prefix(ip)
return str(ip_network(ip)) if ip.find(PREFIX_SEPARATOR) != -1 else add_prefix(ip)


def is_local(ip):
Expand Down
20 changes: 19 additions & 1 deletion tests/route_check_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,5 +359,23 @@
}
}
}
}
},
"10": {
DESCR: "basic good one with IPv6 address",
ARGS: "route_check -m INFO -i 1000",
PRE: {
APPL_DB: {
ROUTE_TABLE: {
},
INTF_TABLE: {
"PortChannel1013:2000:31:0:0::1/64": {},
}
},
ASIC_DB: {
RT_ENTRY_TABLE: {
RT_ENTRY_KEY_PREFIX + "2000:31::1/128" + RT_ENTRY_KEY_SUFFIX: {},
}
}
}
},
}

0 comments on commit 86e3e00

Please sign in to comment.