Browse Source

Merge pull request #5898 from docker/5884-ipam-config-schema

Clearly define IPAM config schema for validation
Joffrey F 7 years ago
parent
commit
3cf58705b7

+ 20 - 1
compose/config/config_schema_v2.0.json

@@ -281,7 +281,8 @@
             "properties": {
                 "driver": {"type": "string"},
                 "config": {
-                    "type": "array"
+                    "type": "array",
+                    "items": {"$ref": "#/definitions/ipam_config"}
                 },
                 "options": {
                   "type": "object",
@@ -305,6 +306,24 @@
       "additionalProperties": false
     },
 
+    "ipam_config": {
+      "id": "#/definitions/ipam_config",
+      "type": "object",
+      "properties": {
+        "subnet": {"type": "string"},
+        "iprange": {"type": "string"},
+        "gateway": {"type": "string"},
+        "aux_addresses": {
+          "type": "object",
+          "patternProperties": {
+            "^.+$": {"type": "string"}
+          },
+          "additionalProperties": false
+        }
+      },
+      "additionalProperties": false
+    },
+
     "volume": {
       "id": "#/definitions/volume",
       "type": ["object", "null"],

+ 20 - 1
compose/config/config_schema_v2.1.json

@@ -332,7 +332,8 @@
             "properties": {
                 "driver": {"type": "string"},
                 "config": {
-                    "type": "array"
+                    "type": "array",
+                    "items": {"$ref": "#/definitions/ipam_config"}
                 },
                 "options": {
                   "type": "object",
@@ -359,6 +360,24 @@
       "additionalProperties": false
     },
 
+    "ipam_config": {
+      "id": "#/definitions/ipam_config",
+      "type": "object",
+      "properties": {
+        "subnet": {"type": "string"},
+        "iprange": {"type": "string"},
+        "gateway": {"type": "string"},
+        "aux_addresses": {
+          "type": "object",
+          "patternProperties": {
+            "^.+$": {"type": "string"}
+          },
+          "additionalProperties": false
+        }
+      },
+      "additionalProperties": false
+    },
+
     "volume": {
       "id": "#/definitions/volume",
       "type": ["object", "null"],

+ 20 - 1
compose/config/config_schema_v2.2.json

@@ -341,7 +341,8 @@
             "properties": {
                 "driver": {"type": "string"},
                 "config": {
-                    "type": "array"
+                    "type": "array",
+                    "items": {"$ref": "#/definitions/ipam_config"}
                 },
                 "options": {
                   "type": "object",
@@ -368,6 +369,24 @@
       "additionalProperties": false
     },
 
+    "ipam_config": {
+      "id": "#/definitions/ipam_config",
+      "type": "object",
+      "properties": {
+        "subnet": {"type": "string"},
+        "iprange": {"type": "string"},
+        "gateway": {"type": "string"},
+        "aux_addresses": {
+          "type": "object",
+          "patternProperties": {
+            "^.+$": {"type": "string"}
+          },
+          "additionalProperties": false
+        }
+      },
+      "additionalProperties": false
+    },
+
     "volume": {
       "id": "#/definitions/volume",
       "type": ["object", "null"],

+ 20 - 1
compose/config/config_schema_v2.3.json

@@ -385,7 +385,8 @@
             "properties": {
                 "driver": {"type": "string"},
                 "config": {
-                    "type": "array"
+                    "type": "array",
+                    "items": {"$ref": "#/definitions/ipam_config"}
                 },
                 "options": {
                   "type": "object",
@@ -412,6 +413,24 @@
       "additionalProperties": false
     },
 
+    "ipam_config": {
+      "id": "#/definitions/ipam_config",
+      "type": "object",
+      "properties": {
+        "subnet": {"type": "string"},
+        "iprange": {"type": "string"},
+        "gateway": {"type": "string"},
+        "aux_addresses": {
+          "type": "object",
+          "patternProperties": {
+            "^.+$": {"type": "string"}
+          },
+          "additionalProperties": false
+        }
+      },
+      "additionalProperties": false
+    },
+
     "volume": {
       "id": "#/definitions/volume",
       "type": ["object", "null"],

+ 20 - 1
compose/config/config_schema_v2.4.json

@@ -384,7 +384,8 @@
             "properties": {
                 "driver": {"type": "string"},
                 "config": {
-                    "type": "array"
+                    "type": "array",
+                    "items": {"$ref": "#/definitions/ipam_config"}
                 },
                 "options": {
                   "type": "object",
@@ -411,6 +412,24 @@
       "additionalProperties": false
     },
 
+    "ipam_config": {
+      "id": "#/definitions/ipam_config",
+      "type": "object",
+      "properties": {
+        "subnet": {"type": "string"},
+        "iprange": {"type": "string"},
+        "gateway": {"type": "string"},
+        "aux_addresses": {
+          "type": "object",
+          "patternProperties": {
+            "^.+$": {"type": "string"}
+          },
+          "additionalProperties": false
+        }
+      },
+      "additionalProperties": false
+    },
+
     "volume": {
       "id": "#/definitions/volume",
       "type": ["object", "null"],

+ 22 - 0
tests/unit/config/config_test.py

@@ -1322,6 +1322,28 @@ class ConfigTest(unittest.TestCase):
         assert mount.type == 'bind'
         assert mount.source == expected_source
 
+    def test_config_invalid_ipam_config(self):
+        with pytest.raises(ConfigurationError) as excinfo:
+            config.load(
+                build_config_details(
+                    {
+                        'version': str(V2_1),
+                        'networks': {
+                            'foo': {
+                                'driver': 'default',
+                                'ipam': {
+                                    'driver': 'default',
+                                    'config': ['172.18.0.0/16'],
+                                }
+                            }
+                        }
+                    },
+                    filename='filename.yml',
+                )
+            )
+        assert ('networks.foo.ipam.config contains an invalid type,'
+                ' it should be an object') in excinfo.exconly()
+
     def test_config_valid_service_names(self):
         for valid_name in ['_', '-', '.__.', '_what-up.', 'what_.up----', 'whatup']:
             services = config.load(