diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 2b968fe575e61ab05917d2a36b2d40ed2980ca40..c8a78993a3024bb09f6fb723097a8c5da57d8b37 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -475,7 +475,7 @@ def _get_dashboards(interface): yield BRIAN_DASHBOARDS.NREN -def _get_dashboard_data(ifc, possible_names): +def _get_dashboard_data(ifc, customers): def _get_interface_type(description): if re.match(r'^PHY', description): @@ -529,18 +529,21 @@ def _get_dashboard_data(ifc, possible_names): 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(' ')] + # names = list(_get_l2_customer_names(description)) + # This will give first 2 names IMS + names = [c['name'] for c in customers][:2] + else: names = [_get_customer_name(description)] + # if no customers found just return the original data + if not names: + return ifc + + # to maintain compatability with current brian dashboard manager we will + # continue to return dashboard_info with the first customer name. We will + # also return dashboards_info (note the plural of dashboards) with up to + # two customers return { **ifc, 'dashboard_info': { @@ -608,9 +611,15 @@ def _get_services_and_customers(config, hostname=None, use_next_redis=False): continue included_service_ids.add(s['id']) - cs['customers'].append(s['customer']) + cs['customers'].append({ + 'name': s['customer'], + 'type': 'UNKNOWN' + }) for c in s.get('additional_customers', []): - cs['customers'].append(c['name']) + cs['customers'].append({ + 'name': c['name'], + 'type': c.get('type', 'UNKNOWN') + }) if s['circuit_type'] == 'service': cs['services'].append({ 'id': s['id'], diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index 1bc5e528d57f7629ee0e5e4f6c6317d46271f6ad..dab2f8b38c16904f78ab84af4b2faf1d2675822f 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -318,96 +318,97 @@ def test_interface_dashboard_mapping(description, expected_dashboards): assert set(list(dashboards)) == set(expected_dashboards) -@pytest.mark.parametrize('interface,expected_names,dashboard_info', [ +@pytest.mark.parametrize('interface,customers,dashboard_info', [ ({ 'description': 'SRV_IAS CUSTOMER JISC #JISC-AP1-IAS IASPS | ASN786', 'dashboards': ['IAS_CUSTOMER', 'NREN'] - }, ['JISC'], {'name': 'JISC', 'interface_type': 'LOGICAL'}), + }, [{'name': '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'] - }, ['JISC'], {'name': 'JISC', 'interface_type': 'LOGICAL'}), + }, [{'name': 'JISC'}], {'name': 'JISC', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L3VPN CUSTOMER EENET #EENET-AP2-LHCONE | ASN3221', 'dashboards': ['LHCONE', 'LHCONE_CUST', 'NREN'] - }, ['EENET'], {'name': 'EENET', 'interface_type': 'LOGICAL'}), + }, [{'name': 'EENET'}], {'name': 'EENET', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_IAS PRIVATE OPTIMA-TELEKOM #HR-EduZone | For Eduzone', # noqa: E501 'dashboards': ['IAS_PEERS', 'IAS_PRIVATE'] }, - ['OPTIMA-TELEKOM'], + [{'name': 'OPTIMA-TELEKOM'}], {'name': 'OPTIMA-TELEKOM', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_CLS PRIVATE AWS #AT-AWS-CLS|ASN16509 | ', 'dashboards': ['CLS', 'CLS_PEERS'] - }, ['AWS'], {'name': 'AWS', 'interface_type': 'LOGICAL'}), + }, [{'name': 'AWS'}], {'name': 'AWS', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_IAS PUBLIC MIX #IX_Peerings_in_MIX |', 'dashboards': ['IAS_PEERS', 'IAS_PUBLIC'] - }, ['MIX'], {'name': 'MIX', 'interface_type': 'LOGICAL'}), + }, [{'name': 'MIX'}], {'name': 'MIX', 'interface_type': 'LOGICAL'}), ({ 'description': 'LAG INFRASTRUCTURE BACKBONE SRF0000001 | bil-por', 'dashboards': ['INFRASTRUCTURE_BACKBONE'] - }, ['bil-por'], {'name': 'bil-por', 'interface_type': 'AGGREGATE'}), + }, [{'name': 'bil-por'}], {'name': 'bil-por', 'interface_type': 'AGGREGATE'}), # noqa: E501 ({ 'description': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001 | bil-por', # noqa: E501 'dashboards': ['INFRASTRUCTURE_BACKBONE'] - }, ['bil-por'], {'name': 'bil-por', 'interface_type': 'LOGICAL'}), + }, [{'name': 'bil-por'}], {'name': 'bil-por', 'interface_type': 'LOGICAL'}), # noqa: E501 ({ 'description': 'SRV_GCS CUSTOMER FCCN MICROSOFT #FCCN_NoveSBE_ExpressRoute_Vlan1945 | UNIT CONFIGURATION HAS BEEN SYSTEM GENERATED', # noqa: E501 'dashboards': ['GCS'] - }, ['FCCN'], {'name': 'FCCN', 'interface_type': 'LOGICAL'}), + }, [{'name': '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'] - }, ['TELIA - BUD'], {'name': 'TELIA - BUD', 'interface_type': 'PHYSICAL'}), + }, [{'name': 'TELIA - BUD'}], {'name': 'TELIA - BUD', 'interface_type': 'PHYSICAL'}), # noqa: E501 ({ 'description': 'SRV_IAS UPSTREAM COGENT #COGENT_GWS_VIE | ASN174', 'dashboards': ['IAS_UPSTREAM'] - }, ['COGENT'], {'name': 'COGENT', 'interface_type': 'LOGICAL'}), + }, [{'name': 'COGENT'}], {'name': 'COGENT', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L3VPN RE_INTERCONNECT CLARA #REDCLARA-LIS-LHCONE | ASN27750', # noqa: E501 'dashboards': ['LHCONE', 'LHCONE_PEER', 'RE_PEER'] - }, ['CLARA'], {'name': 'CLARA', 'interface_type': 'LOGICAL'}), + }, [{'name': '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'] - }, ['REDIRIS'], {'name': 'REDIRIS', 'interface_type': 'LOGICAL'}), + }, [{'name': 'REDIRIS'}], {'name': 'REDIRIS', 'interface_type': 'LOGICAL'}), # noqa: E501 ({ 'description': 'SRV_L2CIRCUIT CUSTOMER TENET PSNC #lon-lon-GEANTOPEN-PSNC-TENET-18067 |', # noqa: E501 'dashboards': ['GEANTOPEN', 'L2_CIRCUIT'] - }, ['TENET', 'PSNC'], {'name': 'TENET', 'interface_type': 'LOGICAL'}), + }, [{'name': 'TENET'}, {'name': 'PSNC'}], {'name': 'TENET', 'interface_type': 'LOGICAL'}), # noqa: E501 ({ 'description': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001', 'dashboards': ['INFRASTRUCTURE_BACKBONE'] }, - ['SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001'], + [{'name': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001'}], {'name': 'SRV_GLOBAL INFRASTRUCTURE BACKBONE SRF0000001', 'interface_type': 'LOGICAL'}), # noqa: E501 ({ 'description': 'SRV_MDVPN CUSTOMER', 'dashboards': ['MDVPN_CUSTOMERS', 'NREN'] }, - ['SRV_MDVPN CUSTOMER'], + [{'name': 'SRV_MDVPN CUSTOMER'}], {'name': 'SRV_MDVPN CUSTOMER', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_MDVPN CUSTOMER', 'dashboards': ['MDVPN_CUSTOMERS', 'NREN'] }, - ['SRV_MDVPN CUSTOMER'], + [{'name': 'SRV_MDVPN CUSTOMER'}], {'name': 'SRV_MDVPN CUSTOMER', 'interface_type': 'LOGICAL'}), ({ 'description': 'SRV_L3VPN RE_INTERCONNECT REDCLARA #REDCLARA-MAD-COPERNICUS | ASN27750', # noqa: E501 'dashboards': ['COPERNICUS'] - }, ['REDCLARA'], {'name': 'REDCLARA', 'interface_type': 'LOGICAL'}), + }, [{'name': 'REDCLARA'}], {'name': 'REDCLARA', 'interface_type': 'LOGICAL'}), # noqa: E501 ]) def test_description_dashboard_parsing( - interface, expected_names, dashboard_info): + interface, customers, dashboard_info): - updated = poller._get_dashboard_data(interface, expected_names) + updated = poller._get_dashboard_data(interface, customers) info = updated['dashboard_info'] assert info == dashboard_info dashboards_info = updated['dashboards_info'] + expected_names = [c['name'] for c in customers] assert set(expected_names) == {d['name'] for d in dashboards_info}