[svn] commit: r2611 - in /branches/trac289: ./ src/bin/xfrin/ src/bin/xfrout/ src/lib/python/isc/ src/lib/python/isc/datasrc/ src/lib/python/isc/notify/ src/lib/python/isc/notify/tests/

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Aug 2 13:32:23 UTC 2010


Author: zhanglikun
Date: Mon Aug  2 13:32:23 2010
New Revision: 2611

Log:
commit the code of notify-out. TODO:merge the code of secondary manager(in branch 215) to this branch, so that it's easy do the test.

Added:
    branches/trac289/src/lib/python/isc/notify/
    branches/trac289/src/lib/python/isc/notify/Makefile.am
    branches/trac289/src/lib/python/isc/notify/__init__.py
    branches/trac289/src/lib/python/isc/notify/notify_out.py
    branches/trac289/src/lib/python/isc/notify/tests/
    branches/trac289/src/lib/python/isc/notify/tests/Makefile.am
    branches/trac289/src/lib/python/isc/notify/tests/notify_out_test.in   (with props)
    branches/trac289/src/lib/python/isc/notify/tests/notify_out_test.py
Modified:
    branches/trac289/configure.ac
    branches/trac289/src/bin/xfrin/xfrin.py.in
    branches/trac289/src/bin/xfrout/xfrout.py.in
    branches/trac289/src/lib/python/isc/Makefile.am
    branches/trac289/src/lib/python/isc/datasrc/sqlite3_ds.py

Modified: branches/trac289/configure.ac
==============================================================================
--- branches/trac289/configure.ac (original)
+++ branches/trac289/configure.ac Mon Aug  2 13:32:23 2010
@@ -423,6 +423,8 @@
                  src/lib/python/isc/config/tests/Makefile
                  src/lib/python/isc/log/Makefile
                  src/lib/python/isc/log/tests/Makefile
+                 src/lib/python/isc/notify/Makefile
+                 src/lib/python/isc/notify/tests/Makefile
                  src/lib/config/Makefile
                  src/lib/config/tests/Makefile
                  src/lib/dns/Makefile
@@ -469,6 +471,7 @@
            src/lib/python/isc/config/tests/config_test
            src/lib/python/isc/cc/tests/cc_test
            src/lib/python/isc/log/tests/log_test
+           src/lib/python/isc/notify/tests/notify_out_test
            src/lib/dns/gen-rdatacode.py
            src/lib/python/bind10_config.py
            src/lib/dns/tests/testdata/gen-wiredata.py

Modified: branches/trac289/src/bin/xfrin/xfrin.py.in
==============================================================================
--- branches/trac289/src/bin/xfrin/xfrin.py.in (original)
+++ branches/trac289/src/bin/xfrin/xfrin.py.in Mon Aug  2 13:32:23 2010
@@ -28,6 +28,7 @@
 import random
 from optparse import OptionParser, OptionValueError
 from isc.config.ccsession import *
+from isc.notify import notify_out
 try:
     from libdns_python import *
 except ImportError as e:
@@ -49,7 +50,7 @@
 SPECFILE_LOCATION = SPECFILE_PATH + "/xfrin.spec"
 AUTH_SPECFILE_LOCATION = AUTH_SPECFILE_PATH + "/auth.spec"
 
-
+XFROUT_MODULE_NAME = 'Xfrout'
 __version__ = 'BIND10'
 # define xfrin rcode
 XFRIN_OK = 0
@@ -66,7 +67,7 @@
 class XfrinConnection(asyncore.dispatcher):
     '''Do xfrin in this class. '''    
 
