Skip to content

Commit

Permalink
fix errors of "show ip bgp summary" and "show ip bgp neigh" under alias
Browse files Browse the repository at this point in the history
In alias mode, the output of "show ip/ipv6 bgp summary" and "show ip/ipv6
bgp neigh" return errors. This PR is used to fix these errors.
  • Loading branch information
JoshYangEC committed Sep 4, 2024
1 parent 791373e commit 5e51c9b
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 15 deletions.
10 changes: 10 additions & 0 deletions tests/bgp_commands_input/bgp_neighbor_test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ def mock_show_bgp_neighbor_single_asic(request):
'rc': 0,
'rc_output': bgp_v4_neighbors_output
},
'bgp_v4_alias_neighbors': {
'args': [],
'rc': 0,
'rc_output': bgp_v4_neighbors_output
},
'bgp_v4_neighbor_ip_address': {
'args': ['10.0.0.57'],
'rc': 0,
Expand Down Expand Up @@ -681,6 +686,11 @@ def mock_show_bgp_neighbor_single_asic(request):
'rc': 0,
'rc_output': bgp_v6_neighbors_output
},
'bgp_v6_alias_neighbors': {
'args': [],
'rc': 0,
'rc_output': bgp_v6_neighbors_output
},
'bgp_v6_neighbor_ip_address': {
'args': ['fc00::72'],
'rc': 0,
Expand Down
92 changes: 92 additions & 0 deletions tests/bgp_commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@
Total number of neighbors 24
"""


show_bgp_summary_alias_v4 = """\
IPv4 Unicast Summary:
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 12811
RIB entries 12817, using 2358328 bytes of memory
Peers 2, using 502080 KiB of memory
Peer groups 1, using 256 bytes of memory
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
etp1 4 65200 5919 2717 0 0 0 1d21h11m 6402 NotAvailable
etp2 4 65200 5916 2714 0 0 0 1d21h10m 6402 NotAvailable
Total number of neighbors 2
"""

show_bgp_summary_alias_v6 = """\
IPv6 Unicast Summary:
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 12811
RIB entries 12817, using 2358328 bytes of memory
Peers 2, using 502080 KiB of memory
Peer groups 1, using 256 bytes of memory
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
etp1 4 65200 5919 2717 0 0 0 1d21h11m 6402 NotAvailable
etp2 4 65200 5916 2714 0 0 0 1d21h10m 6402 NotAvailable
Total number of neighbors 2
"""


show_bgp_summary_v6 = """\
IPv6 Unicast Summary:
Expand Down Expand Up @@ -362,6 +400,60 @@ def test_bgp_summary_v4(
assert result.exit_code == 0
assert result.output == show_bgp_summary_v4

@pytest.mark.parametrize('setup_single_bgp_instance',
['alias_v4'], indirect=['setup_single_bgp_instance'])
def test_bgp_summary_alias_v4(
self,
setup_bgp_commands,
setup_single_bgp_instance):
show = setup_bgp_commands
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_bgp_summary_alias_v4

@pytest.mark.parametrize('setup_single_bgp_instance',
['alias_v6'], indirect=['setup_single_bgp_instance'])
def test_bgp_summary_alias_v6(
self,
setup_bgp_commands,
setup_single_bgp_instance):
show = setup_bgp_commands
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_bgp_summary_alias_v6

@pytest.mark.parametrize('setup_single_bgp_instance',
['alias_empty'], indirect=['setup_single_bgp_instance'])
def test_bgp_summary_alias_empty(
self,
setup_bgp_commands,
setup_single_bgp_instance):
show = setup_bgp_commands
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print("{}".format(result.output))
assert result.exit_code == 2

os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print("{}".format(result.output))
assert result.exit_code == 2

@pytest.mark.parametrize('setup_single_bgp_instance',
['v6'], indirect=['setup_single_bgp_instance'])
def test_bgp_summary_v6(
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def setup_single_bgp_instance(request):
if request.param == 'v4':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv4_bgp_summary.json')
elif request.param == 'alias_v4':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv4_bgp_summary_alias.json')
elif request.param == 'alias_v6':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv6_bgp_summary_alias.json')
elif request.param == 'alias_empty':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ip_bgp_summary_alias_empty.json')
elif request.param == 'v6':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
Expand Down
1 change: 1 addition & 0 deletions tests/mock_tables/ip_bgp_summary_alias_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
61 changes: 61 additions & 0 deletions tests/mock_tables/ipv4_bgp_summary_alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"ipv4Unicast":{
"routerId":"10.1.0.32",
"as":65100,
"vrfId":0,
"vrfName":"default",
"tableVersion":12811,
"ribCount":12817,
"ribMemory":2358328,
"peerCount":2,
"peerMemory":502080,
"peerGroupCount":1,
"peerGroupMemory":256,
"peers":{
"Ethernet0":{
"remoteAs":65200,
"version":4,
"msgRcvd":5919,
"msgSent":2717,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"1d21h11m",
"peerUptimeMsec":162683000,
"peerUptimeEstablishedEpoch":1597732920,
"prefixReceivedCount":6402,
"pfxRcd":6402,
"pfxSnt":1,
"state":"Established",
"connectionsEstablished":1,
"connectionsDropped":0,
"idType":"interface"
},
"Ethernet4":{
"remoteAs":65200,
"version":4,
"msgRcvd":5916,
"msgSent":2714,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"1d21h10m",
"peerUptimeMsec":162638000,
"peerUptimeEstablishedEpoch":1597732965,
"prefixReceivedCount":6402,
"pfxRcd":6402,
"pfxSnt":1,
"state":"Established",
"connectionsEstablished":1,
"connectionsDropped":0,
"idType":"interface"
}
},
"failedPeers":0,
"totalPeers":2,
"dynamicPeers":0,
"bestPath":{
"multiPathRelax":"true"
}
}
}
61 changes: 61 additions & 0 deletions tests/mock_tables/ipv6_bgp_summary_alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"ipv6Unicast":{
"routerId":"10.1.0.32",
"as":65100,
"vrfId":0,
"vrfName":"default",
"tableVersion":12811,
"ribCount":12817,
"ribMemory":2358328,
"peerCount":2,
"peerMemory":502080,
"peerGroupCount":1,
"peerGroupMemory":256,
"peers":{
"Ethernet0":{
"remoteAs":65200,
"version":4,
"msgRcvd":5919,
"msgSent":2717,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"1d21h11m",
"peerUptimeMsec":162683000,
"peerUptimeEstablishedEpoch":1597732920,
"prefixReceivedCount":6402,
"pfxRcd":6402,
"pfxSnt":1,
"state":"Established",
"connectionsEstablished":1,
"connectionsDropped":0,
"idType":"interface"
},
"Ethernet4":{
"remoteAs":65200,
"version":4,
"msgRcvd":5916,
"msgSent":2714,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"1d21h10m",
"peerUptimeMsec":162638000,
"peerUptimeEstablishedEpoch":1597732965,
"prefixReceivedCount":6402,
"pfxRcd":6402,
"pfxSnt":1,
"state":"Established",
"connectionsEstablished":1,
"connectionsDropped":0,
"idType":"interface"
}
},
"failedPeers":0,
"totalPeers":2,
"dynamicPeers":0,
"bestPath":{
"multiPathRelax":"true"
}
}
}
9 changes: 9 additions & 0 deletions tests/show_bgp_neighbor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
def executor(test_vector, show):
runner = CliRunner()
input = testData[test_vector]

if "alias" in test_vector:
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"

if test_vector.startswith('bgp_v6'):
exec_cmd = show.cli.commands["ipv6"].commands["bgp"].commands["neighbors"]
else:
exec_cmd = show.cli.commands["ip"].commands["bgp"].commands["neighbors"]

result = runner.invoke(exec_cmd, input['args'])

if "alias" in test_vector:
os.environ['SONIC_CLI_IFACE_MODE'] = "default"

print(result.exit_code)
print(result.output)

Expand Down Expand Up @@ -50,6 +57,7 @@ def setup_class(cls):
@pytest.mark.parametrize('setup_single_bgp_instance, test_vector',
[
('bgp_v4_neighbors_output', 'bgp_v4_neighbors'),
('bgp_v4_neighbors_output', 'bgp_v4_alias_neighbors'),
('bgp_v4_neighbors_output',
'bgp_v4_neighbor_ip_address'),
('bgp_v4_neighbor_invalid_neigh',
Expand All @@ -61,6 +69,7 @@ def setup_class(cls):
('bgp_v4_neighbor_output_recv_routes',
'bgp_v4_neighbor_recv_routes'),
('bgp_v6_neighbors_output', 'bgp_v6_neighbors'),
('bgp_v6_neighbors_output', 'bgp_v6_alias_neighbors'),
('bgp_v6_neighbors_output',
'bgp_v6_neighbor_ip_address'),
('bgp_v6_neighbor_invalid',
Expand Down
Loading

0 comments on commit 5e51c9b

Please sign in to comment.