BIND 10 trac1451, updated. a593cb487feceef36fc0d8f3670927c2f4e82cdc [1451] address review comments
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 15 15:17:01 UTC 2011
The branch, trac1451 has been updated
via a593cb487feceef36fc0d8f3670927c2f4e82cdc (commit)
via 2103ad2196d78f1a7b4105c38e976d9c20e4a12e (commit)
from 227a3a7be884c74c4a1189f0f3cc6ac77d7adaa7 (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 a593cb487feceef36fc0d8f3670927c2f4e82cdc
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Dec 15 16:16:50 2011 +0100
[1451] address review comments
commit 2103ad2196d78f1a7b4105c38e976d9c20e4a12e
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Dec 15 14:47:09 2011 +0100
[1451] address some of the review comments
-----------------------------------------------------------------------
Summary of changes:
src/bin/ddns/b10-ddns.8 | 16 ++++-
src/bin/ddns/b10-ddns.xml | 38 ++++++++++--
src/bin/ddns/ddns.py.in | 98 ++++++++++++++++++++----------
src/bin/ddns/tests/ddns_test.py | 51 +++++++++++++++-
tests/lettuce/setup_intree_bind10.sh.in | 2 +-
5 files changed, 158 insertions(+), 47 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/ddns/b10-ddns.8 b/src/bin/ddns/b10-ddns.8
index f0fbf01..d1e05d9 100644
--- a/src/bin/ddns/b10-ddns.8
+++ b/src/bin/ddns/b10-ddns.8
@@ -31,12 +31,12 @@
b10-ddns \- Dynamic DNS update service
.SH "SYNOPSIS"
.HP \w'\fBb10\-ddns\fR\ 'u
-\fBb10\-ddns\fR [\fB\-v\fR] [\fB\-\-verbose\fR]
+\fBb10\-ddns\fR [\fB\-v\fR | \fB\-\-verbose\fR]
.SH "DESCRIPTION"
.PP
The
\fBb10\-ddns\fR
-daemon provides the BIND 10 DDNS update service\&. Normally it is started by the
+daemon provides the BIND 10 Dynamic Update (DDNS) service, as specified in RFC 2136\&. Normally it is started by the
\fBbind10\fR(8)
boss process\&. When the
\fBb10\-auth\fR
@@ -54,13 +54,21 @@ will exit\&.
\fBb10\-ddns\fR
receives its configurations from
\fBb10-cfgmgr\fR(8)\&.
+.SH "ARGUMENTS"
+.PP
+The arguments are as follows:
+.PP
+\fB\-v\fR, \fB\-\-verbose\fR
+.RS 4
+This value is ignored at this moment, but is provided for compatibility with the bind10 Boss process
+.RE
.SH "CONFIGURATION AND COMMANDS"
.PP
The configurable settings are:
.PP
-\fITODO\fR
-TODO
+\fIzones\fR
+The zones option is a named set of zones that can be updated with DDNS\&. Each entry has one element called update_acls, which itself is a list of ACLs that define update permissions\&. By default this is empty; DDNS must be explicitely enabled per zone\&.
.PP
The module commands are:
.PP
diff --git a/src/bin/ddns/b10-ddns.xml b/src/bin/ddns/b10-ddns.xml
index efb7667..73bdbc2 100644
--- a/src/bin/ddns/b10-ddns.xml
+++ b/src/bin/ddns/b10-ddns.xml
@@ -44,15 +44,17 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>b10-ddns</command>
- <arg><option>-v</option></arg>
- <arg><option>--verbose</option></arg>
+ <group choice="opt">
+ <arg choice="plain"><option>-v</option></arg>
+ <arg choice="plain"><option>--verbose</option></arg>
+ </group>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>The <command>b10-ddns</command> daemon provides the BIND 10
- DDNS update service.
+ Dynamic Update (DDNS) service, as specified in RFC 2136.
Normally it is started by the
<citerefentry><refentrytitle>bind10</refentrytitle><manvolnum>8</manvolnum></citerefentry>
boss process.
@@ -75,16 +77,40 @@
</refsect1>
<refsect1>
+ <title>ARGUMENTS</title>
+
+ <para>The arguments are as follows:</para>
+
+ <variablelist>
+
+ <varlistentry>
+ <term>
+ <option>-v</option>,
+ <option>--verbose</option>
+ </term>
+ <listitem>
+ <para>
+ This value is ignored at this moment, but is provided for
+ compatibility with the bind10 Boss process
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
<title>CONFIGURATION AND COMMANDS</title>
<para>
The configurable settings are:
</para>
<para>
- <varname>TODO</varname>
- TODO
+ <varname>zones</varname>
+ The zones option is a named set of zones that can be updated with
+ DDNS. Each entry has one element called update_acls, which itself
+ is a list of ACLs that define update permissions.
+ By default this is empty; DDNS must be explicitely enabled per zone.
</para>
-<!-- TODO: formating -->
<para>
The module commands are:
</para>
diff --git a/src/bin/ddns/ddns.py.in b/src/bin/ddns/ddns.py.in
index 4a3c7b5..104d845 100755
--- a/src/bin/ddns/ddns.py.in
+++ b/src/bin/ddns/ddns.py.in
@@ -29,21 +29,20 @@ from isc.log_messages.ddns_messages import *
from optparse import OptionParser, OptionValueError
import os
import signal
-import threading
isc.log.init("b10-ddns")
logger = isc.log.Logger("ddns")
DATA_PATH = bind10_config.DATA_PATH
if "B10_FROM_BUILD" in os.environ:
- DATA_PATH = DATA_PATH + "/src/bin/ddns"
+ DATA_PATH = os.environ['B10_FROM_BUILD'] + "/src/bin/ddns"
SPECFILE_LOCATION = DATA_PATH + "/ddns.spec"
isc.util.process.rename()
class DDNSConfigError(Exception):
- """An exception indicating an error in updating ddns configuration.
+ '''An exception indicating an error in updating ddns configuration.
This exception is raised when the ddns process encounters an error in
handling configuration updates. Not all syntax error can be caught
@@ -51,7 +50,7 @@ class DDNSConfigError(Exception):
validate the given configuration data itself. When it finds an error
it raises this exception (either directly or by converting an exception
from other modules) as a unified error in configuration.
- """
+ '''
pass
class DDNSSessionError(Exception):
@@ -60,9 +59,10 @@ class DDNSSessionError(Exception):
pass
class DDNSSession:
- """Class to handle one DDNS update"""
+ '''Class to handle one DDNS update'''
def __init__(self):
+ '''Initialize a DDNS Session'''
self._handle()
def _handle(self):
@@ -75,13 +75,25 @@ class DDNSSession:
pass
class DDNSServer:
- def __init__(self):
- self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION,
- self.config_handler,
- self.command_handler)
+ def __init__(self, cc_session = None):
+ '''
+ Initialize the DDNS Server.
+ This sets up a ModuleCCSession for the BIND 10 system.
+ Parameters:
+ cc_session: If None (default), a new ModuleCCSession will be set up
+ If specified, the given session will be used. This is
+ mainly used for testing.
+ '''
+ if cc_session is not None:
+ self._cc = cc_session
+ else:
+ self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION,
+ self.config_handler,
+ self.command_handler)
+
self._config_data = self._cc.get_full_config()
self._cc.start()
- self._shutdown_event = threading.Event()
+ self._shutdown = False
def config_handler(self, new_config):
'''Update config data.'''
@@ -89,40 +101,62 @@ class DDNSServer:
return answer
def command_handler(self, cmd, args):
+ '''
+ Handle a CC session command, as sent from bindctl or other
+ BIND 10 modules.
+ '''
if cmd == "shutdown":
logger.info(DDNS_RECEIVED_SHUTDOWN_COMMAND)
self.shutdown()
answer = create_answer(0)
else:
- answer = create_answer(1, "Unknown command:" + str(cmd))
+ answer = create_answer(1, "Unknown command: " + str(cmd))
return answer
def shutdown(self):
- self._shutdown_event.set()
- main_thread = threading.currentThread()
- for th in threading.enumerate():
- if th is main_thread:
- continue
- th.join()
+ '''
+ Shut down the server. Perform any cleanup that is necessary.
+ Currently, this only sets the internal _shutdown value to true,
+ so the main loop in run() stops.
+ '''
+ self._shutdown = True
def run(self):
- '''Get and process all commands sent from cfgmgr or other modules. '''
+ '''
+ Get and process all commands sent from cfgmgr or other modules.
+ This loops waiting for events until self.shutdown() has been called.
+ '''
logger.info(DDNS_RUNNING)
- while not self._shutdown_event.is_set():
+ while not self._shutdown:
self._cc.check_command(False)
-ddns_server = None
-
-def signal_handler(signal, frame):
- if ddns_server is not None:
- ddns_server.shutdown()
- sys.exit(0)
+def create_signal_handler(ddns_server):
+ '''
+ This creates a signal_handler for use in set_signal_handler, which
+ shuts down the given DDNSServer (or any object that has a shutdown()
+ method)
+ '''
+ def signal_handler(signal, frame):
+ '''
+ Handler for process signals. Since only signals to shut down are sent
+ here, the actual signal is not checked and the server is simply shut
+ down.
+ '''
+ if ddns_server is not None:
+ ddns_server.shutdown()
+ return signal_handler
-def set_signal_handler():
+def set_signal_handler(signal_handler):
+ '''
+ Sets the signal handler(s).
+ '''
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
def set_cmd_options(parser):
+ '''
+ Helper function to set command-line options
+ '''
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display more about what is going on")
@@ -131,13 +165,15 @@ if '__main__' == __name__:
parser = OptionParser()
set_cmd_options(parser)
(options, args) = parser.parse_args()
- VERBOSE_MODE = options.verbose
+ if options.verbose:
+ print("[b10-ddns] Warning: -v verbose option is ignored at this point.")
- set_signal_handler()
ddns_server = DDNSServer()
+ logger.debug(10, DDNS_STOPPED_BY_KEYBOARD)
+ set_signal_handler(create_signal_handler(ddns_server))
ddns_server.run()
except KeyboardInterrupt:
- logger.INFO(DDNS_STOPPED_BY_KEYBOARD)
+ logger.info(DDNS_STOPPED_BY_KEYBOARD)
except SessionError as e:
logger.error(DDNS_CC_SESSION_ERROR, str(e))
except ModuleCCSessionError as e:
@@ -146,7 +182,3 @@ if '__main__' == __name__:
logger.error(DDNS_CONFIG_ERROR, str(e))
except SessionTimeout as e:
logger.error(DDNS_CC_SESSION_TIMEOUT_ERROR)
-
- if ddns_server:
- ddns_server.shutdown()
-
diff --git a/src/bin/ddns/tests/ddns_test.py b/src/bin/ddns/tests/ddns_test.py
index 141944b..e18a990 100755
--- a/src/bin/ddns/tests/ddns_test.py
+++ b/src/bin/ddns/tests/ddns_test.py
@@ -17,10 +17,55 @@
import unittest
import isc
+import ddns
+import isc.config
-class TestInitialization(unittest.TestCase):
- def test_noop(self):
- self.assertTrue(True)
+class MyCCSession(isc.config.ConfigData):
+ '''Fake session with minimal interface compliance'''
+ def __init__(self):
+ module_spec = isc.config.module_spec_from_file(
+ ddns.SPECFILE_LOCATION)
+ isc.config.ConfigData.__init__(self, module_spec)
+ self._started = False
+
+ def start(self):
+ '''Called by DDNSServer initialization, but not used in tests'''
+ self._started = True
+
+class TestDDNSServer(unittest.TestCase):
+ def setUp(self):
+ cc_session = MyCCSession()
+ self.assertFalse(cc_session._started)
+ self.ddns_server = ddns.DDNSServer(cc_session)
+ self.assertTrue(cc_session._started)
+
+ def test_config_handler(self):
+ # Config handler does not do anything yet, but should at least
+ # return 'ok' for now.
+ new_config = {}
+ answer = self.ddns_server.config_handler(new_config)
+ self.assertEqual((0, None), isc.config.parse_answer(answer))
+
+ def test_shutdown_command(self):
+ '''Test whether the shutdown command works'''
+ self.assertFalse(self.ddns_server._shutdown)
+ answer = self.ddns_server.command_handler('shutdown', None)
+ self.assertEqual((0, None), isc.config.parse_answer(answer))
+ self.assertTrue(self.ddns_server._shutdown)
+
+ def test_command_handler(self):
+ '''Test some commands.'''
+ # this command should not exist
+ answer = self.ddns_server.command_handler('bad_command', None)
+ self.assertEqual((1, 'Unknown command: bad_command'),
+ isc.config.parse_answer(answer))
+
+ def test_signal_handler(self):
+ '''Test whether signal_handler calls shutdown()'''
+ signal_handler = ddns.create_signal_handler(self.ddns_server)
+ self.assertFalse(self.ddns_server._shutdown)
+ signal_handler(None, None)
+ self.assertTrue(self.ddns_server._shutdown)
if __name__== "__main__":
isc.log.resetUnitTestRootLogger()
diff --git a/tests/lettuce/setup_intree_bind10.sh.in b/tests/lettuce/setup_intree_bind10.sh.in
index 40fd82d..b1f17bc 100755
--- a/tests/lettuce/setup_intree_bind10.sh.in
+++ b/tests/lettuce/setup_intree_bind10.sh.in
@@ -20,7 +20,7 @@ export PYTHON_EXEC
BIND10_PATH=@abs_top_builddir@/src/bin/bind10
-PATH=@abs_top_builddir@/src/bin/bind10:@abs_top_builddir@/src/bin/bindctl:@abs_top_builddir@/src/bin/msgq:@abs_top_builddir@/src/bin/auth:@abs_top_builddir@/src/bin/resolver:@abs_top_builddir@/src/bin/cfgmgr:@abs_top_builddir@/src/bin/cmdctl:@abs_top_builddir@/src/bin/stats:@abs_top_builddir@/src/bin/xfrin:@abs_top_builddir@/src/bin/xfrout:@abs_top_builddir@/src/bin/zonemgr:@abs_top_builddir@/src/bin/dhcp6:@abs_top_builddir@/src/bin/sockcreator:$PATH
+PATH=@abs_top_builddir@/src/bin/bind10:@abs_top_builddir@/src/bin/bindctl:@abs_top_builddir@/src/bin/msgq:@abs_top_builddir@/src/bin/auth:@abs_top_builddir@/src/bin/resolver:@abs_top_builddir@/src/bin/cfgmgr:@abs_top_builddir@/src/bin/cmdctl:@abs_top_builddir@/src/bin/stats:@abs_top_builddir@/src/bin/xfrin:@abs_top_builddir@/src/bin/xfrout:@abs_top_builddir@/src/bin/zonemgr:@abs_top_builddir@/src/bin/ddns:@abs_top_builddir@/src/bin/dhcp6:@abs_top_builddir@/src/bin/sockcreator:$PATH
export PATH
PYTHONPATH=@abs_top_builddir@/src/bin:@abs_top_builddir@/src/lib/python/isc/log_messages:@abs_top_builddir@/src/lib/python:@abs_top_builddir@/src/lib/dns/python/.libs:@abs_top_builddir@/src/lib/xfr/.libs:@abs_top_builddir@/src/lib/log/.libs:@abs_top_builddir@/src/lib/util/io/.libs:@abs_top_builddir@/src/lib/python/isc/config:@abs_top_builddir@/src/lib/python/isc/acl/.libs:@abs_top_builddir@/src/lib/python/isc/datasrc/.libs
More information about the bind10-changes
mailing list