Browse Source

[2113] Construct the classes

Michal 'vorner' Vaner 12 years ago
parent
commit
22af769109

+ 13 - 8
src/bin/cfgmgr/plugins/datasrc_config_plugin.py

@@ -16,6 +16,7 @@
 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
 spec = module_spec_from_file(path_search('datasrc.spec', PLUGIN_PATHS))
 
 def check(config):
@@ -26,14 +27,18 @@ def check(config):
     errors=[]
     if not spec.validate_config(False, config, errors):
         return ' '.join(errors)
-    # TODO: Once we have solved ticket #2051, create the list and
-    # fill it with the configuration. We probably want to have some way
-    # to not load the data sources, just the configuration. It could
-    # be hacked together by subclassing ConfigurableClientList and
-    # having empty getDataSource method. But it looks like a hack and it
-    # won't really check the params configuration.
-    #
-    # For now, we let everything pass.
+
+    classes = config.get('classes')
+    # Nothing passed here
+    if classes is None:
+        return None
+
+    for rr_class_str in classes:
+        try:
+            rr_class = isc.dns.RRClass(rr_class_str)
+        except isc.dns.InvalidRRClass as irc:
+            return str(irc)
+
     return None
 
 def load():

+ 13 - 3
src/bin/cfgmgr/plugins/tests/datasrc_test.py

@@ -26,14 +26,14 @@ class DatasrcTest(unittest.TestCase):
         """
         Just a shortcut to check the config is rejected.
         """
-        self.assertIsNotNone(datasrc_config_plugin.check({"datasources":
+        self.assertIsNotNone(datasrc_config_plugin.check({"classes":
                                                          config}))
 
     def accept(self, config):
         """
         Just a shortcut to check the config is accepted.
         """
-        self.assertIsNone(datasrc_config_plugin.check({"datasources":
+        self.assertIsNone(datasrc_config_plugin.check({"classes":
                                                       config}))
 
     def test_load(self):
@@ -50,7 +50,7 @@ class DatasrcTest(unittest.TestCase):
         """
         Check an empty input is OK.
         """
-        self.assertIsNone(datasrc_config_plugin.check({}))
+        self.accept({})
 
     def test_invalid_spec(self):
         """
@@ -63,5 +63,15 @@ class DatasrcTest(unittest.TestCase):
         self.reject({"IN": {}})
         self.reject({"IN": [{"bad-name": True}]})
 
+    def test_class(self):
+        """
+        The class is rejected, if it is wrong.
+        """
+        self.reject({"BAD": []})
+        self.reject({"": []})
+        # But with a good one, it works
+        for c in ["IN", "CH", "HS"]:
+            self.accept({c: []})
+
 if __name__ == '__main__':
         unittest.main()