diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 935d293eaff817f27fa826b0cc067c884fa64243..89d0fe08b7233a2399f073220d6afb602e9f1272 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -2,7 +2,6 @@ import contextlib import logging import re import ipaddress -import time import ncclient import ncclient.manager @@ -11,7 +10,6 @@ from jnpr.junos import exception as EzErrors from lxml import etree import netifaces import requests -from ncclient.xml_ import to_xml CONFIG_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py index 8baec728a3eacf1abc950199b03e0d2bdb32efd7..52726b3282fbeb3fb2d9b3324617cc2e46a38d59 100644 --- a/inventory_provider/routes/data.py +++ b/inventory_provider/routes/data.py @@ -175,6 +175,8 @@ def router_interfaces(hostname=None): result = [] for ifc in common.load_json_docs(config, key_pattern): + if ifc['key'] == 'netconf-interfaces:all': + continue key_fields = ifc['key'].split(':') ifc['value']['router'] = key_fields[1] result.append(ifc['value']) diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 638e2dbe4480017b5b7d4ec9804de186abf1baf4..7704c53947fcc46b3e059b5b060c22690ba2207f 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -700,12 +700,9 @@ def _load_interfaces( yield from _load_docs(f'lab:{base_key_pattern}') -def _add_speeds(config, interfaces): - netconf_interfaces_all = list(common.load_json_docs(config, 'netconf-interfaces:all')) - try: - all_netconf_interfaces = netconf_interfaces_all[0]['value'] - except IndexError: - all_netconf_interfaces = [] +def _add_speeds(interfaces): + r = common.get_current_redis() + all_netconf_interfaces = json.loads(r.get('netconf-interfaces:all')) or [] netconf_interface_index = {} for nc_ifc in all_netconf_interfaces: @@ -925,9 +922,7 @@ def _load_interfaces_and_speeds(hostname=None): current_app.config['INVENTORY_PROVIDER_CONFIG'], hostname, no_lab=no_lab) - basic_interfaces_with_speeds = _add_speeds( - current_app.config['INVENTORY_PROVIDER_CONFIG'], - basic_interfaces) + basic_interfaces_with_speeds = _add_speeds(basic_interfaces) with_bundles = _add_bundle_parents(list(basic_interfaces_with_speeds), hostname) def _result_ifc(ifc): diff --git a/test/data/router-info.json b/test/data/router-info.json index 6b47c27e1c8da3b0b19101dba6abe7e17f7a95eb..c5d6758fdbe6dd4be250a18fc25afa3c04386104 100644 Binary files a/test/data/router-info.json and b/test/data/router-info.json differ diff --git a/test/test_general_routes.py b/test/test_general_routes.py index d0349093646d9bcc49ddec0d331e5dc77824999c..2cecfa590769440c0a4ea733e72fae5d19a78d93 100644 --- a/test/test_general_routes.py +++ b/test/test_general_routes.py @@ -27,6 +27,38 @@ def test_load_json_docs(data_config, mocked_redis): '$schema': 'http://json-schema.org/draft-07/schema#', 'definitions': { + 'allInterfaces': { + 'type': 'array', + 'items': { + '$ref': '#/definitions/extendedInterface' + } + }, + # after several attempts to get this definition to inherit from interface, + # they didn't work, so duplication is unfortunately necessary + 'extendedInterface': { + 'type': 'object', + 'properties': { + 'logical-system': {'type': 'string'}, + 'name': {'type': 'string'}, + 'description': {'type': 'string'}, + 'bundle': { + 'type': 'array', + 'items': {'type': 'string'} + }, + 'ipv4': { + 'type': 'array', + 'items': {'type': 'string'} + }, + 'ipv6': { + 'type': 'array', + 'items': {'type': 'string'} + }, + 'hostname': {'type': 'string'}, + 'speed': {'type': 'string'} + }, + 'required': ['name', 'description', 'ipv4', 'ipv6', 'hostname', 'speed'], + 'additionalProperties': False + }, 'interface': { 'type': 'object', 'properties': { @@ -54,7 +86,11 @@ def test_load_json_docs(data_config, mocked_redis): 'type': 'object', 'properties': { 'key': {'type': 'string'}, - 'value': {'$ref': '#/definitions/interface'} + 'value': { + 'oneOf': [ + {'$ref': '#/definitions/interface'}, + {'$ref': '#/definitions/allInterfaces'} + ]} }, 'required': ['key', 'value'], 'additionalProperties': False