Skip to content
Snippets Groups Projects
Commit cc5a5598 authored by Erik Reid's avatar Erik Reid
Browse files

fixed unit test to support new snmp cache info

parent 3aa6d81a
No related branches found
No related tags found
No related merge requests found
...@@ -7,17 +7,8 @@ from pysnmp.smi import builder, compiler ...@@ -7,17 +7,8 @@ from pysnmp.smi import builder, compiler
# from pysnmp.smi import view, rfc1902 # from pysnmp.smi import view, rfc1902
OID_LIST = { RFC1213_MIB_IFDESC = '1.3.6.1.2.1.2.2.1.2'
## IPv4
'v4Address': '.1.3.6.1.2.1.4.20.1.1',
'v4InterfaceOID': '.1.3.6.1.2.1.4.20.1.2',
'v4InterfaceName': '.1.3.6.1.2.1.31.1.1.1.1',
'v4Mask': '.1.3.6.1.2.1.4.20.1.3',
## IPv6
'v6AddressAndMask' '.1.3.6.1.2.1.55.1.8.1.2'
'v6InterfaceName': '.1.3.6.1.2.1.55.1.5.1.2'
}
def _v6address_oid2str(dotted_decimal): def _v6address_oid2str(dotted_decimal):
hex_params = [] hex_params = []
...@@ -92,8 +83,7 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover ...@@ -92,8 +83,7 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
def get_router_snmp_indexes(hostname, community): def get_router_snmp_indexes(hostname, community):
indexes = {} indexes = {}
RFC1213_MIB_ifDesc = '1.3.6.1.2.1.2.2.1.2' for ifc in walk(hostname, community, RFC1213_MIB_IFDESC):
for ifc in walk(hostname, community, RFC1213_MIB_ifDesc):
m = re.match(r'.*\.(\d+)$', ifc['oid']) m = re.match(r'.*\.(\d+)$', ifc['oid'])
assert m, 'sanity failure parsing oid: %r' % ifc['oid'] assert m, 'sanity failure parsing oid: %r' % ifc['oid']
indexes[ifc['value']] = int(m.group(1)) indexes[ifc['value']] = int(m.group(1))
......
...@@ -26,71 +26,22 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses): ...@@ -26,71 +26,22 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
expected_result_schema = { expected_result_schema = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"v4ifc": {
"type": "object",
"properties": {
"v4Address": {
"type": "string",
"pattern": r'^(\d+\.){3}\d+$'
},
"v4Mask": {
"type": "string",
"pattern": r'^(\d+\.){3}\d+$'
},
"v4InterfaceName": {"type": "string"},
"index": {
"type": "string",
"pattern": r'^\d+$'
}
},
"required": [
"v4Address", "v4Mask", "v4InterfaceName", "index"],
"additionalProperties": False
},
"v6ifc": {
"type": "object",
"properties": {
"v6Address": {
"type": "string",
"pattern": r'^[a-f\d:]+$'
},
"v6Mask": {
"type": "string",
"pattern": r'^\d+$'
},
"v6InterfaceName": {"type": "string"},
"index": {
"type": "string",
"pattern": r'^\d+$'
}
},
"required": [
"v6Address", "v6Mask", "v6InterfaceName", "index"],
"additionalProperties": False
}
},
"type": "array", "type": "array",
"items": { "items": {
"anyOf": [ "name": {"type": "string"},
{"$ref": "#/definitions/v4ifc"}, "index": {"type": "integer"}
{"$ref": "#/definitions/v6ifc"}
]
} }
} }
def _mocked_walk(agent_hostname, community, base_oid): def _mocked_walk(agent_hostname, community, ignored_oid):
return [e for e in snmp_walk_responses return snmp_walk_responses
if e['oid'].startswith(base_oid)]
mocker.patch( mocker.patch(
'inventory_provider.snmp.walk', 'inventory_provider.snmp.walk',
_mocked_walk) _mocked_walk)
interfaces = snmp.get_router_interfaces( interfaces = snmp.get_router_snmp_indexes(
'ignored', 'ignored', {'oids': data_config['oids']}) 'ignored', 'ignored')
interfaces = list(interfaces) interfaces = list(interfaces)
jsonschema.validate(interfaces, expected_result_schema) jsonschema.validate(interfaces, expected_result_schema)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment