diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 2919c18a3bbb0b9192384f4cd02cd54d3df19023..2a58d54adeb272fc831e7c5621f0398091c30131 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 970e9ed1f2f462f9367495b45136f8fe79fe9ce0..b0f312fea2a70cea2c74845e3fb8f91d93cd0d6c 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)