Skip to content

Commit

Permalink
Fixed SONIC_CLI_IFACE_MODE=alias show ip|ipv6 route output in default…
Browse files Browse the repository at this point in the history
… mode issue (sonic-net#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# sonic-net/sonic-buildimage#8498
  • Loading branch information
mlok-nokia authored and preetham-singh committed Nov 18, 2022
1 parent 6a4b494 commit 1a8b1d6
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 28 deletions.
14 changes: 4 additions & 10 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,15 @@ def show_routes(args, namespace, display, verbose, ipver):
# Not ip address just ignore it
found_other_parms = 1

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

combined_route = {}
for ns in ns_l:
# Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request
# If not MultiASIC, skip namespace argument
cmd = "show {} route {}".format(ipver, arg_strg)
if multi_asic.is_multi_asic():
output = bgp_util.run_bgp_show_command(cmd, ns)
else:
output = bgp_util.run_bgp_show_command(cmd)
print("{}".format(output))
return
output = bgp_util.run_bgp_show_command(cmd, ns)

# in case no output or something went wrong with user specified cmd argument(s) error it out
# error from FRR always start with character "%"
Expand Down
34 changes: 23 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ def setup_single_bgp_instance(request):
elif request.param == 'v6':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
elif request.param == 'ip_route':
bgp_mocked_json = 'ip_route.json'
elif request.param == 'ip_specific_route':
bgp_mocked_json = 'ip_specific_route.json'
elif request.param == 'ipv6_specific_route':
bgp_mocked_json = 'ipv6_specific_route.json'
elif request.param == 'ipv6_route':
bgp_mocked_json = 'ipv6_route.json'
elif request.param == 'ip_special_route':
bgp_mocked_json = 'ip_special_route.json'
else:
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'dummy.json')
Expand All @@ -190,23 +200,25 @@ def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd
def mock_run_show_ip_route_commands(request):
if request.param == 'ipv6_route_err':
return show_ip_route_common.show_ipv6_route_err_expected_output
elif request.param == 'ip_route':
return show_ip_route_common.show_ip_route_expected_output
elif request.param == 'ip_specific_route':
return show_ip_route_common.show_specific_ip_route_expected_output
elif request.param == 'ip_special_route':
return show_ip_route_common.show_special_ip_route_expected_output
elif request.param == 'ipv6_route':
return show_ip_route_common.show_ipv6_route_expected_output
elif request.param == 'ipv6_specific_route':
return show_ip_route_common.show_ipv6_route_single_json_expected_output
else:
return ""

def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
bgp_mocked_json_file = os.path.join(
test_path, 'mock_tables', bgp_mocked_json)
if os.path.isfile(bgp_mocked_json_file):
with open(bgp_mocked_json_file) as json_data:
mock_frr_data = json_data.read()
return mock_frr_data
else:
return ""

if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\
if any ([request.param == 'ip_route',\
request.param == 'ip_specific_route', request.param == 'ip_special_route',\
request.param == 'ipv6_route', request.param == 'ipv6_specific_route']):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_bgp_command("",""))
elif request.param.startswith('ipv6_route_err'):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_show_ip_route_commands(request))
elif request.param.startswith('bgp_v4_neighbor') or \
Expand Down
16 changes: 16 additions & 0 deletions tests/ip_show_routes_multi_asic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ def test_show_multi_asic_ipv6_route_all_namespace(
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_all_namesapce_output

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ipv6_route'], indirect=['setup_multi_asic_bgp_instance'])
def test_show_multi_asic_ipv6_route_all_namespace_alias(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(
show.cli.commands["ipv6"].commands["route"], ["-dfrontend"])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_all_namesapce_alias_output

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ipv6_route'], indirect=['setup_multi_asic_bgp_instance'])
def test_show_multi_asic_ipv6_route_single_namespace(
Expand Down
26 changes: 21 additions & 5 deletions tests/ip_show_routes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_show_ip_route(
show.cli.commands["ip"].commands["route"], [])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ip_route_expected_output + "\n"
assert result.output == show_ip_route_common.show_ip_route_expected_output

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

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

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

@pytest.mark.parametrize('setup_single_bgp_instance',
['ipv6_route'], indirect=['setup_single_bgp_instance'])
Expand All @@ -86,7 +86,23 @@ def test_show_ipv6_route(
show.cli.commands["ipv6"].commands["route"], [])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ipv6_route_expected_output + "\n"
assert result.output == show_ip_route_common.show_ipv6_route_expected_output

@pytest.mark.parametrize('setup_single_bgp_instance',
['ipv6_route'], indirect=['setup_single_bgp_instance'])
def test_show_ipv6_route_alias(
self,
setup_ip_route_commands,
setup_single_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(
show.cli.commands["ipv6"].commands["route"], [])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ipv6_route_alias_expected_output

@pytest.mark.parametrize('setup_single_bgp_instance',
['ipv6_route_err'], indirect=['setup_single_bgp_instance'])
Expand Down
11 changes: 11 additions & 0 deletions tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
"speed": "40000",
"asic_port_name": "Eth1-ASIC0"
},
"PORT|Ethernet16": {
"lanes": "17,18,19,20",
"description": "ARISTA01T2:Ethernet3/3/1",
"pfc_asym": "off",
"mtu": "9100",
"alias": "Ethernet1/5",
"admin_status": "up",
"role": "Ext",
"speed": "40000",
"asic_port_name": "Eth1-ASIC0"
},
"PORT|Ethernet-BP0" : {
"lanes": "93,94,95,96",
"description": "ASIC1:Eth0-ASIC1",
Expand Down
Loading

0 comments on commit 1a8b1d6

Please sign in to comment.