diff --git a/Changelog.md b/Changelog.md index 17994967e3842a53a3470660e22545402d425124..b08a15dd10356ff17b8be1033a86e1a5c8d105b9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. +## [0.58] - 2021-01-23 +- DBOARD3-385: use cached netconf data in case of schema validation errors + ## [0.57] - 2021-01-23 - DBOARD3-380: added snmp info to peer-info responses diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 4a08c5233edb47e3e88ae168bc88641d3e4d97f9..a878645893c1ff8ede8371f0fce09d3f943eb216 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -108,6 +108,10 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?> """ # noqa: E501 +class NetconfHandlingError(Exception): + pass + + def _rpc(hostname, ssh): dev = Device( host=hostname, @@ -121,14 +125,22 @@ def _rpc(hostname, ssh): def validate_netconf_config(config_doc): + """ + :param config_doc: + :return: + :raises: NetconfHandlingError in case of validation errors + """ logger = logging.getLogger(__name__) def _validate(schema, doc): if schema.validate(doc): return + messages = [] for e in schema.error_log: - logger.error("%d.%d: %s" % (e.line, e.column, e.message)) - assert False + msg = f'{e.line}.{e.column}: {e.message}' + messages.append(msg) + logger.error(msg) + raise NetconfHandlingError('\n'.join(messages)) schema_doc = etree.XML(CONFIG_SCHEMA.encode('utf-8')) config_schema = etree.XMLSchema(schema_doc) @@ -151,6 +163,7 @@ def load_config(hostname, ssh_params): :param hostname: router hostname :param ssh_params: 'ssh' config element(cf. config.py:CONFIG_SCHEMA) :return: + :raises: NetconfHandlingError from validate_netconf_config """ logger = logging.getLogger(__name__) logger.info("capturing netconf data for '%s'" % hostname) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index f8b491e264a39ed4cdb8637339adb3722a8d7eb4..c596e80b73dab131263b8e42304293cfd9512e26 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -157,7 +157,7 @@ def netconf_refresh_config(self, hostname): netconf_doc = juniper.load_config( hostname, InventoryTask.config["ssh"]) netconf_str = etree.tostring(netconf_doc, encoding='unicode') - except ConnectionError: + except (ConnectionError, juniper.NetconfHandlingError): msg = f'error loading netconf data from {hostname}' logger.exception(msg) self.log_warning(msg) diff --git a/setup.py b/setup.py index f58e5fd302ef7679771abc27a48f5129b36fd6ac..1aed21f6d75bd84d975dbf2a06cf34864e547ef7 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='inventory-provider', - version="0.57", + version="0.58", author='GEANT', author_email='swd@geant.org', description='Dashboard inventory provider',