Skip to content

Commit 5e51c9b

Browse files
committed
fix errors of "show ip bgp summary" and "show ip bgp neigh" under alias
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.
1 parent 791373e commit 5e51c9b

9 files changed

+316
-15
lines changed

tests/bgp_commands_input/bgp_neighbor_test_vector.py

+10
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ def mock_show_bgp_neighbor_single_asic(request):
651651
'rc': 0,
652652
'rc_output': bgp_v4_neighbors_output
653653
},
654+
'bgp_v4_alias_neighbors': {
655+
'args': [],
656+
'rc': 0,
657+
'rc_output': bgp_v4_neighbors_output
658+
},
654659
'bgp_v4_neighbor_ip_address': {
655660
'args': ['10.0.0.57'],
656661
'rc': 0,
@@ -681,6 +686,11 @@ def mock_show_bgp_neighbor_single_asic(request):
681686
'rc': 0,
682687
'rc_output': bgp_v6_neighbors_output
683688
},
689+
'bgp_v6_alias_neighbors': {
690+
'args': [],
691+
'rc': 0,
692+
'rc_output': bgp_v6_neighbors_output
693+
},
684694
'bgp_v6_neighbor_ip_address': {
685695
'args': ['fc00::72'],
686696
'rc': 0,

tests/bgp_commands_test.py

+92
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@
5555
Total number of neighbors 24
5656
"""
5757

58+
59+
show_bgp_summary_alias_v4 = """\
60+
61+
IPv4 Unicast Summary:
62+
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
63+
BGP table version 12811
64+
RIB entries 12817, using 2358328 bytes of memory
65+
Peers 2, using 502080 KiB of memory
66+
Peer groups 1, using 256 bytes of memory
67+
68+
69+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
70+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
71+
etp1 4 65200 5919 2717 0 0 0 1d21h11m 6402 NotAvailable
72+
etp2 4 65200 5916 2714 0 0 0 1d21h10m 6402 NotAvailable
73+
74+
Total number of neighbors 2
75+
"""
76+
77+
show_bgp_summary_alias_v6 = """\
78+
79+
IPv6 Unicast Summary:
80+
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
81+
BGP table version 12811
82+
RIB entries 12817, using 2358328 bytes of memory
83+
Peers 2, using 502080 KiB of memory
84+
Peer groups 1, using 256 bytes of memory
85+
86+
87+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
88+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
89+
etp1 4 65200 5919 2717 0 0 0 1d21h11m 6402 NotAvailable
90+
etp2 4 65200 5916 2714 0 0 0 1d21h10m 6402 NotAvailable
91+
92+
Total number of neighbors 2
93+
"""
94+
95+
5896
show_bgp_summary_v6 = """\
5997
6098
IPv6 Unicast Summary:
@@ -362,6 +400,60 @@ def test_bgp_summary_v4(
362400
assert result.exit_code == 0
363401
assert result.output == show_bgp_summary_v4
364402

403+
@pytest.mark.parametrize('setup_single_bgp_instance',
404+
['alias_v4'], indirect=['setup_single_bgp_instance'])
405+
def test_bgp_summary_alias_v4(
406+
self,
407+
setup_bgp_commands,
408+
setup_single_bgp_instance):
409+
show = setup_bgp_commands
410+
runner = CliRunner()
411+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
412+
result = runner.invoke(
413+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
414+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
415+
print("{}".format(result.output))
416+
assert result.exit_code == 0
417+
assert result.output == show_bgp_summary_alias_v4
418+
419+
@pytest.mark.parametrize('setup_single_bgp_instance',
420+
['alias_v6'], indirect=['setup_single_bgp_instance'])
421+
def test_bgp_summary_alias_v6(
422+
self,
423+
setup_bgp_commands,
424+
setup_single_bgp_instance):
425+
show = setup_bgp_commands
426+
runner = CliRunner()
427+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
428+
result = runner.invoke(
429+
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
430+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
431+
print("{}".format(result.output))
432+
assert result.exit_code == 0
433+
assert result.output == show_bgp_summary_alias_v6
434+
435+
@pytest.mark.parametrize('setup_single_bgp_instance',
436+
['alias_empty'], indirect=['setup_single_bgp_instance'])
437+
def test_bgp_summary_alias_empty(
438+
self,
439+
setup_bgp_commands,
440+
setup_single_bgp_instance):
441+
show = setup_bgp_commands
442+
runner = CliRunner()
443+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
444+
result = runner.invoke(
445+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
446+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
447+
print("{}".format(result.output))
448+
assert result.exit_code == 2
449+
450+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
451+
result = runner.invoke(
452+
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
453+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
454+
print("{}".format(result.output))
455+
assert result.exit_code == 2
456+
365457
@pytest.mark.parametrize('setup_single_bgp_instance',
366458
['v6'], indirect=['setup_single_bgp_instance'])
367459
def test_bgp_summary_v6(

tests/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ def setup_single_bgp_instance(request):
167167
if request.param == 'v4':
168168
bgp_mocked_json = os.path.join(
169169
test_path, 'mock_tables', 'ipv4_bgp_summary.json')
170+
elif request.param == 'alias_v4':
171+
bgp_mocked_json = os.path.join(
172+
test_path, 'mock_tables', 'ipv4_bgp_summary_alias.json')
173+
elif request.param == 'alias_v6':
174+
bgp_mocked_json = os.path.join(
175+
test_path, 'mock_tables', 'ipv6_bgp_summary_alias.json')
176+
elif request.param == 'alias_empty':
177+
bgp_mocked_json = os.path.join(
178+
test_path, 'mock_tables', 'ip_bgp_summary_alias_empty.json')
170179
elif request.param == 'v6':
171180
bgp_mocked_json = os.path.join(
172181
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"ipv4Unicast":{
3+
"routerId":"10.1.0.32",
4+
"as":65100,
5+
"vrfId":0,
6+
"vrfName":"default",
7+
"tableVersion":12811,
8+
"ribCount":12817,
9+
"ribMemory":2358328,
10+
"peerCount":2,
11+
"peerMemory":502080,
12+
"peerGroupCount":1,
13+
"peerGroupMemory":256,
14+
"peers":{
15+
"Ethernet0":{
16+
"remoteAs":65200,
17+
"version":4,
18+
"msgRcvd":5919,
19+
"msgSent":2717,
20+
"tableVersion":0,
21+
"outq":0,
22+
"inq":0,
23+
"peerUptime":"1d21h11m",
24+
"peerUptimeMsec":162683000,
25+
"peerUptimeEstablishedEpoch":1597732920,
26+
"prefixReceivedCount":6402,
27+
"pfxRcd":6402,
28+
"pfxSnt":1,
29+
"state":"Established",
30+
"connectionsEstablished":1,
31+
"connectionsDropped":0,
32+
"idType":"interface"
33+
},
34+
"Ethernet4":{
35+
"remoteAs":65200,
36+
"version":4,
37+
"msgRcvd":5916,
38+
"msgSent":2714,
39+
"tableVersion":0,
40+
"outq":0,
41+
"inq":0,
42+
"peerUptime":"1d21h10m",
43+
"peerUptimeMsec":162638000,
44+
"peerUptimeEstablishedEpoch":1597732965,
45+
"prefixReceivedCount":6402,
46+
"pfxRcd":6402,
47+
"pfxSnt":1,
48+
"state":"Established",
49+
"connectionsEstablished":1,
50+
"connectionsDropped":0,
51+
"idType":"interface"
52+
}
53+
},
54+
"failedPeers":0,
55+
"totalPeers":2,
56+
"dynamicPeers":0,
57+
"bestPath":{
58+
"multiPathRelax":"true"
59+
}
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"ipv6Unicast":{
3+
"routerId":"10.1.0.32",
4+
"as":65100,
5+
"vrfId":0,
6+
"vrfName":"default",
7+
"tableVersion":12811,
8+
"ribCount":12817,
9+
"ribMemory":2358328,
10+
"peerCount":2,
11+
"peerMemory":502080,
12+
"peerGroupCount":1,
13+
"peerGroupMemory":256,
14+
"peers":{
15+
"Ethernet0":{
16+
"remoteAs":65200,
17+
"version":4,
18+
"msgRcvd":5919,
19+
"msgSent":2717,
20+
"tableVersion":0,
21+
"outq":0,
22+
"inq":0,
23+
"peerUptime":"1d21h11m",
24+
"peerUptimeMsec":162683000,
25+
"peerUptimeEstablishedEpoch":1597732920,
26+
"prefixReceivedCount":6402,
27+
"pfxRcd":6402,
28+
"pfxSnt":1,
29+
"state":"Established",
30+
"connectionsEstablished":1,
31+
"connectionsDropped":0,
32+
"idType":"interface"
33+
},
34+
"Ethernet4":{
35+
"remoteAs":65200,
36+
"version":4,
37+
"msgRcvd":5916,
38+
"msgSent":2714,
39+
"tableVersion":0,
40+
"outq":0,
41+
"inq":0,
42+
"peerUptime":"1d21h10m",
43+
"peerUptimeMsec":162638000,
44+
"peerUptimeEstablishedEpoch":1597732965,
45+
"prefixReceivedCount":6402,
46+
"pfxRcd":6402,
47+
"pfxSnt":1,
48+
"state":"Established",
49+
"connectionsEstablished":1,
50+
"connectionsDropped":0,
51+
"idType":"interface"
52+
}
53+
},
54+
"failedPeers":0,
55+
"totalPeers":2,
56+
"dynamicPeers":0,
57+
"bestPath":{
58+
"multiPathRelax":"true"
59+
}
60+
}
61+
}

tests/show_bgp_neighbor_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
def executor(test_vector, show):
1111
runner = CliRunner()
1212
input = testData[test_vector]
13+
14+
if "alias" in test_vector:
15+
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
16+
1317
if test_vector.startswith('bgp_v6'):
1418
exec_cmd = show.cli.commands["ipv6"].commands["bgp"].commands["neighbors"]
1519
else:
1620
exec_cmd = show.cli.commands["ip"].commands["bgp"].commands["neighbors"]
1721

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

24+
if "alias" in test_vector:
25+
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
26+
2027
print(result.exit_code)
2128
print(result.output)
2229

@@ -50,6 +57,7 @@ def setup_class(cls):
5057
@pytest.mark.parametrize('setup_single_bgp_instance, test_vector',
5158
[
5259
('bgp_v4_neighbors_output', 'bgp_v4_neighbors'),
60+
('bgp_v4_neighbors_output', 'bgp_v4_alias_neighbors'),
5361
('bgp_v4_neighbors_output',
5462
'bgp_v4_neighbor_ip_address'),
5563
('bgp_v4_neighbor_invalid_neigh',
@@ -61,6 +69,7 @@ def setup_class(cls):
6169
('bgp_v4_neighbor_output_recv_routes',
6270
'bgp_v4_neighbor_recv_routes'),
6371
('bgp_v6_neighbors_output', 'bgp_v6_neighbors'),
72+
('bgp_v6_neighbors_output', 'bgp_v6_alias_neighbors'),
6473
('bgp_v6_neighbors_output',
6574
'bgp_v6_neighbor_ip_address'),
6675
('bgp_v6_neighbor_invalid',

0 commit comments

Comments
 (0)