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
# from pysnmp.smi import view, rfc1902
OID_LIST = {
## 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'
}
RFC1213_MIB_IFDESC = '1.3.6.1.2.1.2.2.1.2'
def _v6address_oid2str(dotted_decimal):
hex_params = []
......@@ -92,8 +83,7 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
def get_router_snmp_indexes(hostname, community):
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'])
assert m, 'sanity failure parsing oid: %r' % ifc['oid']
indexes[ifc['value']] = int(m.group(1))
......
......@@ -26,71 +26,22 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
expected_result_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",
"items": {
"anyOf": [
{"$ref": "#/definitions/v4ifc"},
{"$ref": "#/definitions/v6ifc"}
]
"name": {"type": "string"},
"index": {"type": "integer"}
}
}
def _mocked_walk(agent_hostname, community, base_oid):
return [e for e in snmp_walk_responses
if e['oid'].startswith(base_oid)]
def _mocked_walk(agent_hostname, community, ignored_oid):
return snmp_walk_responses
mocker.patch(
'inventory_provider.snmp.walk',
_mocked_walk)
interfaces = snmp.get_router_interfaces(
'ignored', 'ignored', {'oids': data_config['oids']})
interfaces = snmp.get_router_snmp_indexes(
'ignored', 'ignored')
interfaces = list(interfaces)
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