From ee3895fee162efe41845a55abdac0f1f0823b2eb Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 18 Aug 2023 10:26:46 -0500 Subject: [PATCH 1/6] Add some schema validation tests for new port definitions --- tests/test_schemas.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 85556fa..6681e18 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -78,6 +78,38 @@ def test_port_schema(self): self._read_schema(self.PORT_SCHEMA_FILE), ) + def test_port_schema_l2vpn_p2p(self): + jsonschema.validate( + self._read_json(TestData.PORT_FILE_L2VPN_PTP), + self._read_schema(self.PORT_SCHEMA_FILE), + ) + + def test_port_schema_l2vpn_p2p_invalid(self): + self.assertRaises( + json.decoder.JSONDecodeError, + self._read_json, + TestData.PORT_FILE_L2VPN_PTP_INVALID, + ) + + def test_port_schema_l2vpn_p2p_bad_range(self): + jsonschema.validate( + self._read_json(TestData.PORT_FILE_L2VPN_PTP_BAD_RANGE), + self._read_schema(self.PORT_SCHEMA_FILE), + ) + + def test_port_schema_l2vpn_p2p_ptmp(self): + jsonschema.validate( + self._read_json(TestData.PORT_FILE_L2VPN_PTP_PTMP), + self._read_schema(self.PORT_SCHEMA_FILE), + ) + + def test_port_schema_l2vpn_p2p_ptmp_invalid(self): + self.assertRaises( + json.decoder.JSONDecodeError, + self._read_json, + TestData.PORT_FILE_L2VPN_PTP_PTMP_INVALID, + ) + def test_service_schema(self): jsonschema.validate( self._read_json(TestData.SERVICE_FILE), From b556ddb2714439dbbb3e97ca5dd14115eae75e39 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 18 Aug 2023 10:41:02 -0500 Subject: [PATCH 2/6] Port.nni must be a string --- schemas/Port.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/Port.json b/schemas/Port.json index 75f127f..b986936 100644 --- a/schemas/Port.json +++ b/schemas/Port.json @@ -19,7 +19,7 @@ "type": "string" }, "nni": { - "type": "boolean" + "type": "string" }, "type": { "type": "string", From 076870461559373095895479afb8a3b8e99e2b37 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 18 Aug 2023 10:44:22 -0500 Subject: [PATCH 3/6] Add a bare Port.services --- schemas/Port.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/schemas/Port.json b/schemas/Port.json index b986936..596f423 100644 --- a/schemas/Port.json +++ b/schemas/Port.json @@ -21,6 +21,9 @@ "nni": { "type": "string" }, + "services": { + "type": "object" + }, "type": { "type": "string", "enum": [ From 94a4bd76425399186990258a90c225ca4c187008 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 18 Aug 2023 15:43:57 -0500 Subject: [PATCH 4/6] Add l2vpn-p2p and l2vpn-pmtp services to Port --- schemas/Port.json | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/schemas/Port.json b/schemas/Port.json index 596f423..1cb3880 100644 --- a/schemas/Port.json +++ b/schemas/Port.json @@ -22,7 +22,35 @@ "type": "string" }, "services": { - "type": "object" + "type": "object", + "properties": { + "l2vpn-ptp": { + "type": "object", + "properties": { + "vlan_range": { + "type": "array", + "uniqueItems": true, + "items": [ + { + } + ] + } + } + }, + "l2vpn-pmtp": { + "type": "object", + "properties": { + "vlan_range": { + "type": "array", + "uniqueItems": true, + "items": [ + { + } + ] + } + } + } + } }, "type": { "type": "string", From 194864c8a3f603e9b5804502a1b12d6a64bb0b11 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 18 Aug 2023 16:10:54 -0500 Subject: [PATCH 5/6] Expand L2VPN types --- schemas/Port.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/schemas/Port.json b/schemas/Port.json index 1cb3880..0a79806 100644 --- a/schemas/Port.json +++ b/schemas/Port.json @@ -32,6 +32,21 @@ "uniqueItems": true, "items": [ { + "anyOf": [ + { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": [ + { + "type": "number" + } + ] + }, + { + "type": "number" + } + ] } ] } @@ -45,6 +60,21 @@ "uniqueItems": true, "items": [ { + "anyOf": [ + { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": [ + { + "type": "number" + } + ] + }, + { + "type": "number" + } + ] } ] } From 385d8b1e9d41c641c21bc5115c91494305bd16f9 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 18 Aug 2023 16:14:32 -0500 Subject: [PATCH 6/6] Give L2VPN its own separate schema --- schemas/L2VPN.json | 30 ++++++++++++++++++++++++++ schemas/Port.json | 52 ++-------------------------------------------- 2 files changed, 32 insertions(+), 50 deletions(-) create mode 100644 schemas/L2VPN.json diff --git a/schemas/L2VPN.json b/schemas/L2VPN.json new file mode 100644 index 0000000..7bac68e --- /dev/null +++ b/schemas/L2VPN.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "L2VPN", + "type": "object", + "properties": { + "vlan_range": { + "type": "array", + "uniqueItems": true, + "items": [ + { + "anyOf": [ + { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": [ + { + "type": "number" + } + ] + }, + { + "type": "number" + } + ] + } + ] + } + } +} diff --git a/schemas/Port.json b/schemas/Port.json index 0a79806..e875b00 100644 --- a/schemas/Port.json +++ b/schemas/Port.json @@ -26,59 +26,11 @@ "properties": { "l2vpn-ptp": { "type": "object", - "properties": { - "vlan_range": { - "type": "array", - "uniqueItems": true, - "items": [ - { - "anyOf": [ - { - "type": "array", - "minItems": 2, - "maxItems": 2, - "items": [ - { - "type": "number" - } - ] - }, - { - "type": "number" - } - ] - } - ] - } - } + "$ref": "L2VPN.json" }, "l2vpn-pmtp": { "type": "object", - "properties": { - "vlan_range": { - "type": "array", - "uniqueItems": true, - "items": [ - { - "anyOf": [ - { - "type": "array", - "minItems": 2, - "maxItems": 2, - "items": [ - { - "type": "number" - } - ] - }, - { - "type": "number" - } - ] - } - ] - } - } + "$ref": "L2VPN.json" } } },