-    def __init__(self,
+    def __init__(self, server_,
                  sock_map, zone_name, rrclass, db_file, shutdown_event,
                  master_addrinfo, verbose = False, idle_timeout = 60): 
         ''' idle_timeout: max idle time for read data from socket.
@@ -77,6 +78,7 @@
         asyncore.dispatcher.__init__(self, map=sock_map)
         self.create_socket(master_addrinfo[0], master_addrinfo[1])
         self._zone_name = zone_name
+        self._server = server_
         self._sock_map = sock_map
         self._rrclass = rrclass
         self._db_file = db_file
@@ -192,6 +194,7 @@
                                             self._handle_xfrin_response)
 
                 self.log_msg(logstr + 'succeeded')
+                self._server.send_notify_command(self._zone_name)
                 ret = XFRIN_OK
 
         except XfrinException as e:
@@ -316,11 +319,11 @@
             sys.stdout.write('[b10-xfrin] %s\n' % str(msg))
 
 
-def process_xfrin(xfrin_recorder, zone_name, rrclass, db_file, 
+def process_xfrin(server, xfrin_recorder, zone_name, rrclass, db_file, 
                   shutdown_event, master_addrinfo, check_soa, verbose):
     xfrin_recorder.increment(zone_name)
     sock_map = {}
-    conn = XfrinConnection(sock_map, zone_name, rrclass, db_file,
+    conn = XfrinConnection(server, sock_map, zone_name, rrclass, db_file,
                            shutdown_event, master_addrinfo, verbose)
     if conn.connect_to_master():
         conn.do_xfrin(check_soa)
@@ -370,17 +373,20 @@
 separately for convenience of unit tests; by letting the test code override
 this method we can test most of this class without requiring a command channel.
 '''
-        self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION,
+        # Create one session for sending command to other modules, because the 
+        # listening session will block the send operation.
+        self._send_cc_session = isc.cc.Session()
+        self._module_cc = isc.config.ModuleCCSession(SPECFILE_LOCATION,
                                               self.config_handler,
                                               self.command_handler)
-        self._cc.start()
+        self._module_cc.start()
 
     def _cc_check_command(self):
         '''
 This is a straightforward wrapper for cc.check_command, but provided as
 a separate method for the convenience of unit tests.
 '''
-        self._cc.check_command()
+        self._module_cc.check_command()
 
     def config_handler(self, new_config):
         # TODO, process new config data
@@ -420,6 +426,12 @@
 
         return answer
 
+    def send_notify_command(self, zone_name):
+        '''Send Notify command to xfrout module.'''
+        param = {'zone_name': zone_name}
+        msg = create_command(notify_out.ZONE_NOTIFY_CMD, param)
+        self._send_cc_session.group_sendmsg(msg, XFROUT_MODULE_NAME)
+
     def _parse_cmd_params(self, args):
         zone_name = args.get('zone_name')
         if not zone_name:
@@ -441,14 +453,14 @@
             # should add it on start, and not remove it here
             # (or, if we have writable ds, we might not need this in
             # the first place)
-            self._cc.add_remote_config(AUTH_SPECFILE_LOCATION)
-            db_file, is_default = self._cc.get_remote_config_value("Auth", "database_file")
+            self._module_cc.add_remote_config(AUTH_SPECFILE_LOCATION)
+            db_file, is_default = self._module_cc.get_remote_config_value("Auth", "database_file")
             if is_default and "B10_FROM_BUILD" in os.environ:
                 # this too should be unnecessary, but currently the
                 # 'from build' override isn't stored in the config
                 # (and we don't have writable datasources yet)
                 db_file = os.environ["B10_FROM_BUILD"] + os.sep + "bind10_zones.sqlite3"
-            self._cc.remove_remote_config(AUTH_SPECFILE_LOCATION)
+            self._module_cc.remove_remote_config(AUTH_SPECFILE_LOCATION)
 
         return (zone_name, master_addrinfo, db_file)
 
@@ -469,7 +481,8 @@
             return (1, 'zone xfrin is in progress')
 
         xfrin_thread = threading.Thread(target = process_xfrin,
-                                        args = (self.recorder,
+                                        args = (self,
+                                                self.recorder,
                                                 zone_name, rrclass,
                                                 db_file,
                                                 self._shutdown_event,

Modified: branches/trac289/src/bin/xfrout/xfrout.py.in
==============================================================================
--- branches/trac289/src/bin/xfrout/xfrout.py.in (original)
+++ branches/trac289/src/bin/xfrout/xfrout.py.in Mon Aug  2 13:32:23 2010
@@ -28,6 +28,7 @@
 from isc.config.ccsession import *
 from isc.log.log import *
 from isc.cc import SessionError
+from isc.notify import notify_out
 import socket
 import select
 import errno
@@ -303,7 +304,7 @@
         self._log = log
         self.update_config_data(config_data)
         self._cc = cc
-
+        
     def finish_request(self, request, client_address):
         '''Finish one request by instantiating RequestHandlerClass.'''
         self.RequestHandlerClass(request, client_address, self, self._log)
@@ -415,16 +416,25 @@
                                 self._config_data.get('log_severity'), self._config_data.get('log_versions'),
                                 self._config_data.get('log_max_bytes'), True)
         self._start_xfr_query_listener()
+        self._start_notifier()
 
     def _start_xfr_query_listener(self):
         '''Start a new thread to accept xfr query. '''
-    
         self._unix_socket_server = UnixSockServer(self._listen_sock_file, XfroutSession, 
                                                   self._shutdown_event, self._config_data,
                                                   self._cc, self._log);
         listener = threading.Thread(target = listen_on_xfr_query, args = (self._unix_socket_server,))
         listener.start()
-
+        
+    def _start_notifier(self):
+        datasrc = self._unix_socket_server.get_db_file()
+        self._notifier = notify_out.NotifyOut(datasrc, self._log)
+        td = threading.Thread(target = notify_out.dispatcher, args = (self._notifier,))
+        td.daemon = True
+        td.start()
+
+    def send_notify(self, zone_name):
+        self._notifier.send_notify(zone_name)
 
     def config_handler(self, new_config):
         '''Update config data. TODO. Do error check'''
@@ -466,11 +476,20 @@
             self._log.log_message("info", "Received shutdown command.")
             self.shutdown()
             answer = create_answer(0)
+        
+        elif cmd == notify_out.ZONE_NOTIFY_CMD:
+            zone_name = args.get('zone_name')
+            if zone_name:
+                self._log.log_message("info", "Receive notify command for zone " + zone_name)
+                self.send_notify(zone_name)
+                answer = create_answer(0)
+            else:
+                answer = create_answer(1, "Bad command parameter:" + str(args))
+
         else: 
             answer = create_answer(1, "Unknown command:" + str(cmd))
 
         return answer    
- 
 
     def run(self):
         '''Get and process all commands sent from cfgmgr or other modules. '''

Modified: branches/trac289/src/lib/python/isc/Makefile.am
==============================================================================
--- branches/trac289/src/lib/python/isc/Makefile.am (original)
+++ branches/trac289/src/lib/python/isc/Makefile.am Mon Aug  2 13:32:23 2010
@@ -1,4 +1,4 @@
-SUBDIRS = datasrc cc config log # Util
+SUBDIRS = datasrc cc config log notify # Util
 
 python_PYTHON = __init__.py
 

Modified: branches/trac289/src/lib/python/isc/datasrc/sqlite3_ds.py
==============================================================================
--- branches/trac289/src/lib/python/isc/datasrc/sqlite3_ds.py (original)
+++ branches/trac289/src/lib/python/isc/datasrc/sqlite3_ds.py Mon Aug  2 13:32:23 2010
@@ -120,6 +120,39 @@
 
     return datas
 
+
+#########################################################################
+# get_zone_rrset
+#   returns the rrset of the zone with the given zone name, rrset name 
+#   and given rd type. 
+#   If the zone doesn't exist or rd type doesn't exist, return an empty list. 
+#########################################################################
+def get_zone_rrset(zonename, rr_name, rdtype, dbfile):
+    conn, cur = open(dbfile)
+    id = get_zoneid(zonename, cur)
+    cur.execute("SELECT * FROM records WHERE name = ? and zone_id = ? and rdtype = ?", 
+                [rr_name, id, rdtype])
+    datas = cur.fetchall()
+    cur.close()
+    conn.close()
+    return datas
+
+
+#########################################################################
+# get_zones_info:
+#   returns all the zones' information.
+#########################################################################
+def get_zones_info(db_file):
+    conn, cur = open(db_file)
+    cur.execute("SELECT name, rdclass FROM zones")
+    info = cur.fetchone()
+    while info:
+        yield info
+        info = cur.fetchone()
+
+    cur.close()
+    conn.close()
+
 #########################################################################
 # get_zoneid:
 #   returns the zone_id for a given zone name, or an empty




More information about the bind10-changes mailing list