diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index fb006ac2a6cb86358807228138f355bfc76f702e..0b4b63c83ee130774d4661d7b46d4352b66b5524 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -542,6 +542,7 @@ def peer_info(address_str: str) -> Response: if asn_group_info: result['asn'] = asn_group_info + contacts = set() for interface in find_interfaces(address): ims_equipment = get_ims_equipment_name(interface["router"]) ims_interface = get_ims_interface(interface["interface name"]) @@ -555,6 +556,7 @@ def peer_info(address_str: str) -> Response: t = {'interface': interface} if services_and_locs.get('services', None): t['services'] = services_and_locs['services'] + contacts.update(services_and_locs['contacts']) result['interfaces'].append(t) result['locations'].extend(services_and_locs['locations']) @@ -570,6 +572,7 @@ def peer_info(address_str: str) -> Response: } for h in snmp_info] result['locations'] = _remove_duplicates_from_list(result['locations']) + result['contacts'] = sorted(list(contacts)) if not result.get('interfaces', None): result.pop('interfaces', None) result = json.dumps(result) @@ -684,9 +687,12 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \ tls_a_ids = set() tls_b_ids = set() all_tls = {} + contacts_a = set() + contacts_b = set() if circuits_a: circuits_a = json.loads(circuits_a.decode('utf-8')) for c in circuits_a: + contacts_a.update(c['contacts']) for fr in c['fibre-routes']: fr_a_ids.add(fr['id']) all_frs[fr['id']] = fr @@ -696,6 +702,7 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \ if circuits_b: circuits_b = json.loads(circuits_b.decode('utf-8')) for c in circuits_b: + contacts_b.update(c['contacts']) for fr in c['fibre-routes']: fr_b_ids.add(fr['id']) all_frs[fr['id']] = fr @@ -711,6 +718,9 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \ tls_ids = tls_a_ids & tls_b_ids if not tls_ids: tls_ids = tls_a_ids | tls_b_ids + contacts = contacts_a | contacts_b + else: + contacts = contacts_a & contacts_b top_level_services = [all_tls[x] for x in tls_ids] if fibre_routes: @@ -746,7 +756,8 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \ }, }, 'df_route': fibre_routes[0], - 'related-services': top_level_services + 'related-services': top_level_services, + 'contacts': sorted(list(contacts)) } for rs in result['related-services']: rs.pop('id', None) diff --git a/inventory_provider/routes/classifier_schema.py b/inventory_provider/routes/classifier_schema.py index 6b67e1ba038d6befcaa0d99ec7427c9d7fe98451..e4e9e0d1068e829017b3e5ae5c51ee18a0f7c555 100644 --- a/inventory_provider/routes/classifier_schema.py +++ b/inventory_provider/routes/classifier_schema.py @@ -428,7 +428,11 @@ PEER_INFO_RESPONSE_SCHEMA = { "type": "array", "items": {"$ref": "#/definitions/snmp-info"} }, - "asn": {"$ref": "#/definitions/asn-group"} + "asn": {"$ref": "#/definitions/asn-group"}, + "contacts": { + "type": "array", + "items": {"type": "string"} + } }, "additionalProperties": False } diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 00d2e8174b98927afcce1c11fa7d3ab89deb09a9..358bae060653ad02e3693551495ca14fedac4881 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -514,7 +514,10 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): def _populate_hierarchy(): nonlocal hierarchy - hierarchy = {d['id']: d for d in ims_data.get_circuit_hierarchy(ds1)} + hierarchy = {} + for d in ims_data.get_circuit_hierarchy(ds1): + d['contacts'] = customer_contacts.get(d['customerid'], []) + hierarchy[d['id']] = d logger.debug("hierarchy complete") def _populate_port_id_details(): @@ -575,10 +578,7 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): 'status': c['status'], 'circuit_type': 'service', 'project': c['project'], - 'contacts': customer_contacts.get( - c['customerid'], - [] - ) + 'contacts': sorted(list(c['contacts'])) } elif c['sub-circuits']: for sub in c['sub-circuits']: diff --git a/test/data/router-info.json b/test/data/router-info.json index af54367b2e583429302192f14dea41093d87c454..14ea174366273fcc32d990bac00d2abf6876aa09 100644 Binary files a/test/data/router-info.json and b/test/data/router-info.json differ diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index ba47b98d282a70bd79cf572a5c1f55d56db799e9..11cc878db2d0e9509c73b3bfc94ff6f165dd8ff0 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -79,7 +79,7 @@ IX_PUBLIC_PEER_INFO_KEYS = { @pytest.mark.parametrize('peer_address,expected_response_keys', [ # MDVPN, asn=13092 - ('147.91.0.117', VPN_RR_PEER_INFO_KEYS | {'asn'}), + ('147.91.0.117', VPN_RR_PEER_INFO_KEYS | {'asn', 'contacts'}), # # MDVPN, no asn # ('62.40.96.18', VPN_RR_PEER_INFO_KEYS | {'interfaces'}), # ('2001:07f8:0036:0000:0000:3417:0000:0001', IX_PUBLIC_PEER_INFO_KEYS), @@ -115,7 +115,7 @@ def test_peer_not_found(client): headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 response_data = json.loads(rv.data.decode('utf-8')) - assert response_data == {'locations': []} + assert response_data == {'locations': [], "contacts": []} @pytest.mark.parametrize('equipment,entity_name', [