From e9866c2c3ca4f78ed8a955ae4faf49d03b0411a8 Mon Sep 17 00:00:00 2001 From: Pelle Koster <pelle.koster@geant.org> Date: Thu, 18 Apr 2024 13:38:28 +0200 Subject: [PATCH] poller/interfaces filters out irrelevant interfaces --- inventory_provider/routes/poller.py | 11 +++++++---- test/test_general_poller_routes.py | 14 ++++++++++++++ test/test_worker.py | 20 ++++++++++---------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 9a061aca..0518d81e 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 re.match(r"^(xe|ge|et|ae|irb|gr).+", 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 452cf332..9dc710c5 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,19 @@ 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 = rv.json + assert all( + re.match(r"^(xe|ge|et|ae|irb|gr).+", ifc["name"]) for ifc in response_data + ) + + 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 50a4f2e0..fa4cd517 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, -- GitLab