diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 84ab31934494e542778c1cc41236aa3f928ef0d1..456fe5defc75af7c1edb1cbe4e2169ed89ddc3f0 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -182,12 +182,13 @@ INTERFACE_LIST_SCHEMA = { 'dashboards_info': { 'type': 'array', 'items': {'$ref': '#/definitions/db_info'} - } + }, + 'port_type': {'type': 'string'} }, 'required': [ 'router', 'name', 'description', 'snmp-index', 'bundle', 'bundle-parents', - 'circuits', 'dashboards'], + 'circuits', 'dashboards', 'port_type'], 'additionalProperties': False }, }, @@ -498,13 +499,6 @@ def _get_dashboard_data(ifc, customers): if len(dashboards) == 0: 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): name = description.split(' ') if len(name) >= 3: @@ -720,6 +714,17 @@ def _add_bundle_parents(interfaces, hostname=None): 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( config, hostname=None, no_lab=False, use_next_redis=False): basic_interfaces = \ @@ -757,8 +762,12 @@ def load_interfaces_to_poll( dashboards = _get_dashboards(ifc) ifc['dashboards'] = sorted([d.name for d in dashboards]) - yield _get_dashboard_data( + + ifc = _get_dashboard_data( ifc, ifc_services_and_customers.get('customers', [])) + port_type = _get_port_type(ifc['description']) + ifc['port_type'] = port_type + yield ifc else: continue return _get_populated_interfaces(basic_interfaces) diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index 3ac1cf637120ad2a59b62bac2f699ef4f6dd5a7e..7159c8d41a4be3b5b6b6493c91a37141635b5f23 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -412,6 +412,19 @@ def test_description_dashboard_parsing( 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): rv = client.get( '/poller/gws/direct-config',