Skip to content

Commit 4918050

Browse files
markx-aristamssonicbld
authored andcommitted
Fix test_bgp_bounce.py for v6 topos (sonic-net#21771)
Check IPv6 no-export community with IPv6 VM commands for v6 topos Add IPv6 route-map to bgp_no_export.j2 template Signed-off-by: markxiao <[email protected]> Signed-off-by: mssonicbld <[email protected]>
1 parent 29672ad commit 4918050

3 files changed

Lines changed: 42 additions & 13 deletions

File tree

tests/bgp/bgp_helpers.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,36 @@ def define_config(duthost, template_src_path, template_dst_path):
100100
duthost.copy(src=template_src_path, dest=template_dst_path)
101101

102102

103-
def get_no_export_output(vm_host):
103+
def get_no_export_output(vm_host, ipv6=False):
104104
"""
105105
Get no export routes on the VM
106106
107107
Args:
108108
vm_host: VM host object
109-
"""
110-
if isinstance(vm_host, EosHost):
111-
out = vm_host.eos_command(commands=['show ip bgp community no-export'])["stdout"]
112-
return re.findall(r'\d+\.\d+.\d+.\d+\/\d+\s+\d+\.\d+.\d+.\d+.*', out[0])
113-
elif isinstance(vm_host, SonicHost):
114-
out = vm_host.command("vtysh -c 'show ip bgp community no-export'")["stdout"]
115-
# For SonicHost, output is already a string, no need to index
116-
return re.findall(r'\d+\.\d+.\d+.\d+\/\d+\s+\d+\.\d+.\d+.\d+.*', out)
109+
ipv6: Boolean flag to check IPv6 routes
110+
"""
111+
if ipv6:
112+
ipv6_pattern = r'[0-9a-fA-F:]+\/\d+\s+[0-9a-fA-F:]+.*'
113+
if isinstance(vm_host, EosHost):
114+
out = vm_host.eos_command(commands=['show ipv6 bgp match community no-export'])["stdout"]
115+
return re.findall(ipv6_pattern, out[0])
116+
elif isinstance(vm_host, SonicHost):
117+
out = vm_host.command("vtysh -c 'show ipv6 bgp community no-export'")["stdout"]
118+
# For SonicHost, output is already a string, no need to index
119+
return re.findall(ipv6_pattern, out)
120+
else:
121+
raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.")
117122
else:
118-
raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.")
123+
ipv4_pattern = r'\d+\.\d+.\d+.\d+\/\d+\s+\d+\.\d+.\d+.\d+.*'
124+
if isinstance(vm_host, EosHost):
125+
out = vm_host.eos_command(commands=['show ip bgp community no-export'])["stdout"]
126+
return re.findall(ipv4_pattern, out[0])
127+
elif isinstance(vm_host, SonicHost):
128+
out = vm_host.command("vtysh -c 'show ip bgp community no-export'")["stdout"]
129+
# For SonicHost, output is already a string, no need to index
130+
return re.findall(ipv4_pattern, out)
131+
else:
132+
raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.")
119133

120134

121135
def apply_default_bgp_config(duthost, copy=False):

tests/bgp/templates/bgp_no_export.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ enable password zebra
2323
route-map TO_TIER0_V4 permit 50
2424
set community no-export additive
2525
!
26+
route-map TO_TIER0_V6 permit 50
27+
set community no-export additive
28+
!
2629
{% endif %}
2730
route-map FROM_BGP_SPEAKER_V4 permit 10
2831
!
@@ -92,6 +95,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
9295
address-family ipv6
9396
neighbor {{ neighbor_addr }} activate
9497
maximum-paths 64
98+
{% if 'LeafRouter' in DEVICE_METADATA['localhost']['type'] %}
99+
{%- if 'ToRRouter' in DEVICE_NEIGHBOR_METADATA[bgp_session['name']]['type'] %}
100+
neighbor {{ neighbor_addr }} route-map TO_TIER0_V6 out
101+
neighbor {{ neighbor_addr }} send-community
102+
neighbor {{ neighbor_addr }} allowas-in 1
103+
{% endif %}
104+
{% endif %}
95105
exit-address-family
96106
{% endif %}
97107
{% endif %}

tests/bgp/test_bgp_bounce.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88

99
from tests.common.helpers.assertions import pytest_assert
10+
from tests.common.utilities import is_ipv6_only_topology
1011
from bgp_helpers import apply_bgp_config
1112
from bgp_helpers import get_no_export_output
1213
from bgp_helpers import BGP_ANNOUNCE_TIME
@@ -16,7 +17,8 @@
1617
]
1718

1819

19-
def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export_bgp_config, backup_bgp_config):
20+
def test_bgp_bounce(duthost, nbrhosts, tbinfo, deploy_plain_bgp_config, deploy_no_export_bgp_config,
21+
backup_bgp_config):
2022
"""
2123
Verify bgp community no export functionality
2224
@@ -34,6 +36,9 @@ def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export
3436
bgp_plain_config = deploy_plain_bgp_config
3537
bgp_no_export_config = deploy_no_export_bgp_config
3638

39+
# Check if this is an IPv6-only topology
40+
is_v6_topo = is_ipv6_only_topology(tbinfo)
41+
3742
# Get random ToR VM
3843
vm_name = random.choice([vm_name for vm_name in list(nbrhosts.keys()) if vm_name.endswith('T0')])
3944
vm_host = nbrhosts[vm_name]['host']
@@ -48,7 +53,7 @@ def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export
4853
time.sleep(BGP_ANNOUNCE_TIME)
4954

5055
# Take action on one of the ToR VM
51-
no_export_route_num = get_no_export_output(vm_host)
56+
no_export_route_num = get_no_export_output(vm_host, ipv6=is_v6_topo)
5257
pytest_assert(not no_export_route_num, "Routes has no_export attribute")
5358

5459
# Apply bgp no export config
@@ -58,5 +63,5 @@ def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export
5863
time.sleep(BGP_ANNOUNCE_TIME)
5964

6065
# Take action on one of the ToR VM
61-
no_export_route_num = get_no_export_output(vm_host)
66+
no_export_route_num = get_no_export_output(vm_host, ipv6=is_v6_topo)
6267
pytest_assert(no_export_route_num, "Routes received on T1 are no-export")

0 commit comments

Comments
 (0)