diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index bdc59359251676c4b0dcd6bb4ae8fb9fd45fcec0..36167cb3292b14606b63ac03ac9fc6e62512cca8 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -106,7 +106,7 @@ def get_service_types(ds: IMS): yield d['selection'] -def get_customer_service_emails(ds: IMS): +def get_customer_tts_contacts(ds: IMS): customer_contacts = defaultdict(set) @@ -121,6 +121,21 @@ def get_customer_service_emails(ds: IMS): yield k, sorted(list(v)) +def get_customer_planned_work_contacts(ds: IMS): + + customer_contacts = defaultdict(set) + + for x in ds.get_filtered_entities( + 'customerrelatedcontact', + "contact.PlannedworkMail != ''", + CUSTOMER_RELATED_CONTACT_PROPERTIES['Contact'] + ): + customer_contacts[x['customerid']].add( + x['contact']['plannedworkmail']) + for k, v in customer_contacts.items(): + yield k, sorted(list(v)) + + def get_circuit_related_customers(ds: IMS): return_value = defaultdict(list) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index eeffb33ae076c204d7a277a4512fc2120f7660b9..fe8088f403e3005ad70a07dfaaa85d738c4004b8 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -745,6 +745,7 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): lg_routers = [] geant_nodes = [] customer_contacts = {} + planned_work_contacts = {} circuit_ids_to_monitor = [] circuit_ids_and_sids = {} additional_circuit_customers = {} @@ -772,7 +773,14 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): def _populate_customer_contacts(): nonlocal customer_contacts customer_contacts = \ - {k: v for k, v in ims_data.get_customer_service_emails(ds=_ds())} + {k: v for k, v in ims_data.get_customer_tts_contacts(ds=_ds())} + + @log_task_entry_and_exit + def _populate_customer_planned_work_contacts(): + nonlocal planned_work_contacts + planned_work_contacts = \ + {k: v for k, v in + ims_data.get_customer_planned_work_contacts(ds=_ds())} @log_task_entry_and_exit def _populate_circuit_ids_to_monitor(): @@ -799,6 +807,8 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): executor.submit(_populate_geant_nodes): 'geant_nodes', executor.submit(_populate_lg_routers): 'lg_routers', executor.submit(_populate_customer_contacts): 'customer_contacts', + executor.submit(_populate_customer_planned_work_contacts): + 'planned_work_contacts', executor.submit(_populate_circuit_ids_to_monitor): 'circuit_ids_to_monitor', executor.submit(_populate_sids): 'sids', @@ -852,6 +862,7 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): 'locations': locations, 'lg_routers': lg_routers, 'customer_contacts': customer_contacts, + 'planned_work_contacts': planned_work_contacts, 'circuit_ids_to_monitor': circuit_ids_to_monitor, 'circuit_ids_sids': circuit_ids_and_sids, 'additional_circuit_customers': additional_circuit_customers, @@ -865,6 +876,7 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): def transform_ims_data(data): locations = data['locations'] customer_contacts = data['customer_contacts'] + planned_work_contacts = data['planned_work_contacts'] circuit_ids_to_monitor = data['circuit_ids_to_monitor'] additional_circuit_customers = data['additional_circuit_customers'] hierarchy = data['hierarchy'] @@ -880,11 +892,16 @@ def transform_ims_data(data): customer_ids.update( [ac['id'] for ac in additional_circuit_customers.get(c['id'], [])] ) - return set().union( + tts_contacts = set().union( *[customer_contacts.get(cid, []) for cid in customer_ids]) + pw_contacts = set().union( + *[planned_work_contacts.get(cid, []) for cid in customer_ids]) + return tts_contacts, pw_contacts for d in hierarchy.values(): - d['contacts'] = sorted(list(_get_circuit_contacts(d))) + c, ttc = _get_circuit_contacts(d) + d['contacts'] = sorted(list(c)) + d['planned_work_contacts'] = sorted(list(ttc)) def _convert_to_bits(value, unit): unit = unit.lower() @@ -940,7 +957,8 @@ def transform_ims_data(data): 'circuit_type': c['circuit-type'], 'service_type': c['product'], 'project': c['project'], - 'contacts': c['contacts'] + 'contacts': c['contacts'], + 'planned_work_contacts': c['planned_work_contacts'] } if c['id'] in circuit_ids_to_monitor: rs[c['id']]['status'] = c['status'] @@ -1021,7 +1039,7 @@ def transform_ims_data(data): circuits = port_id_services.get(details['port_id'], []) for circ in circuits: - contacts = _get_circuit_contacts(circ) + contacts, pw_contacts = _get_circuit_contacts(circ) circ['fibre-routes'] = [] for x in set(_get_fibre_routes(circ['id'])): c = { @@ -1038,7 +1056,9 @@ def transform_ims_data(data): # why were these removed? # contacts.update(tlc.pop('contacts')) contacts.update(tlc.get('contacts')) + pw_contacts.update(tlc.get('planned_work_contacts', [])) circ['contacts'] = sorted(list(contacts)) + circ['planned_work_contacts'] = sorted(list(pw_contacts)) circ['calculated-speed'] = _get_speed(circ['id']) _format_service(circ) diff --git a/test/test_worker.py b/test/test_worker.py index 6693e97117a3d867e1b8b96b93205df764f80316..7018c2c608d62afe9ea2e0a43777b704c8212537 100644 --- a/test/test_worker.py +++ b/test/test_worker.py @@ -21,9 +21,14 @@ def test_extract_ims_data(mocker): return_value=['lg router 1', 'lg router 2'] ) mocker.patch( - 'inventory_provider.tasks.worker.ims_data.get_customer_service_emails', + 'inventory_provider.tasks.worker.ims_data.get_customer_tts_contacts', return_value=[('123', 'CON A'), ('456', 'CON B')] ) + mocker.patch( + 'inventory_provider.tasks.worker.ims_data.' + 'get_customer_planned_work_contacts', + return_value=[('223', 'CON PW A'), ('556', 'CON PW B')] + ) mocker.patch( 'inventory_provider.tasks.worker.ims_data.get_monitored_circuit_ids', return_value=[123, 456, 789] @@ -80,6 +85,8 @@ def test_extract_ims_data(mocker): assert res['locations'] == {'loc_a': 'LOC A', 'loc_b': 'LOC B'} assert res['lg_routers'] == ['lg router 1', 'lg router 2'] assert res['customer_contacts'] == {'123': 'CON A', '456': 'CON B'} + assert res['planned_work_contacts'] == \ + {'223': 'CON PW A', '556': 'CON PW B'} assert res['circuit_ids_to_monitor'] == [123, 456, 789] assert res['additional_circuit_customers'] == \ [ @@ -152,6 +159,11 @@ def test_transform_ims_data(): "cu_1_1": ["customer_1_1@a.org"] } + planned_work_contacts = { + "cu_1": ["customer_1_PW@a.org"], + "cu_1_1": ["customer_1_1_PW@a.org"] + } + port_id_details = { "port_id_1": [{ "equipment_name": "eq_a", @@ -320,6 +332,7 @@ def test_transform_ims_data(): data = { "locations": locations, "customer_contacts": customer_contacts, + "planned_work_contacts": planned_work_contacts, "circuit_ids_to_monitor": ["sub_circuit_2"], "additional_circuit_customers": additional_circuit_customer_ids, "hierarchy": hierarchy,