Skip to content
Snippets Groups Projects
Commit 5ecfdcd5 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Merge branch 'feature/POL1-643-poller-port-type' into 'develop'

Add port_type parsing from description for BRIAN

See merge request !5
parents df06a688 d87c0ec5
Branches
Tags
1 merge request!5Add port_type parsing from description for BRIAN
...@@ -120,10 +120,16 @@ class BRIAN_DASHBOARDS(Enum): ...@@ -120,10 +120,16 @@ class BRIAN_DASHBOARDS(Enum):
# NREN customer # NREN customer
NREN = auto() NREN = auto()
class PORT_TYPES(Enum):
ACCESS = auto()
SERVICE = auto()
UNKNOWN = auto()
# only used in INTERFACE_LIST_SCHEMA and sphinx docs # only used in INTERFACE_LIST_SCHEMA and sphinx docs
_DASHBOARD_IDS = [d.name for d in list(BRIAN_DASHBOARDS)] _DASHBOARD_IDS = [d.name for d in list(BRIAN_DASHBOARDS)]
_PORT_TYPES = [t.name for t in list(PORT_TYPES)]
_INTERFACE_TYPES = [i.name for i in list(INTERFACE_TYPES)] _INTERFACE_TYPES = [i.name for i in list(INTERFACE_TYPES)]
INTERFACE_LIST_SCHEMA = { INTERFACE_LIST_SCHEMA = {
...@@ -182,12 +188,13 @@ INTERFACE_LIST_SCHEMA = { ...@@ -182,12 +188,13 @@ INTERFACE_LIST_SCHEMA = {
'dashboards_info': { 'dashboards_info': {
'type': 'array', 'type': 'array',
'items': {'$ref': '#/definitions/db_info'} 'items': {'$ref': '#/definitions/db_info'}
} },
'port_type': {'enum': _PORT_TYPES}
}, },
'required': [ 'required': [
'router', 'name', 'description', 'router', 'name', 'description',
'snmp-index', 'bundle', 'bundle-parents', 'snmp-index', 'bundle', 'bundle-parents',
'circuits', 'dashboards'], 'circuits', 'dashboards', 'port_type'],
'additionalProperties': False 'additionalProperties': False
}, },
}, },
...@@ -498,13 +505,6 @@ def _get_dashboard_data(ifc, customers): ...@@ -498,13 +505,6 @@ def _get_dashboard_data(ifc, customers):
if len(dashboards) == 0: if len(dashboards) == 0:
return ifc return ifc
def _get_l2_customer_names(description):
info = description.upper().split('#')[0].split('|')[0].split()[1:]
yield info[1]
if info[0] in ['CUSTOMER', 'RE_INTERCONNECT'] \
and len(info) > 2 and info[2]:
yield info[2]
def _get_customer_name(description): def _get_customer_name(description):
name = description.split(' ') name = description.split(' ')
if len(name) >= 3: if len(name) >= 3:
...@@ -720,6 +720,17 @@ def _add_bundle_parents(interfaces, hostname=None): ...@@ -720,6 +720,17 @@ def _add_bundle_parents(interfaces, hostname=None):
yield ifc yield ifc
def _get_port_type(description):
rex = re.search(r'\$([a-zA-Z]+\-\d+)', description)
if rex:
sid = rex.group(1)
if 'GA' in sid:
return PORT_TYPES.ACCESS.name
elif 'GS' in sid:
return PORT_TYPES.SERVICE.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):
basic_interfaces = \ basic_interfaces = \
...@@ -757,8 +768,12 @@ def load_interfaces_to_poll( ...@@ -757,8 +768,12 @@ def load_interfaces_to_poll(
dashboards = _get_dashboards(ifc) dashboards = _get_dashboards(ifc)
ifc['dashboards'] = sorted([d.name for d in dashboards]) ifc['dashboards'] = sorted([d.name for d in dashboards])
yield _get_dashboard_data(
ifc = _get_dashboard_data(
ifc, ifc_services_and_customers.get('customers', [])) ifc, ifc_services_and_customers.get('customers', []))
port_type = _get_port_type(ifc['description'])
ifc['port_type'] = port_type
yield ifc
else: else:
continue continue
return _get_populated_interfaces(basic_interfaces) return _get_populated_interfaces(basic_interfaces)
......
...@@ -412,6 +412,19 @@ def test_description_dashboard_parsing( ...@@ -412,6 +412,19 @@ def test_description_dashboard_parsing(
assert set(expected_names) == {d['name'] for d in dashboards_info} assert set(expected_names) == {d['name'] for d in dashboards_info}
@pytest.mark.parametrize('description,expected_port_type', [
('SRV_IAS CUSTOMER JISC #JISC-AP1-IAS IASPS | ASN786', 'UNKNOWN'),
('SRV_GLOBAL CUSTOMER RENATER #RENATER-AP1 $GS-00505 | ASN2200 |', 'SERVICE'), # noqa: E501
('PHY CUSTOMER AZSCIENCENET SRF19095 $GA-01599 | GEANT-10G-Baku-CO-Interxion|', 'ACCESS') # noqa: E501
])
def test_description_port_type_parsing(
description, expected_port_type):
_port_type = poller._get_port_type(description)
assert _port_type == expected_port_type
def test_gws_config_json(client): def test_gws_config_json(client):
rv = client.get( rv = client.get(
'/poller/gws/direct-config', '/poller/gws/direct-config',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment