diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 9a061acad31590801ad3f40f3e3e3e88e6d21aac..45634297e78c08effbb9aafa804da806816d4681 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -808,10 +808,13 @@ def _get_port_type(description): return PORT_TYPES.UNKNOWN.name -def load_interfaces_to_poll( - config, hostname=None, no_lab=False, use_next_redis=False): - basic_interfaces = \ - list(_load_interfaces(config, hostname, no_lab, use_next_redis)) +def load_interfaces_to_poll(config, hostname=None, no_lab=False, use_next_redis=False): + def is_relevant(ifc): + return not re.match(r"^(lt-|so-|dsc\.|fxp\d|lo\d).*", ifc["name"]) + + basic_interfaces = list( + filter(is_relevant, _load_interfaces(config, hostname, no_lab, use_next_redis)) + ) bundles = _load_interface_bundles(config, hostname, use_next_redis) services_and_customers = \ _get_services_and_customers(config, hostname, use_next_redis) diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index 452cf332e10cea3bbbd1c6cc45a3d792cdd3b648..da419f00736abf6ae444266a8b6575bdc06161cc 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -1,4 +1,5 @@ import json +import re import jsonschema import pytest from inventory_provider.routes import poller @@ -36,6 +37,24 @@ def test_get_all_interfaces_no_lab(client): assert all('.lab.' not in name for name in response_routers) +def test_get_interfaces_returns_only_relevant_interfaces(client): + rv = client.get( + "/poller/interfaces", + headers=DEFAULT_REQUEST_HEADERS, + ) + assert rv.status_code == 200 + assert rv.is_json + response_data = set(ifc["name"] for ifc in rv.json) + # This check for "good" interfaces is for juniper only. Either delete or update + # once nokia routers are included in the test data + assert all( + ifc for ifc in response_data if re.match(r"^(xe|ge|et|ae|irb|gr).+", ifc) + ) + assert not any( + ifc for ifc in response_data if re.match(r"^(lt-|so-|dsc\.|fxp\d|lo\d).*", ifc) + ) + + def test_all_router_interface_speeds(client): rv = client.get( '/poller/speeds', diff --git a/test/test_worker.py b/test/test_worker.py index 50a4f2e03035770d62bd2ed3042075b3db64f79c..fa4cd5174b20c768b20b1e1237230a6a4ca99393 100644 --- a/test/test_worker.py +++ b/test/test_worker.py @@ -657,7 +657,7 @@ def test_populate_poller_interfaces_cache( all_interfaces = [ { "router": "router_a.geant.net", - "name": "interface_a", + "name": "et/1", "bundle": ["ae_a"], "bundle-parents": [], "description": "DESCRIPTION A", @@ -681,7 +681,7 @@ def test_populate_poller_interfaces_cache( }, { "router": "lab_router_a.geant.net", - "name": "lab_interface_a", + "name": "et/2/lab", "bundle": ["ae_c"], "bundle-parents": [], "description": "DESCRIPTION C $GA-0001", @@ -699,8 +699,8 @@ def test_populate_poller_interfaces_cache( bundles = { "router_z.geant.net": {"ae_1": ["interface_z"]}, - "lab_router_a.geant.net": {"ae_c": ["lab_interface_a"]}, - "router_a.geant.net": {"ae_a": ["interface_a"]}, + "lab_router_a.geant.net": {"ae_c": ["et/2/lab"]}, + "router_a.geant.net": {"ae_a": ["et/1"]}, } snmp_indexes = { @@ -715,8 +715,8 @@ def test_populate_poller_interfaces_cache( "index": 1231, "community": "COMMUNITY_A" }, - "interface_a": { - "name": "interface_a", + "et/1": { + "name": "et/1", "index": 12, "community": "COMMUNITY_A" } @@ -761,7 +761,7 @@ def test_populate_poller_interfaces_cache( no_lab_res = [ { 'router': 'router_a.geant.net', - 'name': 'interface_a', + 'name': 'et/1', 'bundle': ['ae_a'], 'bundle-parents': [], 'description': 'DESCRIPTION A', @@ -774,7 +774,7 @@ def test_populate_poller_interfaces_cache( 'router': 'router_a.geant.net', 'name': 'ae_a', 'bundle': [], - 'bundle-parents': ['interface_a'], + 'bundle-parents': ['et/1'], 'description': 'DESCRIPTION B $GA-0001', 'circuits': [], 'port_type': 'ACCESS', @@ -785,7 +785,7 @@ def test_populate_poller_interfaces_cache( 'router': 'router_a.geant.net', 'name': 'ae_a.123', 'bundle': [], - 'bundle-parents': ['interface_a'], + 'bundle-parents': ['et/1'], 'description': 'DESCRIPTION C', 'circuits': [{ 'id': 321, @@ -803,7 +803,7 @@ def test_populate_poller_interfaces_cache( "router": "lab_router_a.geant.net", "name": "ae_c", "bundle": [], - "bundle-parents": ["lab_interface_a"], + "bundle-parents": ["et/2/lab"], "description": "DESCRIPTION D $GS-0001", "circuits": [], "snmp-index": 3,