From 7591803d8827e3e96f2b9721cf341a53e092a587 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 29 Nov 2022 15:30:11 +0200 Subject: [PATCH] tests: Refactor bgp_maximum_prefix_invalid_update test case Just drop `while true` stuff. Signed-off-by: Donatas Abraitis --- .../r1/bgpd.conf | 17 +++++++--- .../r1/zebra.conf | 1 + .../r2/bgpd.conf | 13 +++++--- .../test_bgp_maximum_prefix_invalid_update.py | 33 ++++++++++++------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/r1/bgpd.conf b/tests/topotests/bgp_maximum_prefix_invalid_update/r1/bgpd.conf index 62110429cf..271a5bb1b1 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/r1/bgpd.conf +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/r1/bgpd.conf @@ -1,6 +1,13 @@ router bgp 65000 - no bgp ebgp-requires-policy - neighbor 192.168.255.2 remote-as 65001 - neighbor 192.168.255.2 timers 3 10 - address-family ipv4 unicast - redistribute connected + no bgp ebgp-requires-policy + neighbor 192.168.255.2 remote-as 65001 + neighbor 192.168.255.2 timers 3 10 + address-family ipv4 unicast + redistribute connected + neighbor 192.168.255.2 prefix-list r2 out + exit-address-family + ! +! +ip prefix-list r2 seq 5 permit 172.16.255.253/32 +ip prefix-list r2 seq 10 permit 172.16.255.254/32 +! diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/r1/zebra.conf b/tests/topotests/bgp_maximum_prefix_invalid_update/r1/zebra.conf index 0a283c06d5..68c5021636 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/r1/zebra.conf +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/r1/zebra.conf @@ -1,6 +1,7 @@ ! interface lo ip address 172.16.255.254/32 + ip address 172.16.255.253/32 ! interface r1-eth0 ip address 192.168.255.1/24 diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/r2/bgpd.conf b/tests/topotests/bgp_maximum_prefix_invalid_update/r2/bgpd.conf index 005425e850..cb30808f41 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/r2/bgpd.conf +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/r2/bgpd.conf @@ -1,6 +1,9 @@ router bgp 65001 - no bgp ebgp-requires-policy - neighbor 192.168.255.1 remote-as 65000 - neighbor 192.168.255.1 timers 3 10 - address-family ipv4 - neighbor 192.168.255.1 maximum-prefix 1 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65000 + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 + neighbor 192.168.255.1 maximum-prefix 1 + exit-address-family + ! +! diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py index 5c34ebf919..f402c41974 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py @@ -36,11 +36,13 @@ import os import sys import json import pytest +import functools CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 +from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen pytestmark = [pytest.mark.bgpd] @@ -83,29 +85,36 @@ def test_bgp_maximum_prefix_invalid(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - def _bgp_converge(router): - while True: - output = json.loads( - tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json") - ) - if output["192.168.255.1"]["connectionsEstablished"] > 0: - return True + r2 = tgen.gears["r2"] - def _bgp_parsing_nlri(router): + def _bgp_converge(): + output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = { + "192.168.255.1": { + "connectionsEstablished": 1, + "connectionsDropped": 1, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Can't converge initially" + + def _bgp_parsing_nlri(): cmd_max_exceeded = ( 'grep "%MAXPFXEXCEED: No. of IPv4 Unicast prefix received" bgpd.log' ) cmdt_error_parsing_nlri = 'grep "Error parsing NLRI" bgpd.log' - output_max_exceeded = tgen.gears[router].run(cmd_max_exceeded) - output_error_parsing_nlri = tgen.gears[router].run(cmdt_error_parsing_nlri) + output_max_exceeded = r2.run(cmd_max_exceeded) + output_error_parsing_nlri = r2.run(cmdt_error_parsing_nlri) if len(output_max_exceeded) > 0: if len(output_error_parsing_nlri) > 0: return False return True - if _bgp_converge("r2"): - assert _bgp_parsing_nlri("r2") == True + assert _bgp_parsing_nlri() == True if __name__ == "__main__":