]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: improve bgp test determinism 13522/head
authorChristian Hopps <chopps@labn.net>
Sat, 13 May 2023 00:32:54 +0000 (20:32 -0400)
committerChristian Hopps <chopps@labn.net>
Sat, 13 May 2023 00:36:50 +0000 (20:36 -0400)
don't grep the tail of a log file after running a previous test, there could be
(and have been) other items added to the log in between.

add before and after count of shutdown messages to very the actual message shows
up as the test intended, and keep the search for the shutdown message.

Signed-off-by: Christian Hopps <chopps@labn.net>
tests/topotests/bgp_features/test_bgp_features.py

index c0a5a1905d747e4235b30f5fd0d816fdf34d33b2..e033a0f00593f89ac79318c01d644ea0edd71bf5 100644 (file)
@@ -176,6 +176,19 @@ def test_bgp_convergence():
     # tgen.mininet_cli()
 
 
+def get_shut_msg_count(tgen):
+    shuts = {}
+    for rtrNum in [2, 4]:
+        shutmsg = tgen.net["r{}".format(rtrNum)].cmd_nostatus(
+            'grep -c "NOTIFICATION.*Cease/Administrative Shutdown" bgpd.log', warn=False
+        )
+        try:
+            shuts[rtrNum] = int(shutmsg.strip())
+        except ValueError:
+            shuts[rtrNum] = 0
+    return shuts
+
+
 def test_bgp_shutdown():
     "Test BGP instance shutdown"
 
@@ -185,6 +198,8 @@ def test_bgp_shutdown():
     if tgen.routers_have_failure():
         pytest.skip(tgen.errors)
 
+    shuts_before = get_shut_msg_count(tgen)
+
     tgen.net["r1"].cmd(
         'vtysh -c "conf t" -c "router bgp 65000" -c "bgp shutdown message ABCDabcd"'
     )
@@ -208,6 +223,11 @@ def test_bgp_shutdown():
         )
         assert res is None, assertmsg
 
+    shuts_after = get_shut_msg_count(tgen)
+
+    for k in shuts_before:
+        assert shuts_before[k] + 1 == shuts_after[k]
+
 
 def test_bgp_shutdown_message():
     "Test BGP Peer Shutdown Message"
@@ -222,18 +242,11 @@ def test_bgp_shutdown_message():
         logger.info("Checking BGP shutdown received on router r{}".format(rtrNum))
 
         shut_message = tgen.net["r{}".format(rtrNum)].cmd(
-            'tail bgpd.log | grep "NOTIFICATION.*Cease/Administrative Shutdown"'
+            'grep -e "NOTIFICATION.*Cease/Administrative Shutdown.*ABCDabcd" bgpd.log'
         )
         assertmsg = "BGP shutdown message not received on router R{}".format(rtrNum)
         assert shut_message != "", assertmsg
 
-        assertmsg = "Incorrect BGP shutdown message received on router R{}".format(
-            rtrNum
-        )
-        assert "ABCDabcd" in shut_message, assertmsg
-
-    # tgen.mininet_cli()
-
 
 def test_bgp_no_shutdown():
     "Test BGP instance no shutdown"