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

removed redundant functions and returned netconf document. RE DBOARD3-894

parent caf3e5fa
No related branches found
No related tags found
No related merge requests found
......@@ -568,11 +568,7 @@ def retrieve_and_persist_neteng_managed_device_list(
@log_task_entry_and_exit
def reload_router_config_try_all(self, hostname, lab=False):
try:
_reload_router_config_nokia(
hostname,
lab,
self.log_info,
self.log_warning)
reload_router_config_nokia(self, hostname, lab)
except Exception as e1:
self.log_warning(
f'error loading {hostname} info: {e1} - trying juniper')
......@@ -595,9 +591,12 @@ def reload_router_config_try_all(self, hostname, lab=False):
@log_task_entry_and_exit
def reload_router_config_nokia(self, hostname, lab=False):
try:
netconf_doc = _reload_router_config_nokia(
hostname, lab, self.log_info, self.log_warning)
refresh_nokia_interface_list(hostname, netconf_doc, lab)
self.log_info(
f'loading netconf data for {"lab " if lab else ""} {hostname}')
netconf_doc = retrieve_and_persist_netconf_config_nokia(
hostname, lab, self.log_warning)
r = get_next_redis(InventoryTask.config)
refresh_nokia_interface_list(hostname, netconf_doc, r, lab)
except Exception as e:
errmsg = f'unhandled exception loading {hostname} info: {e}'
logger.exception(errmsg)
......@@ -606,19 +605,6 @@ def reload_router_config_nokia(self, hostname, lab=False):
# TODO: re-raise and handle in some common way for all tasks
@log_task_entry_and_exit
def _reload_router_config_nokia(
hostname,
lab=False,
info_callback=lambda s: None,
warning_callback=lambda s: None
):
info_callback(
f'loading netconf data for {"lab " if lab else ""} {hostname}')
return retrieve_and_persist_netconf_config_nokia(
hostname, lab, warning_callback)
def retrieve_and_persist_netconf_config_nokia(
hostname, lab=False, update_callback=lambda s: None):
redis_key = f'netconf-nokia:{hostname}'
......@@ -642,21 +628,17 @@ def retrieve_and_persist_netconf_config_nokia(
raise InventoryTaskError(
f'netconf error with {hostname}'
f' and no cached netconf data found')
netconf_doc = etree.fromstring(netconf_str)
logger.info(f'Returning cached netconf data for {hostname}')
update_callback(f'Returning cached netconf data for {hostname}')
r = get_next_redis(InventoryTask.config)
r.set(redis_key, netconf_str)
logger.info(f'netconf info loaded from {hostname}')
return netconf_str
def refresh_nokia_interface_list(hostname, netconf, lab=False):
r = get_next_redis(InventoryTask.config)
_refresh_nokia_interface_list(hostname, netconf, r, lab)
return netconf_doc
def _refresh_nokia_interface_list(hostname, netconf, redis, lab=False):
def refresh_nokia_interface_list(hostname, netconf, redis, lab=False):
bundles_keybase = f'netconf-interface-bundles:{hostname}'
interfaces_all_key = f'netconf-interfaces-hosts:{hostname}'
......
......@@ -8,7 +8,7 @@ from inventory_provider.tasks import common
from inventory_provider.tasks.worker import transform_ims_data, \
extract_ims_data, persist_ims_data, \
retrieve_and_persist_neteng_managed_device_list, \
populate_poller_interfaces_cache, _refresh_nokia_interface_list
populate_poller_interfaces_cache, refresh_nokia_interface_list
def test_extract_ims_data(mocker):
......@@ -844,7 +844,7 @@ def test_refresh_nokia_interface_list(mocked_redis, data_config):
netconf_doc = etree.parse(pathlib.Path(__file__).parent.joinpath(
'data/rt0.lon.uk.lab.office.geant.net-netconf-nokia.xml'))
r = common._get_redis(data_config)
_refresh_nokia_interface_list('rt0.lon.uk.lab.office.geant.net', netconf_doc, r, True)
refresh_nokia_interface_list('rt0.lon.uk.lab.office.geant.net', netconf_doc, r, True)
keybase = 'lab:netconf-interface-bundles:rt0.lon.uk.lab.office.geant.net:'
keys = r.keys(f'{keybase}*')
bundles = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment