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

mock nextCmd rather than walk

parent 5eca4573
No related branches found
No related tags found
No related merge requests found
......@@ -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'))
......
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