diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index eacbf8c3cc789b3ac3eeec54178b83b63bfa90db..b457ce190a4e317005093242b5c5da1c9770fa3a 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -610,6 +610,8 @@ def _reload_router_config_nokia( f'loading netconf data for {"lab " if lab else ""} {hostname}') netconf_doc, state_doc = retrieve_and_persist_config_nokia( hostname, lab, warning_callback) + if netconf_doc is None or state_doc is None: + return r = get_next_redis(InventoryTask.config) refresh_nokia_interface_list(hostname, netconf_doc, r, lab) communities = _nokia_community_strings(InventoryTask.config) @@ -645,12 +647,13 @@ def retrieve_and_persist_config_nokia( if not state_str: failed_docs.append('port state') failed_keys.append(redis_state_key) - update_callback(f'no cached info for {failed_keys}') if failed_docs: - raise InventoryTaskError( + update_callback(f'no cached info for {failed_keys}. Ignoring this host') + logger.warning( f'Nokia doc error with {hostname}' - f' and no cached data found for {failed_docs}' + f' and no cached data found for {failed_docs}. Ignoring this host' ) + return None, None netconf_config = nokia.remove_xml_namespaces(etree.fromstring(netconf_str)) state = nokia.remove_xml_namespaces(etree.fromstring(state_str)) update_callback(f'Returning cached nokia data for {hostname}') diff --git a/test/test_worker.py b/test/test_worker.py index 66aa24f4f848c1f6e4213943b395366a396e2d18..3fd325ca7e5b5e657a5f0cc007e6881d66be6c18 100644 --- a/test/test_worker.py +++ b/test/test_worker.py @@ -3,13 +3,16 @@ import pathlib import jsonschema from lxml import etree +from ncclient.transport import TransportError from inventory_provider.nokia import remove_xml_namespaces from inventory_provider.tasks import common -from inventory_provider.tasks.worker import populate_error_report_interfaces_cache, transform_ims_data, \ +from inventory_provider.tasks.worker import populate_error_report_interfaces_cache, \ + 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, \ + retrieve_and_persist_config_nokia def test_extract_ims_data(mocker): @@ -1064,3 +1067,13 @@ def test_populate_error_report_interfaces_cache(mocker, data_config, mocked_redi nokia_router = r.get("classifier-cache:error-report-interfaces:rt0.geant.net") assert json.loads(nokia_router) == exp_nokia_router_interfaces + + +def test_nokia_retrieval_failure(mocker, data_config, mocked_redis): + mocker.patch('inventory_provider.tasks.worker.InventoryTask.config') + mocker.patch("inventory_provider.tasks.worker.nokia.load_docs", side_effect=TransportError("Mocked TransportError")) + r = common._get_redis(data_config) + mocker.patch('inventory_provider.tasks.worker.get_current_redis', return_value=r) + config_doc, state_doc = retrieve_and_persist_config_nokia("unknown.router.geant.net") + assert config_doc is None + assert state_doc is None