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

fixed inconsistent snmp-interfaces cache def

parent c5121a53
No related branches found
No related tags found
No related merge requests found
...@@ -82,9 +82,10 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover ...@@ -82,9 +82,10 @@ 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 = {}
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)) yield {
return indexes 'name': ifc['value'],
'index': int(m.group(1))
}
...@@ -91,9 +91,9 @@ def snmp_refresh_interfaces(hostname, community): ...@@ -91,9 +91,9 @@ def snmp_refresh_interfaces(hostname, community):
_save_value_json( _save_value_json(
'snmp-interfaces:' + hostname, 'snmp-interfaces:' + hostname,
snmp.get_router_snmp_indexes( list(snmp.get_router_snmp_indexes(
hostname, hostname,
community)) community)))
logger.debug( logger.debug(
'<<< snmp_refresh_interfaces(%r, %r)' % (hostname, community)) '<<< snmp_refresh_interfaces(%r, %r)' % (hostname, community))
......
...@@ -28,8 +28,13 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses): ...@@ -28,8 +28,13 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "array", "type": "array",
"items": { "items": {
"name": {"type": "string"}, "type": "object",
"index": {"type": "integer"} "properties": {
"name": {"type": "string"},
"index": {"type": "integer"}
},
"required": ["name", "index"],
"additionalProperties": False
} }
} }
...@@ -40,9 +45,7 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses): ...@@ -40,9 +45,7 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
'inventory_provider.snmp.walk', 'inventory_provider.snmp.walk',
_mocked_walk) _mocked_walk)
interfaces = snmp.get_router_snmp_indexes( interfaces = list(snmp.get_router_snmp_indexes('ignored', 'ignored'))
'ignored', 'ignored')
interfaces = list(interfaces)
jsonschema.validate(interfaces, expected_result_schema) jsonschema.validate(interfaces, expected_result_schema)
assert interfaces, "interface list isn't empty" assert interfaces, "interface list isn't empty"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment