Skip to content

Commit 25acda3

Browse files
authored
Fixed SONIC_CLI_IFACE_MODE=alias show ip|ipv6 route output in default mode issue (#2422)
There are many issues with the "SONIC_CLI_IFACE_MODE=aliasshow ip/ipv6 route [json]" commands on both single asic platform and multiasic platform Doesn't show the interface alias on single asic platform Display the route info twice either in Json format or default format on the single asic platform Doesn't show the interface alias on multiasic platform Display the route info in the Json format even if Json is not specified in the CLI command Resolves# #8498
1 parent 2331e38 commit 25acda3

File tree

8 files changed

+298
-28
lines changed

8 files changed

+298
-28
lines changed

show/bgp_common.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,15 @@ def show_routes(args, namespace, display, verbose, ipver):
367367
# Not ip address just ignore it
368368
found_other_parms = 1
369369

370-
if multi_asic.is_multi_asic():
371-
if not found_json and not found_other_parms:
372-
arg_strg += "json"
370+
# using the same format for both multiasic or non-multiasic
371+
if not found_json and not found_other_parms:
372+
arg_strg += "json"
373373

374374
combined_route = {}
375375
for ns in ns_l:
376376
# Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request
377-
# If not MultiASIC, skip namespace argument
378377
cmd = "show {} route {}".format(ipver, arg_strg)
379-
if multi_asic.is_multi_asic():
380-
output = bgp_util.run_bgp_show_command(cmd, ns)
381-
else:
382-
output = bgp_util.run_bgp_show_command(cmd)
383-
print("{}".format(output))
384-
return
378+
output = bgp_util.run_bgp_show_command(cmd, ns)
385379

386380
# in case no output or something went wrong with user specified cmd argument(s) error it out
387381
# error from FRR always start with character "%"

tests/conftest.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ def setup_single_bgp_instance(request):
165165
elif request.param == 'v6':
166166
bgp_mocked_json = os.path.join(
167167
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
168+
elif request.param == 'ip_route':
169+
bgp_mocked_json = 'ip_route.json'
170+
elif request.param == 'ip_specific_route':
171+
bgp_mocked_json = 'ip_specific_route.json'
172+
elif request.param == 'ipv6_specific_route':
173+
bgp_mocked_json = 'ipv6_specific_route.json'
174+
elif request.param == 'ipv6_route':
175+
bgp_mocked_json = 'ipv6_route.json'
176+
elif request.param == 'ip_special_route':
177+
bgp_mocked_json = 'ip_special_route.json'
168178
else:
169179
bgp_mocked_json = os.path.join(
170180
test_path, 'mock_tables', 'dummy.json')
@@ -190,23 +200,25 @@ def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd
190200
def mock_run_show_ip_route_commands(request):
191201
if request.param == 'ipv6_route_err':
192202
return show_ip_route_common.show_ipv6_route_err_expected_output
193-
elif request.param == 'ip_route':
194-
return show_ip_route_common.show_ip_route_expected_output
195-
elif request.param == 'ip_specific_route':
196-
return show_ip_route_common.show_specific_ip_route_expected_output
197-
elif request.param == 'ip_special_route':
198-
return show_ip_route_common.show_special_ip_route_expected_output
199-
elif request.param == 'ipv6_route':
200-
return show_ip_route_common.show_ipv6_route_expected_output
201-
elif request.param == 'ipv6_specific_route':
202-
return show_ip_route_common.show_ipv6_route_single_json_expected_output
203203
else:
204204
return ""
205205

206+
def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
207+
bgp_mocked_json_file = os.path.join(
208+
test_path, 'mock_tables', bgp_mocked_json)
209+
if os.path.isfile(bgp_mocked_json_file):
210+
with open(bgp_mocked_json_file) as json_data:
211+
mock_frr_data = json_data.read()
212+
return mock_frr_data
213+
else:
214+
return ""
206215

207-
if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\
216+
if any ([request.param == 'ip_route',\
208217
request.param == 'ip_specific_route', request.param == 'ip_special_route',\
209218
request.param == 'ipv6_route', request.param == 'ipv6_specific_route']):
219+
bgp_util.run_bgp_command = mock.MagicMock(
220+
return_value=mock_run_bgp_command("",""))
221+
elif request.param.startswith('ipv6_route_err'):
210222
bgp_util.run_bgp_command = mock.MagicMock(
211223
return_value=mock_run_show_ip_route_commands(request))
212224
elif request.param.startswith('bgp_v4_neighbor') or \

tests/ip_show_routes_multi_asic_test.py

+16
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ def test_show_multi_asic_ipv6_route_all_namespace(
164164
assert result.exit_code == 0
165165
assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_all_namesapce_output
166166

167+
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
168+
['ipv6_route'], indirect=['setup_multi_asic_bgp_instance'])
169+
def test_show_multi_asic_ipv6_route_all_namespace_alias(
170+
self,
171+
setup_ip_route_commands,
172+
setup_multi_asic_bgp_instance):
173+
show = setup_ip_route_commands
174+
runner = CliRunner()
175+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
176+
result = runner.invoke(
177+
show.cli.commands["ipv6"].commands["route"], ["-dfrontend"])
178+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
179+
print("{}".format(result.output))
180+
assert result.exit_code == 0
181+
assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_all_namesapce_alias_output
182+
167183
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
168184
['ipv6_route'], indirect=['setup_multi_asic_bgp_instance'])
169185
def test_show_multi_asic_ipv6_route_single_namespace(

tests/ip_show_routes_test.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_show_ip_route(
3030
show.cli.commands["ip"].commands["route"], [])
3131
print("{}".format(result.output))
3232
assert result.exit_code == 0
33-
assert result.output == show_ip_route_common.show_ip_route_expected_output + "\n"
33+
assert result.output == show_ip_route_common.show_ip_route_expected_output
3434

3535
@pytest.mark.parametrize('setup_single_bgp_instance',
3636
['ip_specific_route'], indirect=['setup_single_bgp_instance'])
@@ -44,7 +44,7 @@ def test_show_specific_ip_route(
4444
show.cli.commands["ip"].commands["route"], ["192.168.0.1"])
4545
print("{}".format(result.output))
4646
assert result.exit_code == 0
47-
assert result.output == show_ip_route_common.show_specific_ip_route_expected_output + "\n"
47+
assert result.output == show_ip_route_common.show_specific_ip_route_expected_output
4848

4949
@pytest.mark.parametrize('setup_single_bgp_instance',
5050
['ip_special_route'], indirect=['setup_single_bgp_instance'])
@@ -58,7 +58,7 @@ def test_show_special_ip_route(
5858
show.cli.commands["ip"].commands["route"], [])
5959
print("{}".format(result.output))
6060
assert result.exit_code == 0
61-
assert result.output == show_ip_route_common.show_special_ip_route_expected_output + "\n"
61+
assert result.output == show_ip_route_common.show_special_ip_route_expected_output
6262

6363
@pytest.mark.parametrize('setup_single_bgp_instance',
6464
['ipv6_specific_route'], indirect=['setup_single_bgp_instance'])
@@ -72,7 +72,7 @@ def test_show_specific_ipv6_route_json(
7272
show.cli.commands["ip"].commands["route"], ["20c0:a8c7:0:81::", "json"])
7373
print("{}".format(result.output))
7474
assert result.exit_code == 0
75-
assert result.output == show_ip_route_common.show_ipv6_route_single_json_expected_output + "\n"
75+
assert result.output == show_ip_route_common.show_ipv6_route_single_json_expected_output
7676

7777
@pytest.mark.parametrize('setup_single_bgp_instance',
7878
['ipv6_route'], indirect=['setup_single_bgp_instance'])
@@ -86,7 +86,23 @@ def test_show_ipv6_route(
8686
show.cli.commands["ipv6"].commands["route"], [])
8787
print("{}".format(result.output))
8888
assert result.exit_code == 0
89-
assert result.output == show_ip_route_common.show_ipv6_route_expected_output + "\n"
89+
assert result.output == show_ip_route_common.show_ipv6_route_expected_output
90+
91+
@pytest.mark.parametrize('setup_single_bgp_instance',
92+
['ipv6_route'], indirect=['setup_single_bgp_instance'])
93+
def test_show_ipv6_route_alias(
94+
self,
95+
setup_ip_route_commands,
96+
setup_single_bgp_instance):
97+
show = setup_ip_route_commands
98+
runner = CliRunner()
99+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
100+
result = runner.invoke(
101+
show.cli.commands["ipv6"].commands["route"], [])
102+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
103+
print("{}".format(result.output))
104+
assert result.exit_code == 0
105+
assert result.output == show_ip_route_common.show_ipv6_route_alias_expected_output
90106

91107
@pytest.mark.parametrize('setup_single_bgp_instance',
92108
['ipv6_route_err'], indirect=['setup_single_bgp_instance'])

tests/mock_tables/asic0/config_db.json

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
"speed": "40000",
3939
"asic_port_name": "Eth1-ASIC0"
4040
},
41+
"PORT|Ethernet16": {
42+
"lanes": "17,18,19,20",
43+
"description": "ARISTA01T2:Ethernet3/3/1",
44+
"pfc_asym": "off",
45+
"mtu": "9100",
46+
"alias": "Ethernet1/5",
47+
"admin_status": "up",
48+
"role": "Ext",
49+
"speed": "40000",
50+
"asic_port_name": "Eth1-ASIC0"
51+
},
4152
"PORT|Ethernet-BP0" : {
4253
"lanes": "93,94,95,96",
4354
"description": "ASIC1:Eth0-ASIC1",

0 commit comments

Comments
 (0)