Skip to content

Commit fd161e5

Browse files
thisptr-shBYGX-wcr
andauthored
Fix show ip route json and show ipv6 route json when there is no IPv4 or IPv6 route (#4177) (#4363)
* remove early return * add unit tests for IP4 only and IP6 only scenarios * fix incorrect UT data format * fix UT data * add early return for non-json case --------- Signed-off-by: BYGX-wcr <wcr@live.cn> Signed-off-by: Priyansh Tratiya <ptratiya@microsoft.com> Co-authored-by: Changrong Wu <wcr@live.cn>
1 parent 8936c06 commit fd161e5

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

show/bgp_common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ def show_routes(args, namespace, display, verbose, ipver):
415415
else:
416416
combined_route = route_info
417417

418-
if not combined_route:
419-
return
420-
421418
if not found_json:
419+
if len(combined_route) == 0:
420+
return
421+
422422
#print out the header if this is not a json request
423423
if not filter_by_ip:
424424
print_show_ip_route_hdr()

tests/route_check_test_data.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,4 +1704,63 @@
17041704
},
17051705
RET: -1,
17061706
},
1707+
"33": {
1708+
DESCR: "Good test case, only IPv4 routes",
1709+
MULTI_ASIC: False,
1710+
NAMESPACE: [''],
1711+
ARGS: "route_check -m INFO -i 1000",
1712+
PRE: {
1713+
DEFAULTNS: {
1714+
APPL_DB: {
1715+
ROUTE_TABLE: {
1716+
"0.0.0.0/0": {"ifname": "portchannel0"},
1717+
"10.10.196.12/31": {"ifname": "portchannel0"},
1718+
"10.10.196.20/31": {"ifname": "portchannel0"},
1719+
"10.10.196.30/31": {"ifname": "lo"}
1720+
},
1721+
INTF_TABLE: {
1722+
"PortChannel1013:10.10.196.24/31": {},
1723+
"PortChannel1024": {}
1724+
}
1725+
},
1726+
ASIC_DB: {
1727+
RT_ENTRY_TABLE: {
1728+
ASIC_RT_ENTRY_KEY_PREFIX + "10.10.196.12/31" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
1729+
ASIC_RT_ENTRY_KEY_PREFIX + "10.10.196.20/31" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
1730+
ASIC_RT_ENTRY_KEY_PREFIX + "10.10.196.24/32" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
1731+
ASIC_RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + ASIC_RT_ENTRY_KEY_SUFFIX: {}
1732+
}
1733+
}
1734+
}
1735+
}
1736+
},
1737+
"34": {
1738+
DESCR: "Good test case, only IPv6 routes",
1739+
MULTI_ASIC: False,
1740+
NAMESPACE: [''],
1741+
ARGS: "route_check -m INFO -i 1000",
1742+
PRE: {
1743+
DEFAULTNS: {
1744+
APPL_DB: {
1745+
ROUTE_TABLE: {
1746+
"::/0": {"ifname": "portchannel0"},
1747+
"2603:10b0:503:df4::6c/126": {"ifname": "portchannel0"},
1748+
"2603:10b0:503:df4::7c/126": {"ifname": "portchannel0"},
1749+
},
1750+
INTF_TABLE: {
1751+
"PortChannel1023:2603:10b0:503:df4::5d/126": {},
1752+
"PortChannel1024": {}
1753+
}
1754+
},
1755+
ASIC_DB: {
1756+
RT_ENTRY_TABLE: {
1757+
ASIC_RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::5d/128" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
1758+
ASIC_RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::6c/126" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
1759+
ASIC_RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::7c/126" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
1760+
ASIC_RT_ENTRY_KEY_PREFIX + "::/0" + ASIC_RT_ENTRY_KEY_SUFFIX: {}
1761+
}
1762+
}
1763+
}
1764+
}
1765+
},
17071766
}

0 commit comments

Comments
 (0)