From 460405961bf3767c87c033c6e2756e4244c1d203 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Mon, 11 Feb 2019 11:12:01 +0100 Subject: [PATCH] raise from load_netconf_data instead of returning None --- inventory_provider/tasks/worker.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index ee817b29..96917adf 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -249,7 +249,7 @@ def load_netconf_data(hostname): r = get_redis(InventoryTask.config) netconf = r.get('netconf:' + hostname) if not netconf: - return None + raise InventoryTaskError('no netconf data found for %r' % hostname) return etree.fromstring(netconf.decode('utf-8')) @@ -313,20 +313,19 @@ def reload_router_config(self, hostname): # get the timestamp for the current netconf data current_netconf_timestamp = None - netconf_doc = load_netconf_data(hostname) - if netconf_doc: + try: + netconf_doc = load_netconf_data(hostname) current_netconf_timestamp \ = juniper.netconf_changed_timestamp(netconf_doc) logger.debug( 'current netconf timestamp: %r' % current_netconf_timestamp) + except InventoryTaskError as e: + pass # ok at this point if not found # load new netconf data netconf_refresh_config.apply(args=[hostname]) netconf_doc = load_netconf_data(hostname) - if netconf_doc is None: - raise InventoryTaskError( - 'failure loading netconf data for %r' % hostname) # return if new timestamp is the same as the original timestamp new_netconf_timestamp = juniper.netconf_changed_timestamp(netconf_doc) -- GitLab