diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py index 06681911b261f5b8eaaf0a0245c8d0623267e953..6ca9e170af839f09295fbe7d03a5e650469598c0 100644 --- a/inventory_provider/snmp.py +++ b/inventory_provider/snmp.py @@ -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)) + } diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index d1f85aba0a137765580ad3d4b5854093d119b929..8779a1d4b22e6bff65759a829cc4733010a5b9b3 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -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)) diff --git a/test/test_snmp_handling.py b/test/test_snmp_handling.py index a0a07b4ccc5b8472be0269b31f12a567766a5b45..aef5b462b3f0f945d855039c5aa1730f122df262 100644 --- a/test/test_snmp_handling.py +++ b/test/test_snmp_handling.py @@ -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"