BIND 10 trac670, updated. f9a697ab99914d58e7e135ca069b3d5a06c00511 [trac670] Implement configuring the zones

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Mar 17 20:39:41 UTC 2011


The branch, trac670 has been updated
       via  f9a697ab99914d58e7e135ca069b3d5a06c00511 (commit)
      from  320bafb306878cd9f13ba9703a0d4573fb645341 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f9a697ab99914d58e7e135ca069b3d5a06c00511
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Mar 17 21:14:58 2011 +0100

    [trac670] Implement configuring the zones

-----------------------------------------------------------------------

Summary of changes:
 src/bin/zonemgr/tests/zonemgr_test.py |   24 +++++++++++++++++++-----
 src/bin/zonemgr/zonemgr.py.in         |   29 +++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 7 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/zonemgr/tests/zonemgr_test.py b/src/bin/zonemgr/tests/zonemgr_test.py
index b51390c..3ad0ce6 100644
--- a/src/bin/zonemgr/tests/zonemgr_test.py
+++ b/src/bin/zonemgr/tests/zonemgr_test.py
@@ -22,10 +22,10 @@ import tempfile
 from zonemgr import *
 
 ZONE_NAME_CLASS1_IN = ("sd.cn.", "IN")
-ZONE_NAME_CLASS2_CH = ("tw.cn", "CH")
+ZONE_NAME_CLASS2_CH = ("tw.cn.", "CH")
 ZONE_NAME_CLASS3_IN = ("example.com", "IN")
 ZONE_NAME_CLASS1_CH = ("sd.cn.", "CH")
-ZONE_NAME_CLASS2_IN = ("tw.cn", "IN")
+ZONE_NAME_CLASS2_IN = ("tw.cn.", "IN")
 
 MAX_TRANSFER_TIMEOUT = 14400
 LOWERBOUND_REFRESH = 10
@@ -70,6 +70,19 @@ class FakeConfig:
 class MyZonemgrRefresh(ZonemgrRefresh):
     def __init__(self):
         self._master_socket, self._slave_socket = socket.socketpair()
+        self._zonemgr_refresh_info = {}
+
+        def get_zone_soa(zone_name, db_file):
+            if zone_name == 'sd.cn.':
+                return (1, 2, 'sd.cn.', 'cn.sd.', 21600, 'SOA', None,
+                        'a.dns.cn. root.cnnic.cn. 2009073106 7200 3600 2419200 21600')
+            elif zone_name == 'tw.cn.':
+                return (1, 2, 'tw.cn.', 'cn.sd.', 21600, 'SOA', None,
+                        'a.dns.cn. root.cnnic.cn. 2009073112 7200 3600 2419200 21600')
+            else:
+                return None
+        sqlite3_ds.get_zone_soa = get_zone_soa
+
         ZonemgrRefresh.__init__(self, MySession(), "initdb.file",
             self._slave_socket, FakeConfig())
         current_time = time.time()
@@ -79,7 +92,7 @@ class MyZonemgrRefresh(ZonemgrRefresh):
          'next_refresh_time': current_time + 6500, 
          'zone_soa_rdata': 'a.dns.cn. root.cnnic.cn. 2009073105 7200 3600 2419200 21600', 
          'zone_state': 0},
-         ('tw.cn', 'CH'): {
+         ('tw.cn.', 'CH'): {
          'last_refresh_time': current_time, 
          'next_refresh_time': current_time + 6900, 
          'zone_soa_rdata': 'a.dns.cn. root.cnnic.cn. 2009073112 7200 3600 2419200 21600', 
@@ -365,7 +378,7 @@ class TestZonemgrRefresh(unittest.TestCase):
                     'next_refresh_time': time1 + 7200, 
                     'zone_soa_rdata': 'a.dns.cn. root.cnnic.cn. 2009073105 7200 3600 2419200 21600', 
                     'zone_state': ZONE_OK},
-                ("tw.cn","CH"):{
+                ("tw.cn.","CH"):{
                     'last_refresh_time': time1 - 7200, 
                     'next_refresh_time': time1, 
                     'refresh_timeout': time1 + MAX_TRANSFER_TIMEOUT, 
@@ -433,7 +446,8 @@ class TestZonemgrRefresh(unittest.TestCase):
                     "lowerbound_refresh" : 60,
                     "lowerbound_retry" : 30,
                     "max_transfer_timeout" : 19800,
-                    "jitter_scope" : 0.25
+                    "jitter_scope" : 0.25,
+                    "secondary_zones": []
                 }
         self.zone_refresh.update_config_data(config_data)
         self.assertEqual(60, self.zone_refresh._lowerbound_refresh)
diff --git a/src/bin/zonemgr/zonemgr.py.in b/src/bin/zonemgr/zonemgr.py.in
index 16796dd..68fc594 100755
--- a/src/bin/zonemgr/zonemgr.py.in
+++ b/src/bin/zonemgr/zonemgr.py.in
@@ -34,6 +34,7 @@ import threading
 import select
 import socket
 import errno
+import copy
 from isc.datasrc import sqlite3_ds
 from optparse import OptionParser, OptionValueError
 from isc.config.ccsession import *
@@ -411,6 +412,28 @@ class ZonemgrRefresh:
 
     def update_config_data(self, new_config):
         """ update ZonemgrRefresh config """
+        backup = copy.copy(self._zonemgr_refresh_info)
+        try:
+            required = {}
+            # Add new zones
+            for secondary_zone in new_config.get('secondary_zones'):
+                name_class = (secondary_zone['name'], secondary_zone['class'])
+                required[name_class] = True
+                # Add it only if it isn't there already
+                if not name_class in self._zonemgr_refresh_info:
+                    self.zonemgr_add_zone(name_class)
+            # Drop the zones that are no longer there
+            # Do it in two phases, python doesn't like deleting while iterating
+            to_drop = []
+            for old_zone in self._zonemgr_refresh_info:
+                if not old_zone in required:
+                    to_drop.append(old_zone)
+            for drop in to_drop:
+                del self._zonemgr_refresh_info[drop]
+        # If we are not able to find it in database, restore the original
+        except:
+            self._zonemgr_refresh_info = backup
+            raise
         self._lowerbound_refresh = new_config.get('lowerbound_refresh')
         self._lowerbound_retry = new_config.get('lowerbound_retry')
         self._max_transfer_timeout = new_config.get('max_transfer_timeout')
@@ -480,14 +503,16 @@ class Zonemgr:
         return answer
 
     def _config_data_check(self, config_data):
-        """Check whether the new config data is valid or 
-        not. """ 
+        """Check whether the new config data is valid or
+        not. It contains only basic logic, not full check against
+        database."""
         # 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 big, 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:




More information about the bind10-changes mailing list