From f5da2b9a441c82bead9823bc73afbf81687faba9 Mon Sep 17 00:00:00 2001 From: Francois Dumontet Date: Thu, 28 Sep 2023 12:06:53 +0200 Subject: [PATCH] tests: add bgp4v2 MIB traps test Signed-off-by: Francois Dumontet --- .../test_bgp_snmp_bgp4v2mib.py | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 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 f07b2da527d5..402ea648d422 100755 --- a/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py +++ b/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py @@ -205,7 +205,7 @@ def _snmpwalk_origin(): } # bgp4V2NlriOrigin - tgen.mininet_cli() + #tgen.mininet_cli() output, _ = snmp.walk(".1.3.6.1.3.5.1.1.9.1.9") logger.info("FMJA") logger.info(output) @@ -245,19 +245,58 @@ def _snmptrap_ipv4(): ] # load trapd resulting file - tgen.mininet_cli() - # os.path.join(CWD, "{}/{}/snmptrapd.log".format(r2.logdir,r2.name)) + # tgen.mininet_cli() + snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir, r2.name) outputfile = open(snmptrapfile).read() - output = snmp.trap(outputfile) - logger.info(output) + output = snmp.trap_v4(outputfile) return output == expected r1.vtysh_cmd("clear bgp *") - _, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=15, wait=2) + _, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=2, wait=10) assertmsg = "Can't fetch SNMP trap for ipv4" assert result, assertmsg + def _snmptrap_ipv6(): + expected = [ + ("1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1", "7"), + ("1.3.6.1.3.5.1.1.2.1.6.1.4.192.168.12.1", "179"), + ("1.3.6.1.3.5.1.1.3.1.1.1.4.192.168.12.1", "6"), + ("1.3.6.1.3.5.1.1.3.1.2.1.4.192.168.12.1", "4"), + ("1.3.6.1.3.5.1.1.3.1.4.1.4.192.168.12.1", '"00 "'), + ("1.3.6.1.3.5.1.1.2.1.13.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", "7"), + ("1.3.6.1.3.5.1.1.2.1.6.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", "179"), + ("1.3.6.1.3.5.1.1.3.1.1.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", "6"), + ("1.3.6.1.3.5.1.1.3.1.2.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", "4"), + ( + "1.3.6.1.3.5.1.1.3.1.4.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", + '"00 "', + ), + ("1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1", "6"), + ("1.3.6.1.3.5.1.1.2.1.6.1.4.192.168.12.1", "179"), + ("1.3.6.1.3.5.1.1.2.1.13.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", "6"), + ("1.3.6.1.3.5.1.1.2.1.6.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1", "179"), + ] + + # load trapd resulting file + # tgen.mininet_cli() + + snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir, r2.name) + outputfile = open(snmptrapfile).read() + output = snmp.trap_v6(outputfile) + return output == expected + + snmptrapfile = "{}/{}/snmptrapd.log".format(r2.logdir, r2.name) + trap_file = open(snmptrapfile, "w") + trap_file.truncate(0) + trap_file.close() + r2.vtysh_cmd("conf\nbgp snmp traps bgp4-mibv2 enable") + r2.vtysh_cmd("conf\nbgp snmp traps rfc4273 disable") + r1.vtysh_cmd("clear bgp *") + _, result = topotest.run_and_expect(_snmptrap_ipv6, True, count=2, wait=10) + assertmsg = "Can't fetch SNMP trap for ipv6" + assert result, assertmsg + def test_memory_leak(): "Run the memory leak test and report results."