Browse Source

[1643] Logging

Michal 'vorner' Vaner 13 years ago
parent
commit
07dd87ca1a

+ 2 - 0
src/lib/python/isc/log_messages/Makefile.am

@@ -13,6 +13,7 @@ EXTRA_DIST += cfgmgr_messages.py
 EXTRA_DIST += config_messages.py
 EXTRA_DIST += notify_out_messages.py
 EXTRA_DIST += libxfrin_messages.py
+EXTRA_DIST += server_common_messages.py
 
 CLEANFILES = __init__.pyc
 CLEANFILES += bind10_messages.pyc
@@ -27,6 +28,7 @@ CLEANFILES += cfgmgr_messages.pyc
 CLEANFILES += config_messages.pyc
 CLEANFILES += notify_out_messages.pyc
 CLEANFILES += libxfrin_messages.pyc
+CLEANFILES += server_common_messages.pyc
 
 CLEANDIRS = __pycache__
 

+ 1 - 0
src/lib/python/isc/log_messages/server_common_messages.py

@@ -0,0 +1 @@
+from work.server_common_messages import *

+ 14 - 0
src/lib/python/isc/server_common/Makefile.am

@@ -4,7 +4,21 @@ python_PYTHON = __init__.py tsig_keyring.py
 
 pythondir = $(pyexecdir)/isc/server_common
 
+BUILT_SOURCES = $(PYTHON_LOGMSGPKG_DIR)/work/server_common_messages.py
+nodist_pylogmessage_PYTHON = $(PYTHON_LOGMSGPKG_DIR)/work/server_common_messages.py
+
+pylogmessagedir = $(pyexecdir)/isc/logmessages/
+
+CLEANFILES = $(PYTHON_LOGMSGPKG_DIR)/work/server_common_messages.py
+CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/work/server_common_messages.pyc
+
 CLEANDIRS = __pycache__
 
+EXTRA_DIST = server_common_messages.mes
+
+$(PYTHON_LOGMSGPKG_DIR)/work/server_common_messages.py : server_common_messages.mes
+	$(top_builddir)/src/lib/log/compiler/message \
+	-d $(PYTHON_LOGMSGPKG_DIR)/work -p $(srcdir)/server_common_messages.mes
+
 clean-local:
 	rm -rf $(CLEANDIRS)

+ 36 - 0
src/lib/python/isc/server_common/server_common_messages.mes

@@ -0,0 +1,36 @@
+# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+# No namespace declaration - these constants go in the global namespace
+# of the config_messages python module.
+
+# since these messages are for the python server_common library, care must
+# be taken that names do not conflict with the messages from the c++
+# server_common library. A checker script should verify that, but we do not
+# have that at this moment. So when adding a message, make sure that
+# the name is not already used in src/lib/config/config_messages.mes
+
+% PYSERVER_COMMON_TSIG_KEYRING_DEINIT Deinitializing global TSIG keyring
+A debug message noting that the global TSIG keyring is being removed from
+memory. Most programs don't do that, they just exit, which is OK.
+
+% PYSERVER_COMMON_TSIG_KEYRING_INIT Initializing global TSIG keyring
+A debug message noting the TSIG keyring storage is being prepared. It should
+appear at most once in the lifetime of a program. The keyring still needs
+to be loaded from configuration.
+
+% PYSERVER_COMMON_TSIG_KEYRING_UPDATE Updating global TSIG keyring
+A debug message. The TSIG keyring is being (re)loaded from configuration.
+This happens at startup or when the configuration changes. The old keyring
+is removed and new one created with all the keys.

+ 3 - 0
src/lib/python/isc/server_common/tests/tsig_keyring_test.py

@@ -18,6 +18,7 @@ Tests for isc.server_common.tsig_keyring.
 """
 
 import unittest
+import isc.log
 from isc.server_common.tsig_keyring import *
 import isc.dns
 from isc.testutils.ccsession_mock import MockModuleCCSession
@@ -143,4 +144,6 @@ class TSIGKeyRingTest(unittest.TestCase):
         self.assertEqual(keys, keyring())
 
 if __name__ == "__main__":
+    isc.log.init("bind10") # FIXME Should this be needed?
+    isc.log.resetUnitTestRootLogger()
     unittest.main()

+ 9 - 0
src/lib/python/isc/server_common/tsig_keyring.py

@@ -19,8 +19,11 @@ tsig_keys module.
 """
 
 import isc.dns
+import isc.log
+from isc.log_messages.server_common_messages import *
 
 updater = None
+logger = isc.log.Logger("server_common")
 
 class Unexpected(Exception):
     """
@@ -45,6 +48,8 @@ class Updater:
         Constructor. Pass the ccsession object so the key ring can be
         downloaded.
         """
+        logger.debug(logger.DBGLVL_TRACE_BASIC,
+                     PYSERVER_COMMON_TSIG_KEYRING_INIT)
         self._session = session
         self._keyring = isc.dns.TSIGKeyRing()
         session.add_remote_config_by_name('tsig_keys', self._update)
@@ -61,6 +66,8 @@ class Updater:
         The parameters are there just to match the signature which
         the callback should have (eg. they are ignored).
         """
+        logger.debug(logger.DBGLVL_TRACE_BASIC,
+                     PYSERVER_COMMON_TSIG_KEYRING_UPDATE)
         (data, default) = self._session.get_remote_config_value('tsig_keys',
                                                                 'keys')
         if data is not None: # There's an update
@@ -82,6 +89,8 @@ class Updater:
         Unregister from getting updates. The object will not be
         usable any more after this.
         """
+        logger.debug(logger.DBGLVL_TRACE_BASIC,
+                     PYSERVER_COMMON_TSIG_KEYRING_DEINIT)
         self._session.remove_remote_config('tsig_keys')
 
 def keyring():