BIND 10 trac1643, updated. a11e3b2165821e9ca039196b12d70025845a5d22 [1643] More tests
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Feb 24 10:24:54 UTC 2012
The branch, trac1643 has been updated
via a11e3b2165821e9ca039196b12d70025845a5d22 (commit)
via fcbe40140a5e21ecf3ff078206afe1d68e945462 (commit)
via 07dd87ca1a14058c926497ec1c6ac61ffd3a41f2 (commit)
from 766508d03d1304dc4d66b814a7a21d160b3404c2 (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 a11e3b2165821e9ca039196b12d70025845a5d22
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Feb 24 11:24:29 2012 +0100
[1643] More tests
commit fcbe40140a5e21ecf3ff078206afe1d68e945462
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Feb 24 10:05:05 2012 +0100
[1643] Naming consistency
commit 07dd87ca1a14058c926497ec1c6ac61ffd3a41f2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Feb 24 09:59:47 2012 +0100
[1643] Logging
-----------------------------------------------------------------------
Summary of changes:
src/lib/python/isc/log_messages/Makefile.am | 2 +
.../isc/log_messages/server_common_messages.py | 1 +
src/lib/python/isc/server_common/Makefile.am | 14 ++++
.../isc/server_common/server_common_messages.mes | 36 ++++++++++
.../isc/server_common/tests/tsig_keyring_test.py | 71 ++++++++++++++++---
src/lib/python/isc/server_common/tsig_keyring.py | 35 ++++++----
6 files changed, 134 insertions(+), 25 deletions(-)
create mode 100644 src/lib/python/isc/log_messages/server_common_messages.py
create mode 100644 src/lib/python/isc/server_common/server_common_messages.mes
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/log_messages/Makefile.am b/src/lib/python/isc/log_messages/Makefile.am
index 4b084cc..4b7e1d1 100644
--- a/src/lib/python/isc/log_messages/Makefile.am
+++ b/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__
diff --git a/src/lib/python/isc/log_messages/server_common_messages.py b/src/lib/python/isc/log_messages/server_common_messages.py
new file mode 100644
index 0000000..a491071
--- /dev/null
+++ b/src/lib/python/isc/log_messages/server_common_messages.py
@@ -0,0 +1 @@
+from work.server_common_messages import *
diff --git a/src/lib/python/isc/server_common/Makefile.am b/src/lib/python/isc/server_common/Makefile.am
index dd2fe48..275e34a 100644
--- a/src/lib/python/isc/server_common/Makefile.am
+++ b/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)
diff --git a/src/lib/python/isc/server_common/server_common_messages.mes b/src/lib/python/isc/server_common/server_common_messages.mes
new file mode 100644
index 0000000..b32205c
--- /dev/null
+++ b/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.
diff --git a/src/lib/python/isc/server_common/tests/tsig_keyring_test.py b/src/lib/python/isc/server_common/tests/tsig_keyring_test.py
index 06c930d..e9a2174 100644
--- a/src/lib/python/isc/server_common/tests/tsig_keyring_test.py
+++ b/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
@@ -52,6 +53,7 @@ class TSIGKeyRingTest(unittest.TestCase):
def setUp(self):
self.__session = Session()
self.__sha1name = isc.dns.Name('hmac-sha1')
+ self.__md5name = isc.dns.Name('hmac-md5.sig-alg.reg.int')
def tearDown(self):
deinit_keyring()
@@ -67,22 +69,25 @@ class TSIGKeyRingTest(unittest.TestCase):
tests the interaction with the keyring() function.
"""
# The keyring function raises until initialized
- self.assertRaises(Unexpected, keyring)
+ self.assertRaises(Unexpected, get_keyring)
self.__do_init()
- current_keyring = keyring()
+ current_keyring = get_keyring()
self.assertTrue(isinstance(current_keyring, isc.dns.TSIGKeyRing))
# Another initialization does nothing
self.__do_init()
- self.assertEqual(current_keyring, keyring())
+ self.assertEqual(current_keyring, get_keyring())
# When we deinitialize it, it no longer provides the keyring
deinit_keyring()
self.assertEqual('tsig_keys', self.__session._remove_name)
self.__session._remove_name = None
- self.assertRaises(Unexpected, keyring)
+ self.assertRaises(Unexpected, get_keyring)
# Another deinitialization doesn't change anything
deinit_keyring()
- self.assertRaises(Unexpected, keyring)
+ self.assertRaises(Unexpected, get_keyring)
self.assertIsNone(self.__session._remove_name)
+ # Test we can init it again (not expected, but not forbidden)
+ self.__do_init()
+ self.assertTrue(isinstance(get_keyring(), isc.dns.TSIGKeyRing))
def test_load(self):
"""
@@ -92,7 +97,7 @@ class TSIGKeyRingTest(unittest.TestCase):
# Initial load
self.__session._data = ['key:MTIzNAo=:hmac-sha1']
self.__do_init()
- keys = keyring()
+ keys = get_keyring()
self.assertEqual(1, keys.size())
(rcode, key) = keys.find(isc.dns.Name('key'), self.__sha1name)
self.assertEqual(isc.dns.TSIGKeyRing.SUCCESS, rcode)
@@ -102,7 +107,7 @@ class TSIGKeyRingTest(unittest.TestCase):
self.__session._data = ['key.example:MTIzNAo=:hmac-sha1']
self.__session._callback()
orig_keys = keys
- keys = keyring()
+ keys = get_keyring()
self.assertNotEqual(keys, orig_keys)
self.assertEqual(1, keys.size())
# The old key is not here
@@ -121,10 +126,50 @@ class TSIGKeyRingTest(unittest.TestCase):
"""
self.__session._data = ['key:MTIzNAo=:hmac-sha1']
self.__do_init()
- keys = keyring()
+ keys = get_keyring()
self.__session._data = None
self.__session._callback()
- self.assertEqual(keys, keyring())
+ self.assertEqual(keys, get_keyring())
+
+ def test_no_keys_update(self):
+ """
+ Test we can update the keyring to be empty.
+ """
+ self.__session._data = ['key:MTIzNAo=:hmac-sha1']
+ self.__do_init()
+ keys = get_keyring()
+ self.assertEqual(1, keys.size())
+ self.__session._data = []
+ self.__session._callback()
+ keys = get_keyring()
+ self.assertEqual(0, keys.size())
+
+ def test_update_multi(self):
+ """
+ Test we can handle multiple keys in startup/update.
+ """
+ # Init
+ self.__session._data = ['key:MTIzNAo=:hmac-sha1', 'key2:MTIzNAo=']
+ self.__do_init()
+ keys = get_keyring()
+ self.assertEqual(2, keys.size())
+ (rcode, key) = keys.find(isc.dns.Name('key'), self.__sha1name)
+ self.assertEqual(isc.dns.TSIGKeyRing.SUCCESS, rcode)
+ self.assertEqual(isc.dns.Name('key'), key.get_key_name())
+ (rcode, key) = keys.find(isc.dns.Name('key2'), self.__md5name)
+ self.assertEqual(isc.dns.TSIGKeyRing.SUCCESS, rcode)
+ self.assertEqual(isc.dns.Name('key2'), key.get_key_name())
+ # Update
+ self.__session._data = ['key1:MTIzNAo=:hmac-sha1', 'key3:MTIzNAo=']
+ self.__session._callback()
+ keys = get_keyring()
+ self.assertEqual(2, keys.size())
+ (rcode, key) = keys.find(isc.dns.Name('key1'), self.__sha1name)
+ self.assertEqual(isc.dns.TSIGKeyRing.SUCCESS, rcode)
+ self.assertEqual(isc.dns.Name('key1'), key.get_key_name())
+ (rcode, key) = keys.find(isc.dns.Name('key3'), self.__md5name)
+ self.assertEqual(isc.dns.TSIGKeyRing.SUCCESS, rcode)
+ self.assertEqual(isc.dns.Name('key3'), key.get_key_name())
def test_update_bad(self):
"""
@@ -132,15 +177,17 @@ class TSIGKeyRingTest(unittest.TestCase):
"""
self.__session._data = ['key:MTIzNAo=:hmac-sha1']
self.__do_init()
- keys = keyring()
+ keys = get_keyring()
# Bad TSIG string
self.__session._data = ['key:this makes no sense:really']
self.assertRaises(isc.dns.InvalidParameter, self.__session._callback)
- self.assertEqual(keys, keyring())
+ self.assertEqual(keys, get_keyring())
# A duplicity
self.__session._data = ['key:MTIzNAo=:hmac-sha1', 'key:MTIzNAo=:hmac-sha1']
self.assertRaises(AddError, self.__session._callback)
- self.assertEqual(keys, keyring())
+ self.assertEqual(keys, get_keyring())
if __name__ == "__main__":
+ isc.log.init("bind10") # FIXME Should this be needed?
+ isc.log.resetUnitTestRootLogger()
unittest.main()
diff --git a/src/lib/python/isc/server_common/tsig_keyring.py b/src/lib/python/isc/server_common/tsig_keyring.py
index 9d8f3c1..c743765 100644
--- a/src/lib/python/isc/server_common/tsig_keyring.py
+++ b/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):
"""
@@ -32,7 +35,7 @@ class Unexpected(Exception):
class AddError(Exception):
"""
Raised when a key can not be added. This usually means there's a
- duplicity.
+ duplicate.
"""
pass
@@ -45,12 +48,14 @@ class Updater:
Constructor. Pass the ccsession object so the key ring can be
downloaded.
"""
- self._session = session
- self._keyring = isc.dns.TSIGKeyRing()
- session.add_remote_config_by_name('tsig_keys', self._update)
- self._update()
+ 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)
+ self.__update()
- def _update(self, value=None, module_cfg=None):
+ def __update(self, value=None, module_cfg=None):
"""
Update the key ring by the configuration.
@@ -59,32 +64,36 @@ class Updater:
configuration plugin and not be allowed as far as here.
The parameters are there just to match the signature which
- the callback should have (eg. they are ignored).
+ the callback should have (i.e. they are ignored).
"""
- (data, default) = self._session.get_remote_config_value('tsig_keys',
- 'keys')
+ 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
keyring = isc.dns.TSIGKeyRing()
for key_data in data:
key = isc.dns.TSIGKey(key_data)
if keyring.add(key) != isc.dns.TSIGKeyRing.SUCCESS:
raise AddError("Can't add key " + str(key))
- self._keyring = keyring
+ self.__keyring = keyring
def get_keyring(self):
"""
Return the current key ring.
"""
- return self._keyring
+ return self.__keyring
def deinit(self):
"""
Unregister from getting updates. The object will not be
usable any more after this.
"""
- self._session.remove_remote_config('tsig_keys')
+ logger.debug(logger.DBGLVL_TRACE_BASIC,
+ PYSERVER_COMMON_TSIG_KEYRING_DEINIT)
+ self.__session.remove_remote_config('tsig_keys')
-def keyring():
+def get_keyring():
"""
Get the current key ring. You need to call init_keyring first.
"""
More information about the bind10-changes
mailing list