From 1b2388902a51e123aae11af5b3cbcaf177049e0b Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Mon, 26 Sep 2022 10:09:22 +0100 Subject: [PATCH] added customer information. RE. DBOARD3-643 --- inventory_provider/tasks/worker.py | 12 +++++++++++- test/test_worker.py | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 2919c18a..2a58d54a 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -752,6 +752,7 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): circuit_ids_and_sids = {} additional_circuit_customers = {} flexils_data = {} + customers = {} hierarchy = {} port_id_details = defaultdict(list) @@ -826,6 +827,11 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): if exceptions: raise InventoryTaskError(json.dumps(exceptions, indent=2)) + @log_task_entry_and_exit + def _populate_customers(): + nonlocal customers + customers = {c['id']: c for c in _ds().get_all_entities('customer')} + @log_task_entry_and_exit def _populate_flexils_data(): nonlocal flexils_data @@ -879,7 +885,8 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password): 'port_id_details': port_id_details, 'port_id_services': port_id_services, 'geant_nodes': geant_nodes, - 'flexils_data': flexils_data + 'flexils_data': flexils_data, + 'customers': customers } @@ -895,6 +902,7 @@ def transform_ims_data(data): circuit_ids_and_sids = data['circuit_ids_sids'] geant_nodes = data['geant_nodes'] flexils_data = data['flexils_data'] + customers = data['customers'] sid_services = defaultdict(list) @@ -935,6 +943,8 @@ def transform_ims_data(data): 'circuit_type': d['circuit-type'], 'status': d['status'], 'service_type': d['product'], + 'customerid': d['customerid'], + 'customer': customers.get(d['customerid'], ''), 'contacts': d['contacts'], 'planned_work_contacts': d['planned_work_contacts'] }) diff --git a/test/test_worker.py b/test/test_worker.py index 970e9ed1..b0f312fe 100644 --- a/test/test_worker.py +++ b/test/test_worker.py @@ -88,6 +88,15 @@ def test_extract_ims_data(mocker): 'inventory_provider.tasks.worker.ims_data.get_flexils_by_circuitid', return_value={} ) + mocker.patch( + 'inventory_provider.tasks.worker.IMS.get_all_entities', + return_value=[ + { + 'id': 1, + 'name': 'Cust 1' + } + ] + ) res = extract_ims_data() assert res['locations'] == {'loc_a': 'LOC A', 'loc_b': 'LOC B'} assert res['lg_routers'] == ['lg router 1', 'lg router 2'] @@ -362,6 +371,12 @@ def test_transform_ims_data(): } ] } + customers = { + 99: { + 'id': 99, + 'name': 'flake' + } + } data = { "locations": locations, "customer_contacts": customer_contacts, @@ -373,7 +388,8 @@ def test_transform_ims_data(): "port_id_services": port_id_services, "circuit_ids_sids": circuit_ids_and_sids, "geant_nodes": ["eq_b"], - "flexils_data": flexils_data + "flexils_data": flexils_data, + "customers": customers } orig_port_id_services_len = len(port_id_services.keys()) res = transform_ims_data(data) -- GitLab