Skip to content
Snippets Groups Projects
Commit 6947d2d4 authored by Robert Latta's avatar Robert Latta
Browse files

corrected function call and test. RE DBOARD3-513

parent 499619cb
No related branches found
No related tags found
No related merge requests found
......@@ -97,44 +97,6 @@ class InventoryTask(Task):
self.send_event('task-error', message=message)
@app.task(base=InventoryTask, bind=True, name='snmp_refresh_interfaces')
@log_task_entry_and_exit
def snmp_refresh_interfaces(self, hostname, community, logical_systems):
try:
interfaces = list(
snmp.get_router_snmp_indexes(hostname, community, logical_systems))
except ConnectionError:
msg = f'error loading snmp interface data from {hostname}'
logger.exception(msg)
self.log_warning(msg)
r = get_current_redis(InventoryTask.config)
interfaces = r.get(f'snmp-interfaces:{hostname}')
if not interfaces:
raise InventoryTaskError(
f'snmp error with {hostname}'
f' and no cached snmp interface data found')
# unnecessary json encode/decode here ... could be optimized
interfaces = json.loads(interfaces.decode('utf-8'))
self.log_warning(f'using cached snmp interface data for {hostname}')
r = get_next_redis(InventoryTask.config)
rp = r.pipeline()
rp.set(f'snmp-interfaces:{hostname}', json.dumps(interfaces))
# optimization for DBOARD3-372
# interfaces is a list of dicts like: {'name': str, 'index': int}
for ifc in interfaces:
ifc['hostname'] = hostname
rp.set(
f'snmp-interfaces-single:{hostname}:{ifc["name"]}',
json.dumps(ifc))
rp.execute()
self.log_info(f'snmp interface info loaded from {hostname}')
def _unmanaged_interfaces():
def _convert(d):
......@@ -592,7 +554,8 @@ def reload_lab_router_config_chorded(self, hostname):
logical_systems = juniper.logical_systems(netconf_doc)
# load snmp data, in this thread
snmp_refresh_interfaces(hostname, community, logical_systems)
snmp_refresh_interfaces_chorded(
hostname, community, logical_systems, self.log_info)
self.log_info(f'updated configuration for lab {hostname}')
except Exception as e:
......
......@@ -35,7 +35,7 @@ def test_snmp_refresh_interfaces(mocked_worker_module, router):
for k in list(_ifc_keys()):
del backend_db()[k]
worker.snmp_refresh_interfaces(router, 'fake-community', [])
worker.snmp_refresh_interfaces_chorded(router, 'fake-community', [])
assert backend_db()['snmp-interfaces:' + router]
assert list(_ifc_keys())
......@@ -76,28 +76,29 @@ def test_reload_router_config(mocked_worker_module, router, mocker):
assert 'netconf:' + router not in backend_db()
assert 'snmp-interfaces:' + router not in backend_db()
def _mocked_netconf_refresh_config_apply(args):
def _mocked_retrieve_and_persist_netconf_config(*args, **kwargs):
key = 'netconf:' + args[0]
backend_db()[key] = saved_data[key]
return saved_data[key]
mocker.patch(
'inventory_provider.tasks.worker.reload_router_config_chorded.apply',
_mocked_netconf_refresh_config_apply)
'inventory_provider.tasks.worker.retrieve_and_persist_netconf_config',
_mocked_retrieve_and_persist_netconf_config)
def _mocked_reload_router_config_chorded_apply(args):
assert len(args) == 3
backend_db().update(saved_peerings)
mocker.patch(
'inventory_provider.tasks.worker.reload_router_config_chorded.apply',
_mocked_reload_router_config_chorded_apply)
def _mocked_snmp_refresh_interfaces_apply(args):
assert len(args) == 3
def _mocked_snmp_refresh_interfaces_chorded(*args, **kwargs):
assert len(args) == 4
key = 'snmp-interfaces:' + args[0]
backend_db()[key] = saved_data[key]
mocker.patch(
'inventory_provider.tasks.worker.snmp_refresh_interfaces.apply',
_mocked_snmp_refresh_interfaces_apply)
'inventory_provider.tasks.worker.snmp_refresh_interfaces_chorded',
_mocked_snmp_refresh_interfaces_chorded)
def _mocked_snmp_refresh_peerings_chorded(*args, **kwargs):
assert len(args) == 4
backend_db().update(saved_peerings)
mocker.patch(
'inventory_provider.tasks.worker.snmp_refresh_peerings_chorded',
_mocked_snmp_refresh_peerings_chorded)
def _mocked_update_status(self, **kwargs):
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment