[svn] commit: r880 - in /branches/jelte-configuration/src: bin/bind10/ lib/config/cpp/ lib/config/python/isc/config/

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Feb 19 10:28:25 UTC 2010


Author: jelte
Date: Fri Feb 19 10:28:24 2010
New Revision: 880

Log:
moduleccsession now validates config updates before calling the provided config_handler
renamed validate() to validate_config() (plan on adding validate_command() as well)
added createAnswer function in cpp version

Modified:
    branches/jelte-configuration/src/bin/bind10/bind10.py.in
    branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
    branches/jelte-configuration/src/lib/config/cpp/ccsession.h
    branches/jelte-configuration/src/lib/config/cpp/module_spec.cc
    branches/jelte-configuration/src/lib/config/cpp/module_spec.h
    branches/jelte-configuration/src/lib/config/cpp/module_spec_unittests.cc
    branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py
    branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py
    branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py
    branches/jelte-configuration/src/lib/config/python/isc/config/module_spec_test.py

Modified: branches/jelte-configuration/src/bin/bind10/bind10.py.in
==============================================================================
--- branches/jelte-configuration/src/bin/bind10/bind10.py.in (original)
+++ branches/jelte-configuration/src/bin/bind10/bind10.py.in Fri Feb 19 10:28:24 2010
@@ -115,15 +115,7 @@
         if self.verbose:
             print("[XX] handling new config:")
             print(new_config)
