Skip to content

Commit

Permalink
topotests: fix snmptrap log OID parsing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
davischw authored and mwinter-osr committed Jan 25, 2024
1 parent 9b9abe1 commit 0681a98
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit 0681a98

Please sign in to comment.