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

Add port_type parsing from description for BRIAN

parent df06a688
No related branches found
No related tags found
1 merge request!5Add port_type parsing from description for BRIAN
...@@ -182,12 +182,13 @@ INTERFACE_LIST_SCHEMA = { ...@@ -182,12 +182,13 @@ INTERFACE_LIST_SCHEMA = {
'dashboards_info': { 'dashboards_info': {
'type': 'array', 'type': 'array',
'items': {'$ref': '#/definitions/db_info'} 'items': {'$ref': '#/definitions/db_info'}
} },
'port_type': {'type': 'string'}
}, },
'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 +499,6 @@ def _get_dashboard_data(ifc, customers): ...@@ -498,13 +499,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 +714,17 @@ def _add_bundle_parents(interfaces, hostname=None): ...@@ -720,6 +714,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 'access'
elif 'GS' in sid:
return 'service'
return 'unknown'
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 +762,12 @@ def load_interfaces_to_poll( ...@@ -757,8 +762,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