def _test_parse_varbind_perf(self): result = [] for i in range(100): for y in range(10): result.append(['1.2.%s.%s' % (y, i), i + 3]) main_oids = tuple(['1.2.%s' % i for i in range(10)]) oids_to_poll = main_oids snmp_parser.parse_varbind(result, main_oids, oids_to_poll)
def test_parse_varbind_with_none(self): result = [ [OID1 + '.1', None], [OID2 + '.1', 1], [OID3 + '.1', 1], [OID1 + '.2', 1], [OID2 + '.2', None], [OID3 + '.2', 1], [OID1 + '.3', 1], [OID2 + '.3', 1], [OID3 + '.3', None], ] main_oids = (OID1, OID2, OID3) prev_oids_to_poll = (OID1, OID2, OID3) expected_res = [ [OID1, '1', None], [OID2, '1', 1], [OID3, '1', 1], [OID1, '2', 1], [OID2, '2', None], [OID3, '2', 1], [OID1, '3', 1], [OID2, '3', 1], [OID3, '3', None], ] expected_oids_to_poll = (OID1 + '.3', OID2 + '.3', OID3 + '.3') result, next_oids_to_poll = snmp_parser.parse_varbind( result, main_oids, prev_oids_to_poll) self.assertEqual(next_oids_to_poll, expected_oids_to_poll) self.assertEqual(result, expected_res)
def test_parse_varbind2(self): # unequal oids len result = [ ['1.2.1.1', 1], ['1.2.2.1', 1], ['1.2.3.1', 1], ['1.2.1.2', 1], ['1.2.2.2', 1], ['1.2.3.2', 1], ['1.2.999.1', 1], ['1.2.2.3', 1], ['1.2.3.3', 1], ['1.2.999.2', 1], ['1.2.2.4', 1], ['1.2.3.4', 1], ] main_oids = ('1.2.1', '1.2.2', '1.2.3') prev_oids_to_poll = ('1.2.1', '1.2.2', '1.2.3') expected_res = [['1.2.1', '1', 1], ['1.2.2', '1', 1], ['1.2.3', '1', 1], ['1.2.1', '2', 1], ['1.2.2', '2', 1], ['1.2.3', '2', 1], ['1.2.2', '3', 1], ['1.2.3', '3', 1], ['1.2.2', '4', 1], ['1.2.3', '4', 1]] expected_oids_to_poll = (None, '1.2.2.4', '1.2.3.4') result, next_oids_to_poll = snmp_parser.parse_varbind( result, main_oids, prev_oids_to_poll) self.assertEqual(next_oids_to_poll, expected_oids_to_poll) self.assertEqual(result, expected_res)
def test_parse_varbind_with_end_of_mib(self): in_data = [ [OID1 + '.1', 1], [OID2 + '.1', 1], [OID3 + '.1', 1], [OID1 + '.1', snmp_parser.end_of_mib_view], [OID2 + '.1', snmp_parser.end_of_mib_view], [OID3 + '.2', 1], ] main_oids = (OID1, OID2, OID3) prev_oids_to_poll = (OID1, OID2, OID3) expected_res = [ [OID1, '1', 1], [OID2, '1', 1], [OID3, '1', 1], [OID3, '2', 1], ] expected_oids_to_poll = (None, None, OID3 + ".2") result, next_oids_to_poll = snmp_parser.parse_varbind( in_data, main_oids, prev_oids_to_poll) self.assertEqual(next_oids_to_poll, expected_oids_to_poll) self.assertEqual(result, expected_res)