From 961667e34f160a1e1a0ec85becaa4feb0e262a87 Mon Sep 17 00:00:00 2001 From: David Schweizer Date: Wed, 24 Jan 2024 11:16:03 +0100 Subject: [PATCH 1/2] topotests: fix snmptrap log OID parsing Replace OID string parsing of snmptrap log files based on odd/even line numbers with regex string search to prevent test failures in cases where log entries don't match assumed order. Signed-off-by: David Schweizer --- tests/topotests/lib/snmptest.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/topotests/lib/snmptest.py b/tests/topotests/lib/snmptest.py index bb7c0787c1e1..814813f7f458 100644 --- a/tests/topotests/lib/snmptest.py +++ b/tests/topotests/lib/snmptest.py @@ -213,14 +213,15 @@ def is_notif_bgp4v2_valid(self, output_list, address, type_requested): return False def get_notif_bgp4(self, output_file): + notifs = [] notif_list = [] whitecleanfile = re.sub("\t", " ", output_file) results = whitecleanfile.strip().split("\n") - # don't consider SNMP additional messages - notifs_first = [elem for elem in results if not ("SNMP" in elem)] - # don't consider additional application messages - notifs = [elem for index, elem in enumerate(notifs_first) if index % 2 != 0] + # don't consider additional SNMP or application messages + for result in results: + if re.search(r"(\.([0-9]+))+\s", result): + notifs.append(result) oid_v4 = r"1\.3\.6\.1\.2\.1\.15" for one_notif in notifs: @@ -232,14 +233,15 @@ def get_notif_bgp4(self, output_file): return notif_list def get_notif_bgp4v2(self, output_file): + notifs = [] notif_list = [] whitecleanfile = re.sub("\t", " ", output_file) results = whitecleanfile.strip().split("\n") - # don't consider SNMP additional messages - notifs_first = [elem for elem in results if not ("SNMP" in elem)] - # don't consider additional application messages - notifs = [elem for index, elem in enumerate(results) if index % 2 != 0] + # don't consider additional SNMP or application messages + for result in results: + if re.search(r"(\.([0-9]+))+\s", result): + notifs.append(result) oid_v6 = r"1\.3\.6\.1\.3\.5\.1" for one_notif in notifs: From 1bd96365e456cdf9345010cb231ebac4e0af2ea7 Mon Sep 17 00:00:00 2001 From: David Schweizer Date: Wed, 7 Feb 2024 13:50:53 +0100 Subject: [PATCH 2/2] tests: Reduce wait intervals in test_bgp_snmp_bgp4v2mib Remove sleep time in test_bgp_snmp_bgp4v2mib before run_and_expect and reduce wait intervals for faster test convergence. Signed-off-by: Martin Winter Signed-off-by: David Schweizer --- .../topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py b/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py index 8cd49e35483f..c296aaaf6d52 100755 --- a/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py +++ b/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py @@ -276,7 +276,7 @@ def __get_notif_bgp4_in_trap_file(router): pytest.skip(error_msg) rr.vtysh_cmd("clear bgp *") - _, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=2, wait=10) + _, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=30, wait=1) assertmsg = "Can't fetch SNMP trap for ipv4" assert result, assertmsg @@ -308,8 +308,7 @@ def __get_notif_bgp4v2_in_trap_file(router): r2.vtysh_cmd("conf\nbgp snmp traps bgp4-mibv2") r2.vtysh_cmd("conf\nno bgp snmp traps rfc4273") rr.vtysh_cmd("clear bgp *") - sleep(30) - _, result = topotest.run_and_expect(_snmptrap_ipv6, True, count=2, wait=10) + _, result = topotest.run_and_expect(_snmptrap_ipv6, True, count=60, wait=1) assertmsg = "Can't fetch SNMP trap for ipv6" assert result, assertmsg