From 11adfda0d34a7a01aad640536488ae3c0183e0c9 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sun, 10 Feb 2019 10:20:49 +0100
Subject: [PATCH] fixed & debugged snmp redis data format schema

---
 README.md                  | 62 +++++++++-----------------------
 test/test_snmp_handling.py | 74 ++++++++++++++++++++++++++------------
 2 files changed, 67 insertions(+), 69 deletions(-)

diff --git a/README.md b/README.md
index 0314e0e5..be345ee3 100644
--- a/README.md
+++ b/README.md
@@ -458,20 +458,20 @@ Any non-empty responses are JSON formatted messages.
                 "properties": {
                     "v4Address": {
                         "type": "string",
-                        "pattern": "^(\d+\.){3}\d+$"
+                        "pattern": r'^(\d+\.){3}\d+$'
                     },
                     "v4Mask": {
                         "type": "string",
-                        "pattern": "^(\d+\.){3}\d+$"
+                        "pattern": r'^(\d+\.){3}\d+$'
                     },
-                    "v4InterfaceName": {:"type", "string"},
-                    "index": {`
+                    "v4InterfaceName": {"type": "string"},
+                    "index": {
                         "type": "string",
-                        "pattern": "^\d+$"
+                        "pattern": r'^\d+$'
                     }
                 },
                 "required": [
-                    "v4Address", "v4Mask", "v4InterfaceName", "index],
+                    "v4Address", "v4Mask", "v4InterfaceName", "index"],
                 "additionalProperties": False
             },
             "v6ifc": {
@@ -479,30 +479,30 @@ Any non-empty responses are JSON formatted messages.
                 "properties": {
                     "v6Address": {
                         "type": "string",
-                        "pattern": "^[\d:]+$"
+                        "pattern": r'^[a-f\d:]+$'
                     },
                     "v6Mask": {
                         "type": "string",
-                        "pattern": "^\d+$"
+                        "pattern": r'^\d+$'
                     },
-                    "v6InterfaceName": {:"type", "string"},
-                    "index": {`
+                    "v6InterfaceName": {"type": "string"},
+                    "index": {
                         "type": "string",
-                        "pattern": "^\d+$"
+                        "pattern": r'^\d+$'
                     }
                 },
                 "required": [
-                    "v6Address", "v6Mask", "v6InterfaceName", "index],
+                    "v6Address", "v6Mask", "v6InterfaceName", "index"],
                 "additionalProperties": False
             }
         },
 
         "type": "array",
          "items": {
-            "anyOf": {
-                "$ref": "#/definitions/v4Ifc",
-                "$ref": "#/definitions/v6Ifc"
-            }
+            "anyOf": [
+                {"$ref": "#/definitions/v4ifc"},
+                {"$ref": "#/definitions/v6ifc"}
+            ]
         }
     }
     ```
@@ -744,33 +744,3 @@ Any non-empty responses are JSON formatted messages.
         "additionalProperties": False
     }
     ```
-
-
-* `vpn_rr_peers/<address>`
-  * key examples
-    * `ix_public_peer:193.203.0.203`
-  * valid values:
-    ```json
-    {
-        "$schema": "http://json-schema.org/draft-07/schema#",
-
-        "definitions": {
-            "ip-address": {
-                "type": "string",
-                "oneOf": [
-                    {"pattern": r'^(\d+\.){3}\d+$'},
-                    {"pattern": r'^([a-f\d]{4}:){7}[a-f\d]{4}$'}
-                ]
-            }
-        },
-
-        "type": "object",
-        "properties": {
-            "name": {"$ref": "#/definitions/ip-address"},
-            "description": {"type": "string"},
-            "peer-as": {"type": "integer"}
-        },
-        "required": ["name", "description"],
-        "additionalProperties": False
-    }
-    ```
diff --git a/test/test_snmp_handling.py b/test/test_snmp_handling.py
index f8138a68..d1698440 100644
--- a/test/test_snmp_handling.py
+++ b/test/test_snmp_handling.py
@@ -26,20 +26,58 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
 
     expected_result_schema = {
         "$schema": "http://json-schema.org/draft-07/schema#",
-        "type": "array",
-        "items": {
-            "type": "object",
-            "properties": {
-                "v4Address": {"type": "string"},
-                "v4Mask": {"type": "string"},
-                "v4InterfaceName": {"type": "string"},
-                "v6Address": {"type": "string"},
-                "v6Mask": {"type": "string"},
-                "v6InterfaceName": {"type": "string"},
-                "index": {"type": "string"}
+
+        "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
             },
-            "required": ["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"}
+            ]
         }
     }
 
@@ -57,13 +95,3 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
 
     jsonschema.validate(interfaces, expected_result_schema)
     assert interfaces, "interface list isn't empty"
-    for ifc in interfaces:
-        if 'v4Address' in ifc \
-                and 'v4Mask' in ifc \
-                and 'v4InterfaceName' in ifc:
-            continue
-        if 'v6Address' in ifc \
-                and 'v6Mask' in ifc \
-                and 'v6InterfaceName' in ifc:
-            continue
-        assert False, "address details not found in interface dict"
-- 
GitLab