Skip to content

Commit

Permalink
add more UT
Browse files Browse the repository at this point in the history
  • Loading branch information
arlakshm committed Sep 8, 2024
1 parent 80b2eda commit c9e1a06
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def setup_multi_asic_bgp_instance(request):
m_asic_json_file = 'ip_route_lc.json'
elif request.param == 'ip_route_remote_lc':
m_asic_json_file = 'ip_route_remote_lc.json'
elif request.param == 'ip_route_lc_2':
m_asic_json_file = 'ip_route_lc_2.json'
else:
m_asic_json_file = os.path.join(
test_path, 'mock_tables', 'dummy.json')
Expand Down
20 changes: 18 additions & 2 deletions tests/ip_show_routes_multi_asic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from unittest import mock

import show.main as show

from . import show_ip_route_common
from click.testing import CliRunner
Expand Down Expand Up @@ -280,7 +279,9 @@ def setup_class(cls):
@mock.patch("sonic_py_common.device_info.is_voq_chassis", mock.MagicMock(return_value=True))
def test_voq_chassis_lc(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["-dfrontend"])
Expand Down Expand Up @@ -308,8 +309,9 @@ def test_voq_chassis_remote_lc(
@mock.patch("sonic_py_common.device_info.is_voq_chassis", mock.MagicMock(return_value=True))
def test_voq_chassis_lc_def_route(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
runner = CliRunner()
show = setup_ip_route_commands
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["0.0.0.0/0"])
print("{}".format(result.output))
Expand All @@ -331,6 +333,20 @@ def test_voq_chassis_remote_lc_default_route(
assert result.exit_code == 0
assert result.output == show_ip_route_common.SHOW_IP_ROUTE_REMOTE_LC_DEFAULT_ROUTE

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ip_route_lc_2'], indirect=['setup_multi_asic_bgp_instance'])
@mock.patch("sonic_py_common.device_info.is_voq_chassis", mock.MagicMock(return_value=True))
def test_voq_chassis_lc_def_route_2(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
show = setup_ip_route_commands
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["0.0.0.0/0"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.SHOW_IP_ROUTE_LC_DEFAULT_ROUTE_2

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
56 changes: 56 additions & 0 deletions tests/mock_tables/asic0/ip_route_lc_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"0.0.0.0/0": [
{
"prefix": "0.0.0.0/0",
"prefixLen": 0,
"protocol": "bgp",
"vrfId": 0,
"vrfName": "default",
"selected": true,
"destSelected": true,
"distance": 20,
"metric": 0,
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalNextHopNum": 3,
"internalNextHopActiveNum": 3,
"nexthopGroupId": 2122,
"installedNexthopGroupId": 2122,
"uptime": "01:01:51",
"nexthops": [
{
"flags": 3,
"fib": true,
"ip": "10.0.0.1",
"afi": "ipv4",
"interfaceIndex": 29,
"interfaceName": "PortChannel102",
"active": true,
"weight": 1
},
{
"flags": 5,
"ip": "10.0.0.7",
"afi": "ipv4",
"active": true,
"recursive": true,
"weight": 1
},
{
"flags": 11,
"fib": true,
"ip": "10.0.0.7",
"afi": "ipv4",
"interfaceIndex": 52,
"interfaceName": "Ethernet-IB0",
"resolver": true,
"active": true,
"onLink": true,
"weight": 1
}
]
}
]
}
56 changes: 56 additions & 0 deletions tests/mock_tables/asic1/ip_route_lc_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"0.0.0.0/0": [
{
"prefix": "0.0.0.0/0",
"prefixLen": 0,
"protocol": "bgp",
"vrfId": 0,
"vrfName": "default",
"selected": true,
"destSelected": true,
"distance": 20,
"metric": 0,
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalNextHopNum": 3,
"internalNextHopActiveNum": 3,
"nexthopGroupId": 2173,
"installedNexthopGroupId": 2173,
"uptime": "01:01:57",
"nexthops": [
{
"flags": 5,
"ip": "10.0.0.1",
"afi": "ipv4",
"active": true,
"recursive": true,
"weight": 1
},
{
"flags": 11,
"fib": true,
"ip": "10.0.0.1",
"afi": "ipv4",
"interfaceIndex": 52,
"interfaceName": "Ethernet-IB1",
"resolver": true,
"active": true,
"onLink": true,
"weight": 1
},
{
"flags": 3,
"fib": true,
"ip": "10.0.0.7",
"afi": "ipv4",
"interfaceIndex": 29,
"interfaceName": "PortChannel106",
"active": true,
"weight": 1
}
]
}
]
}
9 changes: 9 additions & 0 deletions tests/show_ip_route_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,3 +923,12 @@
* 20.1.0.128, via PortChannel1
"""


SHOW_IP_ROUTE_LC_DEFAULT_ROUTE_2 = """\
Routing entry for 0.0.0.0/0
Known via "bgp", distance 20, metric 0, best
Last update 01:01:51 ago
* 10.0.0.7, via PortChannel106
* 10.0.0.1, via PortChannel102
"""

0 comments on commit c9e1a06

Please sign in to comment.