Browse Source

[trac670] The config handler

Michal 'vorner' Vaner 14 years ago
parent
commit
cf5b24f110
2 changed files with 21 additions and 11 deletions
  1. 7 6
      src/bin/zonemgr/tests/zonemgr_test.py
  2. 14 5
      src/bin/zonemgr/zonemgr.py.in

+ 7 - 6
src/bin/zonemgr/tests/zonemgr_test.py

@@ -507,8 +507,8 @@ class MyZonemgr(Zonemgr):
         self._cc = MySession()
         self._module_cc = MyCCSession()
         self._config_data = {
-                    "lowerbound_refresh" : 10, 
-                    "lowerbound_retry" : 5, 
+                    "lowerbound_refresh" : 10,
+                    "lowerbound_retry" : 5,
                     "max_transfer_timeout" : 14400,
                     "jitter_scope" : 0.1,
                     "secondary_zones": []
@@ -524,13 +524,14 @@ class TestZonemgr(unittest.TestCase):
 
     def test_config_handler(self):
         config_data1 = {
-                    "lowerbound_refresh" : 60, 
-                    "lowerbound_retry" : 30, 
+                    "lowerbound_refresh" : 60,
+                    "lowerbound_retry" : 30,
                     "max_transfer_timeout" : 14400,
                     "jitter_scope" : 0.1,
                     "secondary_zones": []
                     }
-        self.zonemgr.config_handler(config_data1)
+        self.assertEqual(self.zonemgr.config_handler(config_data1),
+                         {"result": [0]})
         self.assertEqual(config_data1, self.zonemgr._config_data)
         config_data2 = {"zone_name" : "sd.cn.", "port" : "53", "master" : "192.168.1.1"}
         self.zonemgr.config_handler(config_data2)
@@ -551,7 +552,7 @@ class TestZonemgr(unittest.TestCase):
 
     def test_get_db_file(self):
         self.assertEqual("initdb.file", self.zonemgr.get_db_file())
-    
+
     def test_parse_cmd_params(self):
         params1 = {"zone_name" : "org.cn", "zone_class" : "CH", "master" : "127.0.0.1"}
         answer1 = (("org.cn", "CH"), "127.0.0.1")

+ 14 - 5
src/bin/zonemgr/zonemgr.py.in

@@ -490,15 +490,24 @@ class Zonemgr:
     def config_handler(self, new_config):
         """ Update config data. """
         answer = create_answer(0)
+        ok = True
+        complete = copy.copy(self._config_data)
         for key in new_config:
-            if key not in self._config_data:
+            if key not in complete:
                 answer = create_answer(1, "Unknown config data: " + str(key))
+                ok = False
                 continue
-            self._config_data[key] = new_config[key]
+            complete[key] = new_config[key]
 
-        self._config_data_check(self._config_data)
+        self._config_data_check(complete)
         if self._zone_refresh is not None:
-            self._zone_refresh.update_config_data(self._config_data)
+            try:
+                self._zone_refresh.update_config_data(complete)
+            except Exception as e:
+                answer = create_answer(1, str(e))
+                ok = False
+        if ok:
+            self._config_data = complete
 
         return answer
 
@@ -510,7 +519,7 @@ class Zonemgr:
         if config_data.get('jitter_scope') > 0.5:
             config_data['jitter_scope'] = 0.5
             log_msg("[b10-zonemgr] jitter_scope is too big, its value will "
-                      "be set to 0.5") 
+                      "be set to 0.5")
 
 
     def _parse_cmd_params(self, args, command):