Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

topotests: fix snmptrap log OID parsing #15234

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
18 changes: 10 additions & 8 deletions tests/topotests/lib/snmptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading