From 447ac04d113ea33e32fde81551f7a13e55083d80 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Thu, 7 Feb 2019 19:54:56 +0100
Subject: [PATCH] add schema + validation for vpn rr peer list

---
 test/per_router/test_ix_public_peers.py | 46 ++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git a/test/per_router/test_ix_public_peers.py b/test/per_router/test_ix_public_peers.py
index abeb8f75..f282084c 100644
--- a/test/per_router/test_ix_public_peers.py
+++ b/test/per_router/test_ix_public_peers.py
@@ -12,15 +12,12 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join(
     'test',
     'data'))
 
-# ROUTER_NAME = 'mx1.vie.at.geant.net'
-ROUTER_NAME = 'mx2.lju.si.geant.net'
-
 
 @pytest.fixture
 def netconf(router):
     netconf_filename = os.path.join(
         TEST_DATA_DIRNAME,
-        ROUTER_NAME + '-netconf.xml')
+        router + '-netconf.xml')
     doc = etree.parse(netconf_filename)
     juniper.validate_netconf_config(doc)
     return doc
@@ -31,15 +28,19 @@ def test_ix_public_peers(netconf):
     schema = {
         "$schema": "http://json-schema.org/draft-07/schema#",
 
-        "type": "object",
-        "properties": {
-            "name": {
+        "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"},
             "as": {
                 "type": "object",
@@ -55,11 +56,38 @@ def test_ix_public_peers(netconf):
         "additionalProperties": False
     }
 
+    print("HERE123")
     for p in juniper.ix_public_peers(netconf):
         jsonschema.validate(p, schema)
         print(p)
 
 def test_vpn_rr_peers(netconf):
+
+    # there are actually no v6 addresses, pattern could be ommitted
+    # TODO: check if there's a robust justification for this
+    schema = {
+        "$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
+    }
+
     for p in juniper.vpn_rr_peers(netconf):
+        jsonschema.validate(p, schema)
         print(p)
-        # jsonschema.validate(p, schema)
-- 
GitLab