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
def get_router_snmp_indexes(hostname, community):
indexes = {}
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))
return indexes
yield {
'name': ifc['value'],
'index': int(m.group(1))
}
......@@ -91,9 +91,9 @@ def snmp_refresh_interfaces(hostname, community):
_save_value_json(
'snmp-interfaces:' + hostname,
snmp.get_router_snmp_indexes(
list(snmp.get_router_snmp_indexes(
hostname,
community))
community)))
logger.debug(
'<<< snmp_refresh_interfaces(%r, %r)' % (hostname, community))
......
......@@ -28,8 +28,13 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"name": {"type": "string"},
"index": {"type": "integer"}
"type": "object",
"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):
'inventory_provider.snmp.walk',
_mocked_walk)
interfaces = snmp.get_router_snmp_indexes(
'ignored', 'ignored')
interfaces = list(interfaces)
interfaces = list(snmp.get_router_snmp_indexes('ignored', 'ignored'))
jsonschema.validate(interfaces, expected_result_schema)
assert interfaces, "interface list isn't empty"
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