diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index a76b9981356907e37ebd78c2fac91390f697c26c..9dcf2726b55ad84f6577d64491da05e85f581602 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -495,6 +495,12 @@ def _get_dashboard_data(ifc, possible_names): 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 info[2]: + yield info[2] + def _get_customer_name(description): name = description.split(' ') if len(name) >= 3: @@ -515,31 +521,29 @@ def _get_dashboard_data(ifc, possible_names): return description if BRIAN_DASHBOARDS.INFRASTRUCTURE_BACKBONE.name in dashboards: - name = _get_backbone_name(description) - names = [name] + names = [_get_backbone_name(description)] elif BRIAN_DASHBOARDS.GWS_PHY_UPSTREAM.name in dashboards: host = ifc['router'] location = host.split('.')[1].upper() - name = f'{_get_customer_name(description)} - {location}' - names = [name] + names = [f'{_get_customer_name(description)} - {location}'] + elif BRIAN_DASHBOARDS.L2_CIRCUIT.name in dashboards: + # This will give names derived from the Interface Description + names = list(_get_l2_customer_names(description)) + + # DBOARD3-526 + # This will give the first customer from the Interface Description + # and additional names derived from IMS provided they also appear in + # the Interface Description + # names = [_get_customer_name(description)] + # names = names + [n for n in possible_names + # if n in description.upper().split(' ')] else: - name = _get_customer_name(description) - names = [name] - if BRIAN_DASHBOARDS.L2_CIRCUIT.name in dashboards: - # DBOARD3-524 - # Uncomment this line and comment the next if they want all - # customers from IMS - # names = names + possible_names - - # Uncomment this line and comment previous if they only want - # customers from IMS that appear in the interface description - names = names + [n for n in possible_names - if n in description.upper().split(' ')] + names = [_get_customer_name(description)] return { **ifc, 'dashboard_info': { - 'name': name, + 'name': names[0], 'interface_type': interface_type.name }, 'dashboards_info': [{ diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index 36770de22c11970a763d299c7ae5fb56f858c986..1cc7c1791549a07cf0741e7ad5ac8ee213c2a7e1 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -318,88 +318,89 @@ def test_interface_dashboard_mapping(description, expected_dashboards): assert set(list(dashboards)) == set(expected_dashboards) -@pytest.mark.parametrize('interface,dashboard_info', [ +@pytest.mark.parametrize('interface,expected_names,dashboard_info', [ ({ 'description': 'SRV_IAS CUSTOMER JISC #JISC-AP1-IAS IASPS | ASN786', 'dashboards': ['IAS_CUSTOMER', 'NREN'] - }, {'name': 'JISC', 'interface_type': 'LOGICAL'}), + }, ['JISC'], {'name': 'JISC', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L2CIRCUIT CUSTOMER JISC JISC #DUB-LON-NRENBBEXT-JANET-13015 | backup for niran ', # noqa: E501 'dashboards': ['L2_CIRCUIT'] - }, {'name': 'JISC', 'interface_type': 'LOGICAL'}), + }, ['JISC'], {'name': 'JISC', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L3VPN CUSTOMER EENET #EENET-AP2-LHCONE | ASN3221', 'dashboards': ['LHCONE', 'LHCONE_CUST', 'NREN'] - }, {'name': 'EENET', 'interface_type': 'LOGICAL'}), + }, ['EENET'], {'name': 'EENET', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_IAS PRIVATE OPTIMA-TELEKOM #HR-EduZone | For Eduzone', # noqa: E501 'dashboards': ['IAS_PEERS', 'IAS_PRIVATE'] - }, {'name': 'OPTIMA-TELEKOM', 'interface_type': 'LOGICAL'}), + }, ['OPTIMA-TELEKOM'], {'name': 'OPTIMA-TELEKOM', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_CLS PRIVATE AWS #AT-AWS-CLS|ASN16509 | ', 'dashboards': ['CLS', 'CLS_PEERS'] - }, {'name': 'AWS', 'interface_type': 'LOGICAL'}), + }, ['AWS'], {'name': 'AWS', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_IAS PUBLIC MIX #IX_Peerings_in_MIX |', 'dashboards': ['IAS_PEERS', 'IAS_PUBLIC'] - }, {'name': 'MIX', 'interface_type': 'LOGICAL'}), + }, ['MIX'], {'name': 'MIX', 'interface_type': 'LOGICAL'}), ({ 'description': 'LAG INFRASTRUCTURE BACKBONE SRF0000001 | bil-por', 'dashboards': ['INFRASTRUCTURE_BACKBONE'] - }, {'name': 'bil-por', 'interface_type': 'AGGREGATE'}), + }, ['bil-por'], {'name': 'bil-por', 'interface_type': 'AGGREGATE'}), ({ 'description': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001 | bil-por', # noqa: E501 'dashboards': ['INFRASTRUCTURE_BACKBONE'] - }, {'name': 'bil-por', 'interface_type': 'LOGICAL'}), + }, ['bil-por'], {'name': 'bil-por', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_GCS CUSTOMER FCCN MICROSOFT #FCCN_NoveSBE_ExpressRoute_Vlan1945 | UNIT CONFIGURATION HAS BEEN SYSTEM GENERATED', # noqa: E501 'dashboards': ['GCS'] - }, {'name': 'FCCN', 'interface_type': 'LOGICAL'}), + }, ['FCCN'], {'name': 'FCCN', 'interface_type': 'LOGICAL'}), ({ 'description': 'PHY UPSTREAM TELIA SRF9940473 | Telia ID: IC-326863', 'router': 'mx1.bud.hu.geant.net', 'dashboards': ['GWS_PHY_UPSTREAM'] - }, {'name': 'TELIA - BUD', 'interface_type': 'PHYSICAL'}), + }, ['TELIA - BUD'], {'name': 'TELIA - BUD', 'interface_type': 'PHYSICAL'}), ({ 'description': 'SRV_IAS UPSTREAM COGENT #COGENT_GWS_VIE | ASN174', 'dashboards': ['IAS_UPSTREAM'] - }, {'name': 'COGENT', 'interface_type': 'LOGICAL'}), + }, ['COGENT'], {'name': 'COGENT', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L3VPN RE_INTERCONNECT CLARA #REDCLARA-LIS-LHCONE | ASN27750', # noqa: E501 'dashboards': ['LHCONE', 'LHCONE_PEER', 'RE_PEER'] - }, {'name': 'CLARA', 'interface_type': 'LOGICAL'}), + }, ['CLARA'], {'name': 'CLARA', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_MDVPN CUSTOMER REDIRIS #RedIRIS_AP1_BGP_LU_CoC_1 | MD VPN CoC-REDIRIS - ', # noqa: E501 'dashboards': ['MDVPN_CUSTOMERS', 'NREN'] - }, {'name': 'REDIRIS', 'interface_type': 'LOGICAL'}), + }, ['REDIRIS'], {'name': 'REDIRIS', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L2CIRCUIT CUSTOMER TENET PSNC #lon-lon-GEANTOPEN-PSNC-TENET-18067 |', # noqa: E501 'dashboards': ['GEANTOPEN', 'L2_CIRCUIT'] - }, {'name': 'TENET', 'interface_type': 'LOGICAL'}), + }, ['TENET', 'PSNC'], {'name': 'TENET', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001', 'dashboards': ['INFRASTRUCTURE_BACKBONE'] - }, {'name': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001', 'interface_type': 'LOGICAL'}), # noqa: E501 + }, ['SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001'], {'name': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001', 'interface_type': 'LOGICAL'}), # noqa: E501 ({ 'description': 'SRV_MDVPN CUSTOMER', 'dashboards': ['MDVPN_CUSTOMERS', 'NREN'] - }, {'name': 'SRV_MDVPN CUSTOMER', 'interface_type': 'LOGICAL'}), + }, ['SRV_MDVPN CUSTOMER'], {'name': 'SRV_MDVPN CUSTOMER', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_MDVPN CUSTOMER', 'dashboards': ['MDVPN_CUSTOMERS', 'NREN'] - }, {'name': 'SRV_MDVPN CUSTOMER', 'interface_type': 'LOGICAL'}), + }, ['SRV_MDVPN CUSTOMER'], {'name': 'SRV_MDVPN CUSTOMER', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L3VPN RE_INTERCONNECT REDCLARA #REDCLARA-MAD-COPERNICUS | ASN27750', # noqa: E501 'dashboards': ['COPERNICUS'] - }, {'name': 'REDCLARA', 'interface_type': 'LOGICAL'}), + }, ['REDCLARA'], {'name': 'REDCLARA', 'interface_type': 'LOGICAL'}), ]) -def test_description_dashboard_parsing(interface, dashboard_info): +def test_description_dashboard_parsing( + interface, expected_names, dashboard_info): - updated = poller._get_dashboard_data(interface, []) + updated = poller._get_dashboard_data(interface, expected_names) info = updated['dashboard_info'] assert info == dashboard_info dashboards_info = updated['dashboards_info'] - assert dashboards_info == [dashboard_info] + assert set(expected_names) == {d['name'] for d in dashboards_info} def test_gws_config_json(client):