From ac227a0a851e9e7716edcfbf01368cd17204a7c0 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Tue, 7 Mar 2023 12:39:29 +0200 Subject: [PATCH] [route_check] fix IPv6 address handling Signed-off-by: Stepan Blyschak --- scripts/route_check.py | 5 +++-- tests/route_check_test_data.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/route_check.py b/scripts/route_check.py index c6234bcc9d..705025bbd4 100755 --- a/scripts/route_check.py +++ b/scripts/route_check.py @@ -46,6 +46,7 @@ import signal import traceback +from ipaddress import ip_network from swsscommon import swsscommon from utilities_common import chassis @@ -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): @@ -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): diff --git a/tests/route_check_test_data.py b/tests/route_check_test_data.py index 9e4cd3a009..a0b7a97e30 100644 --- a/tests/route_check_test_data.py +++ b/tests/route_check_test_data.py @@ -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: {}, + } + } + } + }, }