[svn] commit: r2338 - in /trunk: ./ src/bin/xfrin/ src/bin/xfrout/ src/bin/xfrout/tests/ src/lib/cc/ src/lib/datasrc/ src/lib/dns/ src/lib/dns/rdata/generic/ src/lib/dns/tests/ src/lib/python/isc/ src/lib/python/isc/log/
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jun 30 03:12:30 UTC 2010
Author: chenzhengzhang
Date: Wed Jun 30 03:12:30 2010
New Revision: 2338
Log:
merge of ticket #176 (python logging framework), also changes xfrout to use the python logging.
[func] jerry
Added python logging framework. It is for testing and experimenting
with logging ideas. Currently, it supports three channels(file,
syslog and stderr) and five levels(debug, info, warning, error and
critical).
Added:
trunk/src/lib/python/isc/log/
- copied from r2337, branches/trac176/src/lib/python/isc/log/
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/configure.ac
trunk/src/bin/xfrin/ (props changed)
trunk/src/bin/xfrout/tests/xfrout_test.py
trunk/src/bin/xfrout/xfrout.py.in
trunk/src/bin/xfrout/xfrout.spec.pre.in
trunk/src/lib/cc/ (props changed)
trunk/src/lib/datasrc/ (props changed)
trunk/src/lib/dns/ (props changed)
trunk/src/lib/dns/rdata/generic/rrsig_46.cc (props changed)
trunk/src/lib/dns/tests/ (props changed)
trunk/src/lib/python/isc/Makefile.am
trunk/src/lib/python/isc/__init__.py
Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Wed Jun 30 03:12:30 2010
@@ -1,3 +1,10 @@
+ 64. [func] jerry
+ Added python logging framework. It is for testing and experimenting
+ with logging ideas. Currently, it supports three channels(file,
+ syslog and stderr) and five levels(debug, info, warning, error and
+ critical).
+ (Trac #176, svn r2338)
+
63. [func] shane
Added initial support for setuid(), using the "-u" flag. This will
be replaced in the future, but for now provides a reasonable
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed Jun 30 03:12:30 2010
@@ -433,6 +433,8 @@
src/lib/python/isc/cc/tests/Makefile
src/lib/python/isc/config/Makefile
src/lib/python/isc/config/tests/Makefile
+ src/lib/python/isc/log/Makefile
+ src/lib/python/isc/log/tests/Makefile
src/lib/config/Makefile
src/lib/config/tests/Makefile
src/lib/dns/Makefile
@@ -473,6 +475,7 @@
src/lib/config/tests/data_def_unittests_config.h
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/dns/gen-rdatacode.py
src/lib/python/bind10_config.py
src/lib/dns/tests/testdata/gen-wiredata.py
Modified: trunk/src/bin/xfrout/tests/xfrout_test.py
==============================================================================
--- trunk/src/bin/xfrout/tests/xfrout_test.py (original)
+++ trunk/src/bin/xfrout/tests/xfrout_test.py Wed Jun 30 03:12:30 2010
@@ -75,7 +75,8 @@
def setUp(self):
request = MySocket(socket.AF_INET,socket.SOCK_STREAM)
- self.xfrsess = MyXfroutSession(request, None, None)
+ self.log = isc.log.NSLogger('xfrout', '', severity = 'critical', log_to_console = False )
+ self.xfrsess = MyXfroutSession(request, None, None, self.log)
self.xfrsess.server = Dbserver()
self.mdata = b'\xd6=\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07example\x03com\x00\x00\xfc\x00\x01'
self.sock = MySocket(socket.AF_INET,socket.SOCK_STREAM)
@@ -238,10 +239,6 @@
reply_msg = self.sock.read_msg()
self.assertEqual(reply_msg.get_rr_count(section.ANSWER()), 2)
- # set event
- self.xfrsess.server._shutdown_event.set()
- self.assertRaises(XfroutException, self.xfrsess._reply_xfrout_query, self.getmsg(), self.sock, "example.com.")
-
class MyCCSession():
def __init__(self):
pass
@@ -260,6 +257,7 @@
self._shutdown_event = threading.Event()
self._max_transfers_out = 10
self._cc = MyCCSession()
+ self._log = isc.log.NSLogger('xfrout', '', severity = 'critical', log_to_console = False )
class TestUnixSockServer(unittest.TestCase):
def setUp(self):
Modified: trunk/src/bin/xfrout/xfrout.py.in
==============================================================================
--- trunk/src/bin/xfrout/xfrout.py.in (original)
+++ trunk/src/bin/xfrout/xfrout.py.in Wed Jun 30 03:12:30 2010
@@ -26,6 +26,7 @@
from socketserver import *
import os
from isc.config.ccsession import *
+from isc.log.log import *
from isc.cc import SessionError
import socket
import select
@@ -53,21 +54,20 @@
SPECFILE_LOCATION = SPECFILE_PATH + "/xfrout.spec"
AUTH_SPECFILE_LOCATION = AUTH_SPECFILE_PATH + os.sep + "auth.spec"
MAX_TRANSFERS_OUT = 10
-verbose_mode = False
-
-
-class XfroutException(Exception): pass
-
+VERBOSE_MODE = False
class XfroutSession(BaseRequestHandler):
+ def __init__(self, request, client_address, server, log):
+ BaseRequestHandler.__init__(self, request, client_address, server)
+ self._log = log
+
def handle(self):
fd = recv_fd(self.request.fileno())
if fd < 0:
# This may happen when one xfrout process try to connect to
# xfrout unix socket server, to check whether there is another
# xfrout running.
- print("[b10-xfrout] Failed to receive the FD for XFR connection, "
- "maybe because another xfrout process was started.")
+ self._log.log_message("error", "Failed to receive the file descriptor for XFR connection")
return
data_len = self.request.recv(2)
@@ -77,8 +77,7 @@
try:
self.dns_xfrout_start(sock, msgdata)
except Exception as e:
- if verbose_mode:
- self.log_msg(str(e))
+ self._log.log_message("error", str(e))
sock.close()
@@ -89,8 +88,7 @@
msg = message(message_mode.PARSE)
msg.from_wire(input_buffer(mdata))
except Exception as err:
- if verbose_mode:
- self.log_msg(str(err))
+ self._log.log_message("error", str(err))
return rcode.FORMERR(), None
return rcode.NOERROR(), msg
@@ -179,16 +177,11 @@
return self. _reply_query_with_error_rcode(msg, sock, rcode_)
try:
- if verbose_mode:
- self.log_msg("transfer of '%s/IN': AXFR started" % zone_name)
-
+ self._log.log_message("info", "transfer of '%s/IN': AXFR started" % zone_name)
self._reply_xfrout_query(msg, sock, zone_name)
-
- if verbose_mode:
- self.log_msg("transfer of '%s/IN': AXFR end" % zone_name)
+ self._log.log_message("info", "transfer of '%s/IN': AXFR end" % zone_name)
except Exception as err:
- if verbose_mode:
- sys.stderr.write("[b10-xfrout] %s\n" % str(err))
+ self._log.log_message("error", str(err))
self.server.decrease_transfers_counter()
return
@@ -262,7 +255,7 @@
# the message length to know if the rrset has been added sucessfully.
for rr_data in sqlite3_ds.get_zone_datas(zone_name, self.server.get_db_file()):
if self.server._shutdown_event.is_set(): # Check if xfrout is shutdown
- raise XfroutException("shutdown!")
+ self._log.log_message("error", "shutdown!")
if rr_type(rr_data[5]) == rr_type.SOA(): #ignore soa record
continue
@@ -281,22 +274,23 @@
self._send_message_with_last_soa(msg, sock, rrset_soa)
- def log_msg(self, msg):
- print('[b10-xfrout] ', msg)
-
class UnixSockServer(ThreadingUnixStreamServer):
'''The unix domain socket server which accept xfr query sent from auth server.'''
- def __init__(self, sock_file, handle_class, shutdown_event, config_data, cc):
+ def __init__(self, sock_file, handle_class, shutdown_event, config_data, cc, log):
self._remove_unused_sock_file(sock_file)
self._sock_file = sock_file
ThreadingUnixStreamServer.__init__(self, sock_file, handle_class)
self._lock = threading.Lock()
self._transfers_counter = 0
self._shutdown_event = shutdown_event
+ 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)
def _remove_unused_sock_file(self, sock_file):
'''Try to remove the socket file. If the file is being used
@@ -333,14 +327,17 @@
ThreadingUnixStreamServer.shutdown(self)
try:
os.unlink(self._sock_file)
- except:
- pass
+ except Exception as e:
+ self._log.log_message("error", str(e))
def update_config_data(self, new_config):
'''Apply the new config setting of xfrout module. '''
+ self._log.log_message('info', 'update config data start.')
self._lock.acquire()
self._max_transfers_out = new_config.get('transfers_out')
+ self._log.log_message('info', 'max transfer out : %d', self._max_transfers_out)
self._lock.release()
+ self._log.log_message('info', 'update config data complete.')
def get_db_file(self):
file, is_default = self._cc.get_remote_config_value("Auth", "database_file")
@@ -391,19 +388,24 @@
class XfroutServer:
def __init__(self):
self._unix_socket_server = None
+ self._log = None
self._listen_sock_file = UNIX_SOCKET_FILE
self._shutdown_event = threading.Event()
self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION, self.config_handler, self.command_handler)
self._cc.add_remote_config(AUTH_SPECFILE_LOCATION);
self._config_data = self._cc.get_full_config()
self._cc.start()
+ self._log = isc.log.NSLogger(self._config_data.get('log_name'), self._config_data.get('log_file'),
+ 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()
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._shutdown_event, self._config_data,
+ self._cc, self._log);
listener = threading.Thread(target = listen_on_xfr_query, args = (self._unix_socket_server,))
listener.start()
@@ -417,6 +419,9 @@
continue
self._config_data[key] = new_config[key]
+ if self._log:
+ self._log.update_config(new_config)
+
if self._unix_socket_server:
self._unix_socket_server.update_config_data(self._config_data)
@@ -442,8 +447,7 @@
def command_handler(self, cmd, args):
if cmd == "shutdown":
- if verbose_mode:
- print("[b10-xfrout] Received shutdown command")
+ self._log.log_message("info", "Received shutdown command.")
self.shutdown()
answer = create_answer(0)
else:
@@ -478,18 +482,18 @@
parser = OptionParser()
set_cmd_options(parser)
(options, args) = parser.parse_args()
- verbose_mode = options.verbose
+ VERBOSE_MODE = options.verbose
set_signal_handler()
xfrout_server = XfroutServer()
xfrout_server.run()
except KeyboardInterrupt:
- print("[b10-xfrout] exit xfrout process")
+ sys.stderr.write("[b10-xfrout] exit xfrout process")
except SessionError as e:
- print('[b10-xfrout] Error creating xfrout, '
- 'is the command channel daemon running?' )
+ sys.stderr.write("[b10-xfrout] Error creating xfrout,"
+ "is the command channel daemon running?")
except ModuleCCSessionError as e:
- print('[b10-xfrout] exit xfrout process:', e)
+ sys.stderr.write("info", '[b10-xfrout] exit xfrout process:', e)
if xfrout_server:
xfrout_server.shutdown()
Modified: trunk/src/bin/xfrout/xfrout.spec.pre.in
==============================================================================
--- trunk/src/bin/xfrout/xfrout.spec.pre.in (original)
+++ trunk/src/bin/xfrout/xfrout.spec.pre.in Wed Jun 30 03:12:30 2010
@@ -12,7 +12,37 @@
"item_name": "db_file",
"item_type": "string",
"item_optional": False,
- "item_default": '@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3'
+ "item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
+ },
+ {
+ "item_name": "log_name",
+ "item_type": "string",
+ "item_optional": False,
+ "item_default": "Xfrout"
+ },
+ {
+ "item_name": "log_file",
+ "item_type": "string",
+ "item_optional": False,
+ "item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/log/Xfrout.log"
+ },
+ {
+ "item_name": "log_severity",
+ "item_type": "string",
+ "item_optional": False,
+ "item_default": "debug"
+ },
+ {
+ "item_name": "log_versions",
+ "item_type": "integer",
+ "item_optional": False,
+ "item_default": 5
+ },
+ {
+ "item_name": "log_max_bytes",
+ "item_type": "integer",
+ "item_optional": False,
+ "item_default": 1048576
}
],
"commands": [
Modified: trunk/src/lib/python/isc/Makefile.am
==============================================================================
--- trunk/src/lib/python/isc/Makefile.am (original)
+++ trunk/src/lib/python/isc/Makefile.am Wed Jun 30 03:12:30 2010
@@ -1,4 +1,4 @@
-SUBDIRS = datasrc cc config # Util
+SUBDIRS = datasrc cc config log # Util
python_PYTHON = __init__.py
Modified: trunk/src/lib/python/isc/__init__.py
==============================================================================
--- trunk/src/lib/python/isc/__init__.py (original)
+++ trunk/src/lib/python/isc/__init__.py Wed Jun 30 03:12:30 2010
@@ -1,3 +1,4 @@
import isc.datasrc
import isc.cc
import isc.config
+import isc.log
More information about the bind10-changes
mailing list