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 bb629f6698bd..48f9de9cef8a 100755 --- a/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py +++ b/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py @@ -229,38 +229,73 @@ def _snmpwalk_med(): def _snmptrap_ipv4(): expected = [ - [ - ("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "0.0.0.0"), - ("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"00 00 "'), - ("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "2"), - ], - [ ("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "192.168.12.1"), ("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"00 00 "'), ("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "6"), - ], - [ ("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "192.168.12.1"), ("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"06 04 "'), - ("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "1"), - ], + ("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "7"), + ("1.3.6.1.2.1.15.3.1.7.192.168.12.1", "192.168.12.1"), + ("1.3.6.1.2.1.15.3.1.14.192.168.12.1", '"06 04 "'), + ("1.3.6.1.2.1.15.3.1.2.192.168.12.1", "6") ] # 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." tgen = get_topogen()