-        errors = []
-        if self.ccs.get_module_spec().validate(False, new_config, errors):
-            self.ccs.set_local_config(new_config)
-            answer = isc.config.ccsession.create_answer(0)
-        else:
-            if len(errors) > 0:
-                answer = isc.config.ccsession.create_answer(1, " ".join(errors))
-            else:
-                answer = isc.config.ccsession.create_answer(1, "Unknown error in validation")
+        answer = isc.config.ccsession.create_answer(0)
         return answer
         # TODO
 

Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.cc Fri Feb 19 10:28:24 2010
@@ -49,6 +49,26 @@
 
 namespace isc {
 namespace config {
+
+ElementPtr
+create_answer(const int rcode, const ElementPtr arg)
+{
+    ElementPtr answer = Element::createFromString("{\"result\": []");
+    ElementPtr answer_content = answer->get("result");
+    answer_content->add(Element::create(rcode));
+    answer_content->add(arg);
+    return answer;
+}
+
+ElementPtr
+create_answer(const int rcode, const std::string& arg)
+{
+    ElementPtr answer = Element::createFromString("{\"result\": []");
+    ElementPtr answer_content = answer->get("result");
+    answer_content->add(Element::create(rcode));
+    answer_content->add(Element::create(arg));
+    return answer;
+}
 
 void
 ModuleCCSession::read_module_specification(const std::string& filename) {
@@ -136,11 +156,14 @@
         cout << "[XX] got something!" << endl << data->str() << endl;
         ElementPtr answer;
         if (data->contains("config_update")) {
-            if (config_handler_) {
+            ElementPtr new_config = data->get("config_update");
+            if (!config_handler_) {
+                answer = create_answer(1, module_name_ + " does not have a config handler");
+            } else if (!module_specification_.validate_config(new_config)) {
+                answer = create_answer(2, "Error in config validation");
+            } else {
                 // handle config update
-                answer = config_handler_(data->get("config_update"));
-            } else {
-                answer = Element::createFromString("{ \"result\": [0] }");
+                answer = config_handler_(new_config);
             }
         }
         if (data->contains("command")) {

Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.h Fri Feb 19 10:28:24 2010
@@ -85,6 +85,9 @@
     isc::data::ElementPtr(*command_handler_)(isc::data::ElementPtr command);
 };
 
+ElementPtr createAnswer(const int rcode, const ElementPtr arg);
+ElementPtr createAnswer(const int rcode, const std::string arg);
+
 }
 }
 #endif // __CCSESSION_H

Modified: branches/jelte-configuration/src/lib/config/cpp/module_spec.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/module_spec.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/module_spec.cc Fri Feb 19 10:28:24 2010
@@ -209,7 +209,7 @@
 }
 
 bool
-ModuleSpec::validate(const ElementPtr data)
+ModuleSpec::validate_config(const ElementPtr data)
 {
     ElementPtr spec = module_specification->find("module_spec/config_data");
     return validate_spec_list(spec, data);

Modified: branches/jelte-configuration/src/lib/config/cpp/module_spec.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/module_spec.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/module_spec.h Fri Feb 19 10:28:24 2010
@@ -83,7 +83,7 @@
         /// \param data The base \c Element of the data to check
         /// \return true if the data conforms to the specification,
         /// false otherwise.
-        bool validate(const ElementPtr data);
+        bool validate_config(const ElementPtr data);
 
     private:
         bool validate_item(const ElementPtr spec, const ElementPtr data);

Modified: branches/jelte-configuration/src/lib/config/cpp/module_spec_unittests.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/module_spec_unittests.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/module_spec_unittests.cc Fri Feb 19 10:28:24 2010
@@ -129,7 +129,7 @@
     ElementPtr data = Element::createFromString(data_file, data_file_name);
     data_file.close();
 
-    return dd.validate(data);
+    return dd.validate_config(data);
 }
 
 TEST(ModuleSpec, DataValidation) {

Modified: branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py Fri Feb 19 10:28:24 2010
@@ -135,8 +135,15 @@
         if msg:
             answer = None
             try:
-                if "config_update" in msg and self._config_handler:
-                    answer = self._config_handler(msg["config_update"])
+                if "config_update" in msg:
+                    new_config = msg["config_update"]
+                    errors = []
+                    if not self._config_handler:
+                        answer = create_answer(2, self._module_name + " has no config handler")
+                    elif not self.get_module_spec().validate_config(False, new_config, errors):
+                        answer = create_answer(1, " ".join(errors))
+                    else:
+                        answer = self._config_handler(msg["config_update"])
                 if "command" in msg and self._command_handler:
                     answer = self._command_handler(msg["command"])
             except Exception as exc:
@@ -168,7 +175,7 @@
         answer, env = self._session.group_recvmsg(False)
         rcode, value = parse_answer(answer)
         if rcode == 0:
-            if value != None and self.get_module_spec().validate(False, value):
+            if value != None and self.get_module_spec().validate_config(False, value):
                 self.set_local_config(value);
                 if self._config_handler:
                     self._config_handler(value)

Modified: branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py Fri Feb 19 10:28:24 2010
@@ -27,7 +27,8 @@
 
 def check_type(spec_part, value):
     """Returns true if the value is of the correct type given the
-       specification part relevant for the value"""
+       specification part relevant for the value. spec_part can be
+       retrieved with find_spec()"""
     if type(spec_part) == list:
         data_type = "list"
     else:

Modified: branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py Fri Feb 19 10:28:24 2010
@@ -64,7 +64,7 @@
             _check(module_spec)
         self._module_spec = module_spec
 
-    def validate(self, full, data, errors = None):
+    def validate_config(self, full, data, errors = None):
         """Check whether the given piece of data conforms to this
            data definition. If so, it returns True. If not, it will
            return false. If errors is given, and is an array, a string

Modified: branches/jelte-configuration/src/lib/config/python/isc/config/module_spec_test.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/module_spec_test.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/module_spec_test.py Fri Feb 19 10:28:24 2010
@@ -76,7 +76,7 @@
         data_file = open(self.spec_file(datafile_name))
         data_str = data_file.read()
         data = isc.cc.data.parse_value_str(data_str)
-        return dd.validate(True, data)
+        return dd.validate_config(True, data)
         
     def test_data_validation(self):
         self.assertEqual(True, self.validate_data("spec22.spec", "data22_1.data"))




More information about the bind10-changes mailing list