Parcourir la source

[2113] Check the configuration by creating the list

A small bugfix in the validation is included. There's no test for it
directly - it is tested implicitly in the plugin test, but I wasn't able
to reproduce it on small test spec files. If we weren't planning for
replacement of the whole thing, it would need some investigation.
Michal 'vorner' Vaner il y a 12 ans
Parent
commit
e93f78639d

+ 9 - 0
src/bin/cfgmgr/plugins/datasrc_config_plugin.py

@@ -17,6 +17,8 @@ from isc.config.module_spec import module_spec_from_file
 from isc.util.file import path_search
 from bind10_config import PLUGIN_PATHS
 import isc.dns
+import isc.datasrc
+import json
 spec = module_spec_from_file(path_search('datasrc.spec', PLUGIN_PATHS))
 
 def check(config):
@@ -39,6 +41,13 @@ def check(config):
         except isc.dns.InvalidRRClass as irc:
             return str(irc)
 
+        dlist = isc.datasrc.ConfigurableClientList(rr_class)
+        try:
+            dlist.configure(json.dumps(classes.get(rr_class_str)),
+                            False)
+        except isc.datasrc.Error as dse:
+            return str(dse)
+
     return None
 
 def load():

+ 22 - 0
src/bin/cfgmgr/plugins/tests/datasrc_test.py

@@ -73,5 +73,27 @@ class DatasrcTest(unittest.TestCase):
         for c in ["IN", "CH", "HS"]:
             self.accept({c: []})
 
+    def test_mem_ok(self):
+        """
+        Test we accept an in-memory data source. It doesn't really matter
+        which one it is. We just want to make sure we accept something
+        and this one does not need any kind of path mangling to find
+        plugins.
+        """
+        self.accept({"IN": [{
+            "type": "MasterFiles",
+            "cache-enable": True,
+            "params": {}
+        }]})
+
+    def test_dstype_bad(self):
+        """
+        The configuration is correct by the spec, but it would be rejected
+        by the client list. Check we reject it.
+        """
+        self.reject({"IN": [{
+            "type": "No such type"
+        }]})
+
 if __name__ == '__main__':
         unittest.main()

+ 2 - 0
src/lib/python/isc/config/module_spec.py

@@ -386,6 +386,8 @@ def _validate_format(spec, value, errors):
     return True
 
 def _validate_item(spec, full, data, errors):
+    if spec.get('item_type') == 'any':
+        return True
     if not _validate_type(spec, data, errors):
         return False
     elif type(data) == list: