Skip to content

Commit

Permalink
Merge pull request #15639 from chiragshah6/fdev2
Browse files Browse the repository at this point in the history
tests: add topotest for PG remote-as add del
  • Loading branch information
ton31337 authored Apr 1, 2024
2 parents 4dc4c2e + ede6e91 commit 6d237c2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/topotests/bgp_peer_group/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ router bgp 65001
neighbor PG timers 3 10
neighbor 192.168.255.3 peer-group PG
neighbor r1-eth0 interface peer-group PG
neighbor PG1 peer-group
neighbor PG1 remote-as external
neighbor PG1 timers 3 20
neighbor 192.168.251.2 peer-group PG1
!
3 changes: 3 additions & 0 deletions tests/topotests/bgp_peer_group/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
interface r1-eth0
ip address 192.168.255.1/24
!
interface r1-eth1
ip address 192.168.251.1/30
!
ip forwarding
!
4 changes: 4 additions & 0 deletions tests/topotests/bgp_peer_group/r2/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ router bgp 65002
neighbor PG remote-as external
neighbor PG timers 3 10
neighbor r2-eth0 interface peer-group PG
neighbor PG1 peer-group
neighbor PG1 remote-as external
neighbor PG1 timers 3 20
neighbor 192.168.251.1 peer-group PG1
!
3 changes: 3 additions & 0 deletions tests/topotests/bgp_peer_group/r2/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
interface r2-eth0
ip address 192.168.255.2/24
!
interface r2-eth1
ip address 192.168.251.2/30
!
ip forwarding
!
49 changes: 48 additions & 1 deletion tests/topotests/bgp_peer_group/test_bgp_peer-group.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# pylint: disable=C0413
from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen

from lib.topolog import logger

pytestmark = [pytest.mark.bgpd]

Expand All @@ -36,6 +36,10 @@ def build_topo(tgen):
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])

switch = tgen.add_switch("s2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])


def setup_module(mod):
tgen = Topogen(build_topo, mod.__name__)
Expand Down Expand Up @@ -70,6 +74,7 @@ def _bgp_peer_group_configured():
expected = {
"r1-eth0": {"peerGroup": "PG", "bgpState": "Established"},
"192.168.255.3": {"peerGroup": "PG", "bgpState": "Established"},
"192.168.251.2": {"peerGroup": "PG1", "bgpState": "Established"},
}
return topotest.json_cmp(output, expected)

Expand All @@ -96,6 +101,48 @@ def _bgp_peer_group_check_advertised_routes():
assert result is None, "Failed checking advertised routes from r3"


def test_bgp_peer_group_remote_as_del_readd():
tgen = get_topogen()

if tgen.routers_have_failure():
pytest.skip(tgen.errors)

r1 = tgen.gears["r1"]
logger.info("Remove bgp peer-group PG1 remote-as neighbor should be retained")
r1.cmd(
'vtysh -c "config t" -c "router bgp 65001" '
+ ' -c "no neighbor PG1 remote-as external" '
)

def _bgp_peer_group_remoteas_del():
output = json.loads(tgen.gears["r1"].vtysh_cmd("show bgp neighbor json"))
expected = {
"192.168.251.2": {"peerGroup": "PG1", "bgpState": "Active"},
}
return topotest.json_cmp(output, expected)

test_func = functools.partial(_bgp_peer_group_remoteas_del)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Failed bgp convergence in r1"

logger.info("Re-add bgp peer-group PG1 remote-as neighbor should be established")
r1.cmd(
'vtysh -c "config t" -c "router bgp 65001" '
+ ' -c "neighbor PG1 remote-as external" '
)

def _bgp_peer_group_remoteas_add():
output = json.loads(tgen.gears["r1"].vtysh_cmd("show bgp neighbor json"))
expected = {
"192.168.251.2": {"peerGroup": "PG1", "bgpState": "Established"},
}
return topotest.json_cmp(output, expected)

test_func = functools.partial(_bgp_peer_group_remoteas_add)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Failed bgp convergence in r1"


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

0 comments on commit 6d237c2

Please sign in to comment.