From cc5a5598defeac9d4ab8b305b3f2441084b476ac Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Thu, 27 Jun 2019 16:49:19 +0200
Subject: [PATCH] fixed unit test to support new snmp cache info

---
 inventory_provider/snmp.py | 16 ++--------
 test/test_snmp_handling.py | 61 ++++----------------------------------
 2 files changed, 9 insertions(+), 68 deletions(-)

diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py
index e7cc25a4..b8ee1f85 100644
--- a/inventory_provider/snmp.py
+++ b/inventory_provider/snmp.py
@@ -7,17 +7,8 @@ from pysnmp.smi import builder, compiler
 # from pysnmp.smi import view, rfc1902
 
 
-OID_LIST = {
-    ## IPv4
-    'v4Address': '.1.3.6.1.2.1.4.20.1.1',
-    'v4InterfaceOID': '.1.3.6.1.2.1.4.20.1.2',
-    'v4InterfaceName': '.1.3.6.1.2.1.31.1.1.1.1',
-    'v4Mask': '.1.3.6.1.2.1.4.20.1.3',
-
-    ## IPv6
-    'v6AddressAndMask' '.1.3.6.1.2.1.55.1.8.1.2'
-    'v6InterfaceName': '.1.3.6.1.2.1.55.1.5.1.2'
-}
+RFC1213_MIB_IFDESC = '1.3.6.1.2.1.2.2.1.2'
+
 
 def _v6address_oid2str(dotted_decimal):
     hex_params = []
@@ -92,8 +83,7 @@ def walk(agent_hostname, community, base_oid):  # pragma: no cover
 
 def get_router_snmp_indexes(hostname, community):
     indexes = {}
-    RFC1213_MIB_ifDesc = '1.3.6.1.2.1.2.2.1.2'
-    for ifc in walk(hostname, community, RFC1213_MIB_ifDesc):
+    for ifc in walk(hostname, community, RFC1213_MIB_IFDESC):
         m = re.match(r'.*\.(\d+)$', ifc['oid'])
         assert m, 'sanity failure parsing oid: %r' % ifc['oid']
         indexes[ifc['value']] = int(m.group(1))
diff --git a/test/test_snmp_handling.py b/test/test_snmp_handling.py
index 08485456..a0a07b4c 100644
--- a/test/test_snmp_handling.py
+++ b/test/test_snmp_handling.py
@@ -26,71 +26,22 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
 
     expected_result_schema = {
         "$schema": "http://json-schema.org/draft-07/schema#",
-
-        "definitions": {
-            "v4ifc": {
-                "type": "object",
-                "properties": {
-                    "v4Address": {
-                        "type": "string",
-                        "pattern": r'^(\d+\.){3}\d+$'
-                    },
-                    "v4Mask": {
-                        "type": "string",
-                        "pattern": r'^(\d+\.){3}\d+$'
-                    },
-                    "v4InterfaceName": {"type": "string"},
-                    "index": {
-                        "type": "string",
-                        "pattern": r'^\d+$'
-                    }
-                },
-                "required": [
-                    "v4Address", "v4Mask", "v4InterfaceName", "index"],
-                "additionalProperties": False
-            },
-            "v6ifc": {
-                "type": "object",
-                "properties": {
-                    "v6Address": {
-                        "type": "string",
-                        "pattern": r'^[a-f\d:]+$'
-                    },
-                    "v6Mask": {
-                        "type": "string",
-                        "pattern": r'^\d+$'
-                    },
-                    "v6InterfaceName": {"type": "string"},
-                    "index": {
-                        "type": "string",
-                        "pattern": r'^\d+$'
-                    }
-                },
-                "required": [
-                    "v6Address", "v6Mask", "v6InterfaceName", "index"],
-                "additionalProperties": False
-            }
-        },
-
         "type": "array",
         "items": {
-            "anyOf": [
-                {"$ref": "#/definitions/v4ifc"},
-                {"$ref": "#/definitions/v6ifc"}
-            ]
+            "name": {"type": "string"},
+            "index": {"type": "integer"}
         }
     }
 
-    def _mocked_walk(agent_hostname, community, base_oid):
-        return [e for e in snmp_walk_responses
-                if e['oid'].startswith(base_oid)]
+    def _mocked_walk(agent_hostname, community, ignored_oid):
+        return snmp_walk_responses
 
     mocker.patch(
         'inventory_provider.snmp.walk',
         _mocked_walk)
 
-    interfaces = snmp.get_router_interfaces(
-        'ignored', 'ignored', {'oids': data_config['oids']})
+    interfaces = snmp.get_router_snmp_indexes(
+        'ignored', 'ignored')
     interfaces = list(interfaces)
 
     jsonschema.validate(interfaces, expected_result_schema)
-- 
GitLab