diff --git a/test/test_snmp_handling.py b/test/test_snmp_handling.py index 022fea5232cee69afb773f678ebce89c5dc3e632..6fe5c44ef9c21c911e384f8b00879b6b50e3ebb2 100644 --- a/test/test_snmp_handling.py +++ b/test/test_snmp_handling.py @@ -15,15 +15,34 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join( "data")) -@pytest.fixture -def snmp_walk_responses(): +def interfaces_walk_responses(): test_data_filename = os.path.join( TEST_DATA_DIRNAME, "snmp-walk-interfaces.json") with open(test_data_filename) as f: return json.loads(f.read()) -def test_snmp_interfaces(mocker, data_config, snmp_walk_responses): +def peering_walk_responses(): + test_data_filename = os.path.join( + TEST_DATA_DIRNAME, "snmp-peer-info.json") + with open(test_data_filename) as f: + for peering in json.loads(f.read()): + yield {'oid': peering['oid'], 'value': 6} + + +def _gen_mocked_nextCmd(mocked_walk_data): + engineErrorIndication = 0 + pduErrorIndication = 0 + errorIndex = 0 + varBinds = [[x['oid'], x['value']] for x in mocked_walk_data] + + def _mocked_nextCmd(*args, **kwargs): + yield engineErrorIndication, pduErrorIndication, errorIndex, varBinds + + return _mocked_nextCmd + + +def test_snmp_interfaces(mocker, data_config): expected_result_schema = { "$schema": "http://json-schema.org/draft-07/schema#", @@ -39,12 +58,9 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses): } } - def _mocked_walk(agent_hostname, community, ignored_oid): - return snmp_walk_responses - - mocker.patch( - 'inventory_provider.snmp.walk', - _mocked_walk) + _mocked_nextCmd = _gen_mocked_nextCmd(interfaces_walk_responses()) + mocker.patch('inventory_provider.snmp.nextCmd', _mocked_nextCmd) + mocker.patch('inventory_provider.snmp.UdpTransportTarget', lambda x: None) interfaces = list(snmp.get_router_snmp_indexes('ignored', 'ignored'))