From f94d19f494e02b1353f9b3a2626a1259b8250ebe Mon Sep 17 00:00:00 2001
From: Pelle Koster <pelle.koster@geant.org>
Date: Wed, 24 Apr 2024 07:30:39 +0000
Subject: [PATCH] Convert Nokia SNMP index to integer

---
 inventory_provider/nokia.py |  2 +-
 test/test_nokia.py          | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/inventory_provider/nokia.py b/inventory_provider/nokia.py
index 640adaba..2a0af547 100644
--- a/inventory_provider/nokia.py
+++ b/inventory_provider/nokia.py
@@ -154,7 +154,7 @@ def get_interfaces_state(state_doc):
     for interface_ in interfaces:
         details = {
             "interface-name": interface_.find('s:interface-name', namespaces=NS).text,
-            "if-index": interface_.find('s:if-index', namespaces=NS).text,
+            "if-index": int(interface_.find('s:if-index', namespaces=NS).text),
             "oper-state": interface_.find('s:oper-state', namespaces=NS).text,
         }
         ipv4 = interface_.find('s:ipv4', namespaces=NS)
diff --git a/test/test_nokia.py b/test/test_nokia.py
index a55f331d..b4302c09 100644
--- a/test/test_nokia.py
+++ b/test/test_nokia.py
@@ -73,3 +73,18 @@ def test_get_interface_state():
     expected_up_interfaces = {'system', 'lag-2.0', 'guy', 'exfo400-100', 'management'}
     assert {k for k, v in interfaces.items() if
             v['oper-state'] == 'up'} == expected_up_interfaces
+
+
+def test_snmp_index():
+    interfaces = get_interfaces_state(state_doc)
+    expected = {
+        "system": 1,
+        "lag-1.0": 2,
+        "lag-2.0": 3,
+        "lag-3.0": 4,
+        "exfo400": 5,
+        "guy": 6,
+        "exfo400-100": 7,
+        "management": 1280,
+    }
+    assert {ifc["interface-name"]: ifc["if-index"] for ifc in interfaces} == expected
-- 
GitLab