Skip to content
Snippets Groups Projects
Commit 8232baed authored by Pelle Koster's avatar Pelle Koster
Browse files

Merge branch 'poller-only-relevant-interfaces' into 'develop'

poller/interfaces filters out irrelevant interfaces

See merge request !34
parents 602dfdb0 fddb329b
No related branches found
No related tags found
1 merge request!34poller/interfaces filters out irrelevant interfaces
...@@ -808,10 +808,13 @@ def _get_port_type(description): ...@@ -808,10 +808,13 @@ def _get_port_type(description):
return PORT_TYPES.UNKNOWN.name return PORT_TYPES.UNKNOWN.name
def load_interfaces_to_poll( def load_interfaces_to_poll(config, hostname=None, no_lab=False, use_next_redis=False):
config, hostname=None, no_lab=False, use_next_redis=False): def is_relevant(ifc):
basic_interfaces = \ return not re.match(r"^(lt-|so-|dsc\.|fxp\d|lo\d).*", ifc["name"])
list(_load_interfaces(config, hostname, no_lab, use_next_redis))
basic_interfaces = list(
filter(is_relevant, _load_interfaces(config, hostname, no_lab, use_next_redis))
)
bundles = _load_interface_bundles(config, hostname, use_next_redis) bundles = _load_interface_bundles(config, hostname, use_next_redis)
services_and_customers = \ services_and_customers = \
_get_services_and_customers(config, hostname, use_next_redis) _get_services_and_customers(config, hostname, use_next_redis)
......
import json import json
import re
import jsonschema import jsonschema
import pytest import pytest
from inventory_provider.routes import poller from inventory_provider.routes import poller
...@@ -36,6 +37,24 @@ def test_get_all_interfaces_no_lab(client): ...@@ -36,6 +37,24 @@ def test_get_all_interfaces_no_lab(client):
assert all('.lab.' not in name for name in response_routers) 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): def test_all_router_interface_speeds(client):
rv = client.get( rv = client.get(
'/poller/speeds', '/poller/speeds',
......
...@@ -657,7 +657,7 @@ def test_populate_poller_interfaces_cache( ...@@ -657,7 +657,7 @@ def test_populate_poller_interfaces_cache(
all_interfaces = [ all_interfaces = [
{ {
"router": "router_a.geant.net", "router": "router_a.geant.net",
"name": "interface_a", "name": "et/1",
"bundle": ["ae_a"], "bundle": ["ae_a"],
"bundle-parents": [], "bundle-parents": [],
"description": "DESCRIPTION A", "description": "DESCRIPTION A",
...@@ -681,7 +681,7 @@ def test_populate_poller_interfaces_cache( ...@@ -681,7 +681,7 @@ def test_populate_poller_interfaces_cache(
}, },
{ {
"router": "lab_router_a.geant.net", "router": "lab_router_a.geant.net",
"name": "lab_interface_a", "name": "et/2/lab",
"bundle": ["ae_c"], "bundle": ["ae_c"],
"bundle-parents": [], "bundle-parents": [],
"description": "DESCRIPTION C $GA-0001", "description": "DESCRIPTION C $GA-0001",
...@@ -699,8 +699,8 @@ def test_populate_poller_interfaces_cache( ...@@ -699,8 +699,8 @@ def test_populate_poller_interfaces_cache(
bundles = { bundles = {
"router_z.geant.net": {"ae_1": ["interface_z"]}, "router_z.geant.net": {"ae_1": ["interface_z"]},
"lab_router_a.geant.net": {"ae_c": ["lab_interface_a"]}, "lab_router_a.geant.net": {"ae_c": ["et/2/lab"]},
"router_a.geant.net": {"ae_a": ["interface_a"]}, "router_a.geant.net": {"ae_a": ["et/1"]},
} }
snmp_indexes = { snmp_indexes = {
...@@ -715,8 +715,8 @@ def test_populate_poller_interfaces_cache( ...@@ -715,8 +715,8 @@ def test_populate_poller_interfaces_cache(
"index": 1231, "index": 1231,
"community": "COMMUNITY_A" "community": "COMMUNITY_A"
}, },
"interface_a": { "et/1": {
"name": "interface_a", "name": "et/1",
"index": 12, "index": 12,
"community": "COMMUNITY_A" "community": "COMMUNITY_A"
} }
...@@ -761,7 +761,7 @@ def test_populate_poller_interfaces_cache( ...@@ -761,7 +761,7 @@ def test_populate_poller_interfaces_cache(
no_lab_res = [ no_lab_res = [
{ {
'router': 'router_a.geant.net', 'router': 'router_a.geant.net',
'name': 'interface_a', 'name': 'et/1',
'bundle': ['ae_a'], 'bundle': ['ae_a'],
'bundle-parents': [], 'bundle-parents': [],
'description': 'DESCRIPTION A', 'description': 'DESCRIPTION A',
...@@ -774,7 +774,7 @@ def test_populate_poller_interfaces_cache( ...@@ -774,7 +774,7 @@ def test_populate_poller_interfaces_cache(
'router': 'router_a.geant.net', 'router': 'router_a.geant.net',
'name': 'ae_a', 'name': 'ae_a',
'bundle': [], 'bundle': [],
'bundle-parents': ['interface_a'], 'bundle-parents': ['et/1'],
'description': 'DESCRIPTION B $GA-0001', 'description': 'DESCRIPTION B $GA-0001',
'circuits': [], 'circuits': [],
'port_type': 'ACCESS', 'port_type': 'ACCESS',
...@@ -785,7 +785,7 @@ def test_populate_poller_interfaces_cache( ...@@ -785,7 +785,7 @@ def test_populate_poller_interfaces_cache(
'router': 'router_a.geant.net', 'router': 'router_a.geant.net',
'name': 'ae_a.123', 'name': 'ae_a.123',
'bundle': [], 'bundle': [],
'bundle-parents': ['interface_a'], 'bundle-parents': ['et/1'],
'description': 'DESCRIPTION C', 'description': 'DESCRIPTION C',
'circuits': [{ 'circuits': [{
'id': 321, 'id': 321,
...@@ -803,7 +803,7 @@ def test_populate_poller_interfaces_cache( ...@@ -803,7 +803,7 @@ def test_populate_poller_interfaces_cache(
"router": "lab_router_a.geant.net", "router": "lab_router_a.geant.net",
"name": "ae_c", "name": "ae_c",
"bundle": [], "bundle": [],
"bundle-parents": ["lab_interface_a"], "bundle-parents": ["et/2/lab"],
"description": "DESCRIPTION D $GS-0001", "description": "DESCRIPTION D $GS-0001",
"circuits": [], "circuits": [],
"snmp-index": 3, "snmp-index": 3,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment