diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index 7d6aa5c10c1c69c2f91ccd3355483d5f73795b73..e918835c2ee01fb560d92e84a2f9fa89d97ca174 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -476,3 +476,11 @@ def lookup_lg_routers(ds: IMS): } } yield eq + + +def lookup_geant_nodes(ds: IMS): + + return (n["name"]for n in ds.get_filtered_entities( + 'Node', + 'customer.Name == "GEANT"', + ims.EQUIP_DEF_PROPERTIES['Nodes'])) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index ef9a1c66011ccaca49eca44b8418f9104f32b455..47aeb0dadd881f9d8eec7f77d3e9ffd0a4b52bae 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -717,6 +717,7 @@ def extract_ims_data(): locations = {} lg_routers = [] + geant_nodes = [] customer_contacts = {} circuit_ids_to_monitor = [] circuit_ids_and_sids = {} @@ -734,6 +735,10 @@ def extract_ims_data(): nonlocal lg_routers lg_routers = list(ims_data.lookup_lg_routers(ds=_ds())) + def _populate_geant_nodes(): + nonlocal geant_nodes + geant_nodes = list(ims_data.lookup_geant_nodes(ds=_ds())) + def _populate_customer_contacts(): nonlocal customer_contacts customer_contacts = \ @@ -758,6 +763,7 @@ def extract_ims_data(): with concurrent.futures.ThreadPoolExecutor() as executor: futures = { executor.submit(_populate_locations): 'locations', + executor.submit(_populate_geant_nodes): 'geant_nodes', executor.submit(_populate_lg_routers): 'lg_routers', executor.submit(_populate_customer_contacts): 'customer_contacts', executor.submit(_populate_circuit_ids_to_monitor): @@ -815,7 +821,8 @@ def extract_ims_data(): 'additional_circuit_customer_ids': additional_circuit_customer_ids, 'hierarchy': hierarchy, 'port_id_details': port_id_details, - 'port_id_services': port_id_services + 'port_id_services': port_id_services, + 'geant_nodes': geant_nodes } @@ -828,6 +835,7 @@ def transform_ims_data(data): port_id_details = data['port_id_details'] port_id_services = data['port_id_services'] circuit_ids_and_sids = data['circuit_ids_sids'] + geant_nodes = data['geant_nodes'] sid_services = defaultdict(list) @@ -992,11 +1000,12 @@ def transform_ims_data(data): f"{circ['equipment']}/{circ['other_end_equipment']}" ][circ['id']] = circ - if circ['id'] in circuit_ids_and_sids: + if circ['id'] in circuit_ids_and_sids \ + and circ['status'] == 'operational': sid = circuit_ids_and_sids[circ['id']] if circ['circuit_type'] == 'circuit': logger.info(f'SID ({sid}) Circuit ({circ["id"]})' - f' not a service. IMS') + f' Name ({circ["name"]}) not a service') else: sid_info = { 'circuit_id': circ['id'], @@ -1007,7 +1016,8 @@ def transform_ims_data(data): 'project': circ['project'], 'customer': circ['customer'], 'equipment': circ['equipment'], - 'port': circ['port'] + 'port': circ['port'], + 'geant_equipment': circ['equipment'] in geant_nodes } if sid_info not in sid_services[sid]: sid_services[sid].append(sid_info) diff --git a/test/test_worker.py b/test/test_worker.py index a70b22b1e2fba14f3ce65a491e30ec3b6f5783e2..7b75b400c18418ae8d0d65f729ba5db3f9132cd9 100644 --- a/test/test_worker.py +++ b/test/test_worker.py @@ -64,6 +64,10 @@ def test_extract_ims_data(mocker): (111113, 'SID-03') ]) ) + mocker.patch( + 'inventory_provider.tasks.worker.ims_data.lookup_geant_nodes', + return_value=[] + ) 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'] @@ -295,12 +299,13 @@ def test_transform_ims_data(): data = { "locations": locations, "customer_contacts": customer_contacts, - "circuit_ids_to_monitor": [], + "circuit_ids_to_monitor": ["sub_circuit_2"], "additional_circuit_customer_ids": additional_circuit_customer_ids, "hierarchy": hierarchy, "port_id_details": port_id_details, "port_id_services": port_id_services, - "circuit_ids_sids": circuit_ids_and_sids + "circuit_ids_sids": circuit_ids_and_sids, + "geant_nodes": ["eq_b"] } res = transform_ims_data(data) ifs = res["interface_services"] @@ -337,7 +342,8 @@ def test_transform_ims_data(): 'project': "customer_1", 'customer': "customer_1", 'equipment': "eq_a", - 'port': "if_c" + 'port': "if_c", + 'geant_equipment': False }, { 'circuit_id': "sub_circuit_2", @@ -348,7 +354,8 @@ def test_transform_ims_data(): 'project': "customer_1", 'customer': "customer_1", 'equipment': "eq_b", - 'port': "if_c" + 'port': "if_c", + 'geant_equipment': True } ]: assert json.dumps(x, sort_keys=True) in [ @@ -404,6 +411,7 @@ def test_persist_ims_data(mocker, data_config, mocked_redis): }, "sid_services": {"SID-001": [{"k1": "data"}, {"k1": "data"}]}, "services_by_type": {}, + "geant_nodes": [] } for k in r.keys("ims:*"): r.delete(k)