def testParseV1FilterDefinitionForGenericTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["0"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 1) self.assertEquals(len(filter._v1Filters), 0) self.assertEquals(len(filter._v2Filters), 0) genericTrapDefinition = filter._v1Traps["0"] self.assert_(genericTrapDefinition != None) self.assertEquals(genericTrapDefinition.lineNumber, 99) self.assertEquals(genericTrapDefinition.action, "include") self.assertEquals(genericTrapDefinition.genericTrap, "0") # Now add another to make sure we can parse more than one results = filter._parseV1FilterDefinition(100, "exclude", ["5"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 2) self.assertEquals(len(filter._v1Filters), 0) self.assertEquals(len(filter._v2Filters), 0) genericTrapDefinition = filter._v1Traps["5"] self.assert_(genericTrapDefinition != None) self.assertEquals(genericTrapDefinition.lineNumber, 100) self.assertEquals(genericTrapDefinition.action, "exclude") self.assertEquals(genericTrapDefinition.genericTrap, "5")
def testParseV1FilterDefinitionForGenericTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["0"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 1) self.assertEquals(len(filter._v1Filters), 0) self.assertEquals(len(filter._v2Filters), 0) genericTrapDefinition = filter._v1Traps["0"] self.assert_(genericTrapDefinition != None) self.assertEquals(genericTrapDefinition.lineNumber, 99) self.assertEquals(genericTrapDefinition.action, "include") self.assertEquals(genericTrapDefinition.genericTrap, "0") # Now add another to make sure we can parse more than one results = filter._parseV1FilterDefinition(100, "exclude", ["5"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 2) self.assertEquals(len(filter._v1Filters), 0) self.assertEquals(len(filter._v2Filters), 0) genericTrapDefinition = filter._v1Traps["5"] self.assert_(genericTrapDefinition != None) self.assertEquals(genericTrapDefinition.lineNumber, 100) self.assertEquals(genericTrapDefinition.action, "exclude") self.assertEquals(genericTrapDefinition.genericTrap, "5")
def testParseV1FilterDefinitionFailsForInvalidEnterpriseSpecificTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5", "abc"]) self.assertEquals(results, "Specific trap 'abc' invalid; must be non-negative integer") results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5", "-1"]) self.assertEquals(results, "Specific trap '-1' invalid; must be non-negative integer")
def testParseV1FilterDefinitionFailsForInvalidTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["a"]) self.assertEquals(results, "Invalid generic trap 'a'; must be one of 0-5") results = filter._parseV1FilterDefinition(99, "include", ["6"]) self.assertEquals(results, "Invalid generic trap '6'; must be one of 0-5")
def testParseV1FilterDefinitionFailsForInvalidTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["a"]) self.assertEquals(results, "Invalid generic trap 'a'; must be one of 0-5") results = filter._parseV1FilterDefinition(99, "include", ["6"]) self.assertEquals(results, "Invalid generic trap '6'; must be one of 0-5")
def testParseV1FilterDefinitionFailsForConflictingTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["1"]) self.assertEquals(results, None) results = filter._parseV1FilterDefinition(100, "include", ["1"]) self.assertEquals(results, "Generic trap '1' conflicts with previous definition at line 99") # Verify we find a conflict for generic traps where the action differs results = filter._parseV1FilterDefinition(100, "exclude", ["1"]) self.assertEquals(results, "Generic trap '1' conflicts with previous definition at line 99")
def testParseV1FilterDefinitionFailsForEmptyOID(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", []) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid") results = filter._parseV1FilterDefinition(99, "include", [""]) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid") results = filter._parseV1FilterDefinition(99, "include", ["."]) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid") results = filter._parseV1FilterDefinition(99, "include", ["..."]) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid")
def testParseV1FilterDefinitionFailsForInvalidEnterpriseSpecificTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5", "abc"]) self.assertEquals( results, "Specific trap 'abc' invalid; must be non-negative integer") results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5", "-1"]) self.assertEquals( results, "Specific trap '-1' invalid; must be non-negative integer")
def testParseV1FilterDefinitionFailsForConflictingTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["1"]) self.assertEquals(results, None) results = filter._parseV1FilterDefinition(100, "include", ["1"]) self.assertEquals( results, "Generic trap '1' conflicts with previous definition at line 99") # Verify we find a conflict for generic traps where the action differs results = filter._parseV1FilterDefinition(100, "exclude", ["1"]) self.assertEquals( results, "Generic trap '1' conflicts with previous definition at line 99")
def testParseV1FilterDefinitionFailsForTooManyArgs(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["0", "1", "2"]) self.assertEquals( results, "Too many fields found; at most 4 fields allowed for V1 filters")
def testParseV1FilterDefinitionFailsForEmptyOID(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", []) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid") results = filter._parseV1FilterDefinition(99, "include", [""]) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid") results = filter._parseV1FilterDefinition(99, "include", ["."]) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid") results = filter._parseV1FilterDefinition(99, "include", ["..."]) self.assertEquals(results, "'' is not a valid OID: Empty OID is invalid")
def testParseV1FilterDefinitionFailsForInvalidOID(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["invalidOID"]) self.assertEquals( results, "'invalidOID' is not a valid OID: Invalid character found; only digits, '.' and '*' allowed" )
def testParseV1FilterDefinitionFailsForConflictingOID(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5", "2"]) self.assertEquals(results, None) results = filter._parseV1FilterDefinition(100, "include", [".1.3.6.1.4.5", "2"]) self.assertEquals(results, "OID '1.3.6.1.4.5' conflicts with previous definition at line 99") # Verify we find a conflict for OIDs where the action differs results = filter._parseV1FilterDefinition(100, "exclude", [".1.3.6.1.4.5", "2"]) self.assertEquals(results, "OID '1.3.6.1.4.5' conflicts with previous definition at line 99") results = filter._parseV1FilterDefinition(101, "include", [".1.3.6.1.4.*"]) self.assertEquals(results, None) # Verify we find a conflict for glob-based OIDs results = filter._parseV1FilterDefinition(102, "include", [".1.3.6.1.4.*"]) self.assertEquals(results, "OID '1.3.6.1.4.*' conflicts with previous definition at line 101") # Verify we find a conflict for glob-based OIDs where the action differs results = filter._parseV1FilterDefinition(102, "exclude", [".1.3.6.1.4.*"]) self.assertEquals(results, "OID '1.3.6.1.4.*' conflicts with previous definition at line 101")
def testParseV1FilterDefinitionFailsForConflictingOID(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5", "2"]) self.assertEquals(results, None) results = filter._parseV1FilterDefinition(100, "include", [".1.3.6.1.4.5", "2"]) self.assertEquals( results, "OID '1.3.6.1.4.5' conflicts with previous definition at line 99") # Verify we find a conflict for OIDs where the action differs results = filter._parseV1FilterDefinition(100, "exclude", [".1.3.6.1.4.5", "2"]) self.assertEquals( results, "OID '1.3.6.1.4.5' conflicts with previous definition at line 99") results = filter._parseV1FilterDefinition(101, "include", [".1.3.6.1.4.*"]) self.assertEquals(results, None) # Verify we find a conflict for glob-based OIDs results = filter._parseV1FilterDefinition(102, "include", [".1.3.6.1.4.*"]) self.assertEquals( results, "OID '1.3.6.1.4.*' conflicts with previous definition at line 101") # Verify we find a conflict for glob-based OIDs where the action differs results = filter._parseV1FilterDefinition(102, "exclude", [".1.3.6.1.4.*"]) self.assertEquals( results, "OID '1.3.6.1.4.*' conflicts with previous definition at line 101")
def testParseV1FilterDefinitionFailsForInvalidOID(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["invalidOID"]) self.assertEquals(results, "'invalidOID' is not a valid OID: Invalid character found; only digits, '.' and '*' allowed")
def testParseV1FilterDefinitionFailsForTooManyArgs(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["0", "1", "2"]) self.assertEquals(results, "Too many fields found; at most 4 fields allowed for V1 filters")
def testParseV1FilterDefinitionFailsForMissingEnterpriseSpecificTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5"]) self.assertEquals(results, "Missing specific trap number or '*'")
def testParseV1FilterDefinitionFailsForEnterpriseSpecificGlob(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5.*", "23"]) self.assertEquals(results, "Specific trap not allowed with globbed OID")
def testParseV1FilterDefinitionFailsForEnterpriseSpecificGlob(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5.*", "23"]) self.assertEquals(results, "Specific trap not allowed with globbed OID")
def testParseV1FilterDefinitionEnterpriseSpecificTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["1.2.3.*"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 1) self.assertEquals(len(filter._v2Filters), 0) oidLevels = 4 mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 1) filterDef = mapByLevel["1.2.3.*"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 99) self.assertEquals(filterDef.action, "include") self.assertEquals(filterDef.oid, "1.2.3.*") self.assertEquals(filterDef.specificTrap, None) # Add another 4-level OID results = filter._parseV1FilterDefinition(100, "exclude", ["1.2.3.4", "25"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 1) self.assertEquals(len(filter._v2Filters), 0) mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 2) filterDef = mapByLevel["1.2.3.4-25"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 100) self.assertEquals(filterDef.action, "exclude") self.assertEquals(filterDef.oid, "1.2.3.4") self.assertEquals(filterDef.specificTrap, "25") # Add a different specific trap for the same OID results = filter._parseV1FilterDefinition(101, "exclude", ["1.2.3.4", "99"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 1) self.assertEquals(len(filter._v2Filters), 0) mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 3) filterDef = mapByLevel["1.2.3.4-99"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 101) self.assertEquals(filterDef.action, "exclude") self.assertEquals(filterDef.oid, "1.2.3.4") self.assertEquals(filterDef.specificTrap, "99") # Add another single-level OID results = filter._parseV1FilterDefinition(101, "exclude", ["*"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 2) self.assertEquals(len(filter._v2Filters), 0) oidLevels = 1 mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 1) filterDef = mapByLevel["*"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 101) self.assertEquals(filterDef.action, "exclude") self.assertEquals(filterDef.oid, "*") self.assertEquals(filterDef.specificTrap, None)
def testParseV1FilterDefinitionFailsForMissingEnterpriseSpecificTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", [".1.3.6.1.4.5"]) self.assertEquals(results, "Missing specific trap number or '*'")
def testParseV1FilterDefinitionEnterpriseSpecificTrap(self): filter = TrapFilter() results = filter._parseV1FilterDefinition(99, "include", ["1.2.3.*"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 1) self.assertEquals(len(filter._v2Filters), 0) oidLevels = 4 mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 1) filterDef = mapByLevel["1.2.3.*"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 99) self.assertEquals(filterDef.action, "include") self.assertEquals(filterDef.oid, "1.2.3.*") self.assertEquals(filterDef.specificTrap, None) # Add another 4-level OID results = filter._parseV1FilterDefinition(100, "exclude", ["1.2.3.4", "25"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 1) self.assertEquals(len(filter._v2Filters), 0) mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 2) filterDef = mapByLevel["1.2.3.4-25"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 100) self.assertEquals(filterDef.action, "exclude") self.assertEquals(filterDef.oid, "1.2.3.4") self.assertEquals(filterDef.specificTrap, "25") # Add a different specific trap for the same OID results = filter._parseV1FilterDefinition(101, "exclude", ["1.2.3.4", "99"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 1) self.assertEquals(len(filter._v2Filters), 0) mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 3) filterDef = mapByLevel["1.2.3.4-99"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 101) self.assertEquals(filterDef.action, "exclude") self.assertEquals(filterDef.oid, "1.2.3.4") self.assertEquals(filterDef.specificTrap, "99") # Add another single-level OID results = filter._parseV1FilterDefinition(101, "exclude", ["*"]) self.assertEquals(results, None) self.assertEquals(len(filter._v1Traps), 0) self.assertEquals(len(filter._v1Filters), 2) self.assertEquals(len(filter._v2Filters), 0) oidLevels = 1 mapByLevel = filter._v1Filters[oidLevels] self.assert_(mapByLevel != None) self.assertEquals(len(mapByLevel), 1) filterDef = mapByLevel["*"] self.assert_(filterDef != None) self.assertEquals(filterDef.lineNumber, 101) self.assertEquals(filterDef.action, "exclude") self.assertEquals(filterDef.oid, "*") self.assertEquals(filterDef.specificTrap, None)