[svn] commit: r2087 - in /branches/trac176/src: bin/xfrout/xfrout.py.in bin/xfrout/xfrout.spec.pre.in lib/python/isc/log/tests/log_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Jun 8 02:34:55 UTC 2010
Author: chenzhengzhang
Date: Tue Jun 8 02:34:54 2010
New Revision: 2087
Log:
Refine python logging test cases
Modified:
branches/trac176/src/bin/xfrout/xfrout.py.in
branches/trac176/src/bin/xfrout/xfrout.spec.pre.in
branches/trac176/src/lib/python/isc/log/tests/log_test.py
Modified: branches/trac176/src/bin/xfrout/xfrout.py.in
==============================================================================
--- branches/trac176/src/bin/xfrout/xfrout.py.in (original)
+++ branches/trac176/src/bin/xfrout/xfrout.py.in Tue Jun 8 02:34:54 2010
@@ -48,13 +48,17 @@
UNIX_SOCKET_FILE = "@@LOCALSTATEDIR@@/auth_xfrout_conn"
MAX_TRANSFERS_OUT = 10
-verbose_mode = False
+VERBOSE_MODE = False
class XfroutException(Exception): pass
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:
@@ -66,10 +70,12 @@
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()
+
+ def setLogger(self, logger):
+ self._log = logger
def _parse_query_message(self, mdata):
''' parse query message to [socket,message]'''
@@ -78,8 +84,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
@@ -168,16 +173,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(str(err))
+ self._log.log_message("error", str(err))
self.server.decrease_transfers_counter()
return
@@ -291,9 +291,12 @@
self._log = log
self.update_config_data(config_data)
+ def finish_request(self, request, client_address):
+ '''Finish one request by instantiating RequestHandlerClass.'''
+ self.RequestHandlerClass(request, client_address, self, self._log)
def shutdown(self):
- self._log.log_message('warning', 'Xfrout process will is shutting down')
+ self._log.log_message('warning', 'Xfrout process is shutting down!')
ThreadingUnixStreamServer.shutdown(self)
try:
os.unlink(self._sock_file)
@@ -303,14 +306,14 @@
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._log.log_message('info', 'update config data start.')
self._lock.acquire()
self._max_transfers_out = new_config.get('transfers_out')
- self._log.log_message('debug', 'max transfer out : %d', self._max_transfers_out)
+ self._log.log_message('info', 'max transfer out : %d', self._max_transfers_out)
self._db_file = new_config.get('db_file')
- self._log.log_message('debug', 'db file name : %s', self._db_file)
+ self._log.log_message('info', 'db file name : %s', self._db_file)
self._lock.release()
- self._log.log_message('info', 'update config data complete')
+ self._log.log_message('info', 'update config data complete.')
def get_db_file(self):
self._lock.acquire()
@@ -405,8 +408,7 @@
def command_handler(self, cmd, args):
if cmd == "shutdown":
- if verbose_mode:
- self._log.log_message("info", "Received shutdown command")
+ self._log.log_message("info", "Received shut down command.")
self.shutdown()
answer = create_answer(0)
else:
@@ -441,7 +443,7 @@
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()
Modified: branches/trac176/src/bin/xfrout/xfrout.spec.pre.in
==============================================================================
--- branches/trac176/src/bin/xfrout/xfrout.spec.pre.in (original)
+++ branches/trac176/src/bin/xfrout/xfrout.spec.pre.in Tue Jun 8 02:34:54 2010
@@ -24,7 +24,7 @@
"item_name": "log_file",
"item_type": "string",
"item_optional": False,
- "item_default": "/var/log/xfrout.log"
+ "item_default": '@@LOCALSTATEDIR@@/Xfrout.log'
},
{
"item_name": "severity",
Modified: branches/trac176/src/lib/python/isc/log/tests/log_test.py
==============================================================================
--- branches/trac176/src/lib/python/isc/log/tests/log_test.py (original)
+++ branches/trac176/src/lib/python/isc/log/tests/log_test.py Tue Jun 8 02:34:54 2010
@@ -30,10 +30,12 @@
self.assertEqual(self.handler.maxBytes, 512)
self.assertEqual(self.handler.backupCount, 3)
- self.handler.update_config(FILE_LOG3, 4, 1024)
- self.assertEqual(self.handler.baseFilename, FILE_LOG2)
- self.assertEqual(self.handler.maxBytes, 1024)
- self.assertEqual(self.handler.backupCount, 4)
+ dir = os.path.split(FILE_LOG3)
+ if not os.path.exists(dir[0]):
+ self.handler.update_config(FILE_LOG3, 4, 1024)
+ self.assertEqual(self.handler.baseFilename, FILE_LOG2)
+ self.assertEqual(self.handler.maxBytes, 1024)
+ self.assertEqual(self.handler.backupCount, 4)
def tearDown(self):
self.handler.flush()
More information about the bind10-changes
mailing list