Skip to content

Commit fdea806

Browse files
[route_check] fix IPv6 address handling (#2799)
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. Signed-off-by: Stepan Blyschak <[email protected]>
1 parent ea1d849 commit fdea806

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

scripts/route_check.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import signal
4747
import traceback
4848

49+
from ipaddress import ip_network
4950
from swsscommon import swsscommon
5051
from utilities_common import chassis
5152

@@ -141,7 +142,7 @@ def add_prefix(ip):
141142
ip = ip + PREFIX_SEPARATOR + "32"
142143
else:
143144
ip = ip + PREFIX_SEPARATOR + "128"
144-
return ip
145+
return str(ip_network(ip))
145146

146147

147148
def add_prefix_ifnot(ip):
@@ -150,7 +151,7 @@ def add_prefix_ifnot(ip):
150151
:param ip: IP to add prefix as string.
151152
:return ip with prefix
152153
"""
153-
return ip if ip.find(PREFIX_SEPARATOR) != -1 else add_prefix(ip)
154+
return str(ip_network(ip)) if ip.find(PREFIX_SEPARATOR) != -1 else add_prefix(ip)
154155

155156

156157
def is_local(ip):

tests/route_check_test_data.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,23 @@
332332
}
333333
}
334334
}
335-
}
335+
},
336+
"10": {
337+
DESCR: "basic good one with IPv6 address",
338+
ARGS: "route_check -m INFO -i 1000",
339+
PRE: {
340+
APPL_DB: {
341+
ROUTE_TABLE: {
342+
},
343+
INTF_TABLE: {
344+
"PortChannel1013:2000:31:0:0::1/64": {},
345+
}
346+
},
347+
ASIC_DB: {
348+
RT_ENTRY_TABLE: {
349+
RT_ENTRY_KEY_PREFIX + "2000:31::1/128" + RT_ENTRY_KEY_SUFFIX: {},
350+
}
351+
}
352+
}
353+
},
336354
}

0 commit comments

Comments
 (0)