Parcourir la source

merge #380, Remove duplicate code from _setup_session and config_handler
skip changelog entry


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@3302 e5f2f494-b856-4b98-b285-d166d9295462

Jerry il y a 14 ans
Parent
commit
f7c4d42008
2 fichiers modifiés avec 20 ajouts et 9 suppressions
  1. 9 0
      src/bin/zonemgr/tests/zonemgr_test.py
  2. 11 9
      src/bin/zonemgr/zonemgr.py.in

+ 9 - 0
src/bin/zonemgr/tests/zonemgr_test.py

@@ -506,6 +506,15 @@ class TestZonemgr(unittest.TestCase):
         params1 = {"zone_class" : "CH"}
         self.assertRaises(ZonemgrException, self.zonemgr._parse_cmd_params, params2, ZONE_NOTIFY_COMMAND)
 
+    def test_config_data_check(self):
+        # jitter should not be bigger than half of the original value
+        config_data2 = {"jitter_scope" : 0.2}
+        config_data3 = {"jitter_scope" : 0.6}
+        self.zonemgr._config_data_check(config_data2)
+        self.assertEqual(0.2, config_data2.get("jitter_scope"))
+        self.zonemgr._config_data_check(config_data3)
+        self.assertEqual(0.5, config_data3.get("jitter_scope"))
+
     def tearDown(self):
         pass
 

+ 11 - 9
src/bin/zonemgr/zonemgr.py.in

@@ -435,10 +435,7 @@ class Zonemgr:
                                                   self.command_handler)
         self._module_cc.add_remote_config(AUTH_SPECFILE_LOCATION)
         self._config_data = self._module_cc.get_full_config()
-        # jitter should not be bigger than half of the original value
-        if self._config_data.get('jitter_scope') > 0.5:
-            self._config_data['jitter_scope'] = 0.5
-            log_msg("[b10-zonemgr] jitter_scope should not be bigger than 0.5.") 
+        self._config_data_check(self._config_data)
         self._module_cc.start()
 
     def get_db_file(self):
@@ -468,18 +465,23 @@ class Zonemgr:
             if key not in self._config_data:
                 answer = create_answer(1, "Unknown config data: " + str(key))
                 continue
-            # jitter should not be bigger than half of the original value
-            if key == 'jitter_scope':
-                if new_config.get(key) > 0.5:
-                    new_config[key] = 0.5
-                    log_msg("[b10-zonemgr] jitter_scope should not be bigger than 0.5.") 
             self._config_data[key] = new_config[key]
 
+        self._config_data_check(self._config_data)
         if (self._zone_refresh):
             self._zone_refresh.update_config_data(self._config_data)
 
         return answer
 
+    def _config_data_check(self, config_data):
+        """Check whether the new config data is valid or 
+        not. """ 
+        # jitter should not be bigger than half of the original value
+        if config_data.get('jitter_scope') > 0.5:
+            config_data['jitter_scope'] = 0.5
+            log_msg("[b10-zonemgr] jitter_scope is too bigger, its value will "
+                      "be set to 0.5") 
+
     def _parse_cmd_params(self, args, command):
         zone_name = args.get("zone_name")
         if not zone_name: