From 0cde7cae39b986c44802868927bac160a8a75241 Mon Sep 17 00:00:00 2001
From: Robert Latta <robert.latta@geant.org>
Date: Fri, 9 Sep 2022 10:30:49 +0100
Subject: [PATCH] added flexILS data retrieval

---
 inventory_provider/db/ims_data.py | 10 +++++
 test/test_ims_data.py             | 63 ++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py
index 36167cb3..0851fa3e 100644
--- a/inventory_provider/db/ims_data.py
+++ b/inventory_provider/db/ims_data.py
@@ -67,6 +67,16 @@ NODE_LOCATION_SCHEMA = {
 }
 
 
+def get_flex_ils_entities(ds: IMS):
+    for f in ds.get_all_entities('FLEXILS_SCHF_SUBINTERFACES'):
+        yield {
+            'circuit_id': f['circuitid'],
+            'node_name': f['nodename'],
+            'port_name': f['port'],
+            'full_port_name': f['port_ref']
+        }
+
+
 def get_non_monitored_circuit_ids(ds: IMS):
     # note the id for the relevant field is hard-coded. I didn't want to use
     # the name of the field as this can be changed by users
diff --git a/test/test_ims_data.py b/test/test_ims_data.py
index a84590d6..320e847a 100644
--- a/test/test_ims_data.py
+++ b/test/test_ims_data.py
@@ -8,7 +8,8 @@ from inventory_provider.db.ims import InventoryStatus
 from inventory_provider.db.ims_data import lookup_lg_routers, \
     get_node_locations, IMS_OPSDB_STATUS_MAP, \
     get_port_id_services, get_port_details, \
-    get_circuit_hierarchy, get_ids_and_sids, NODE_LOCATION_SCHEMA
+    get_circuit_hierarchy, get_ids_and_sids, NODE_LOCATION_SCHEMA, \
+    get_flex_ils_entities
 
 
 def _json_test_data(filename):
@@ -385,3 +386,63 @@ def test_get_circuit_ids_and_sids(mocker):
         'dummy_base', 'dummy_username', 'dummy_password')
     res = list(get_ids_and_sids(ds))
     assert res == expected_response
+
+
+def test_get_flex_ils_entities(mocker):
+    ims = mocker.patch('inventory_provider.db.ims.IMS')
+    ims.return_value.get_all_entities.return_value = \
+        [
+            {
+                "$id": "1630",
+                "circuitid": 702203,
+                "circuitname": "GEANT LAB-GEANT LAB-OCH-003",
+                "id": 1,
+                "nodename": "CAM01-MTC6-3",
+                "node_id": 130498,
+                "port": "A-1-S1",
+                "port_ref": "1-A-1-S1-1",
+                "shelfname": "1-MTC-6",
+                "rowVersion": "0001-01-01T00:00:00",
+                "circuit": None,
+                "node_": None,
+                "errors": None,
+                "haserrors": False,
+                "customproperties": {}
+            },
+            {
+                "$id": "1631",
+                "circuitid": 702203,
+                "circuitname": "GEANT LAB-GEANT LAB-OCH-003",
+                "id": 2,
+                "nodename": "CAM01-MTC6-3",
+                "node_id": 130498,
+                "port": "A-1-L1",
+                "port_ref": "1-A-1-L1-1",
+                "shelfname": "1-MTC-6",
+                "rowversion": "0001-01-01T00:00:00",
+                "circuit": None,
+                "node_": None,
+                "errors": None,
+                "haserrors": False,
+                "customproperties": {}
+            }
+        ]
+    expected_result = [
+        {
+            'circuit_id': 702203,
+            'node_name': 'CAM01-MTC6-3',
+            'port_name': 'A-1-S1',
+            'full_port_name': '1-A-1-S1-1'
+        },
+        {
+            'circuit_id': 702203,
+            'node_name': 'CAM01-MTC6-3',
+            'port_name': 'A-1-L1',
+            'full_port_name': '1-A-1-L1-1'
+        }
+    ]
+
+    ds = inventory_provider.db.ims.IMS(
+        'dummy_base', 'dummy_username', 'dummy_password')
+    res = list(get_flex_ils_entities(ds))
+    assert res == expected_result
-- 
GitLab