2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 22:15:23 +00:00

[1451] address review comments

This commit is contained in:
Jelte Jansen
2011-12-15 16:16:50 +01:00
parent 2103ad2196
commit a593cb487f
4 changed files with 125 additions and 35 deletions

View File

@@ -31,12 +31,12 @@
b10-ddns \- Dynamic DNS update service b10-ddns \- Dynamic DNS update service
.SH "SYNOPSIS" .SH "SYNOPSIS"
.HP \w'\fBb10\-ddns\fR\ 'u .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" .SH "DESCRIPTION"
.PP .PP
The The
\fBb10\-ddns\fR \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) \fBbind10\fR(8)
boss process\&. When the boss process\&. When the
\fBb10\-auth\fR \fBb10\-auth\fR
@@ -54,13 +54,21 @@ will exit\&.
\fBb10\-ddns\fR \fBb10\-ddns\fR
receives its configurations from receives its configurations from
\fBb10-cfgmgr\fR(8)\&. \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" .SH "CONFIGURATION AND COMMANDS"
.PP .PP
The configurable settings are: The configurable settings are:
.PP .PP
\fITODO\fR \fIzones\fR
TODO 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 .PP
The module commands are: The module commands are:
.PP .PP

View File

@@ -44,15 +44,17 @@
<refsynopsisdiv> <refsynopsisdiv>
<cmdsynopsis> <cmdsynopsis>
<command>b10-ddns</command> <command>b10-ddns</command>
<arg><option>-v</option></arg> <group choice="opt">
<arg><option>--verbose</option></arg> <arg choice="plain"><option>-v</option></arg>
<arg choice="plain"><option>--verbose</option></arg>
</group>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
<refsect1> <refsect1>
<title>DESCRIPTION</title> <title>DESCRIPTION</title>
<para>The <command>b10-ddns</command> daemon provides the BIND 10 <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 Normally it is started by the
<citerefentry><refentrytitle>bind10</refentrytitle><manvolnum>8</manvolnum></citerefentry> <citerefentry><refentrytitle>bind10</refentrytitle><manvolnum>8</manvolnum></citerefentry>
boss process. boss process.
@@ -74,17 +76,41 @@
</para> </para>
</refsect1> </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> <refsect1>
<title>CONFIGURATION AND COMMANDS</title> <title>CONFIGURATION AND COMMANDS</title>
<para> <para>
The configurable settings are: The configurable settings are:
</para> </para>
<para> <para>
<varname>TODO</varname> <varname>zones</varname>
TODO 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> </para>
<!-- TODO: formating -->
<para> <para>
The module commands are: The module commands are:
</para> </para>

View File

@@ -35,7 +35,7 @@ logger = isc.log.Logger("ddns")
DATA_PATH = bind10_config.DATA_PATH DATA_PATH = bind10_config.DATA_PATH
if "B10_FROM_BUILD" in os.environ: 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" SPECFILE_LOCATION = DATA_PATH + "/ddns.spec"
@@ -75,14 +75,22 @@ class DDNSSession:
pass pass
class DDNSServer: class DDNSServer:
def __init__(self): def __init__(self, cc_session = None):
''' '''
Initialize the DDNS Server. Initialize the DDNS Server.
This sets up a ModuleCCSession for the BIND 10 system. 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.
''' '''
self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION, if cc_session is not None:
self.config_handler, self._cc = cc_session
self.command_handler) else:
self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION,
self.config_handler,
self.command_handler)
self._config_data = self._cc.get_full_config() self._config_data = self._cc.get_full_config()
self._cc.start() self._cc.start()
self._shutdown = False self._shutdown = False
@@ -102,7 +110,7 @@ class DDNSServer:
self.shutdown() self.shutdown()
answer = create_answer(0) answer = create_answer(0)
else: else:
answer = create_answer(1, "Unknown command:" + str(cmd)) answer = create_answer(1, "Unknown command: " + str(cmd))
return answer return answer
def shutdown(self): def shutdown(self):
@@ -122,18 +130,23 @@ class DDNSServer:
while not self._shutdown: while not self._shutdown:
self._cc.check_command(False) self._cc.check_command(False)
ddns_server = None def create_signal_handler(ddns_server):
def signal_handler(signal, frame):
''' '''
Handler for process signals. Since only signals to shut down are sent This creates a signal_handler for use in set_signal_handler, which
here, the actual signal is not checked and the server is simply shut shuts down the given DDNSServer (or any object that has a shutdown()
down. method)
''' '''
if ddns_server is not None: def signal_handler(signal, frame):
ddns_server.shutdown() '''
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). Sets the signal handler(s).
''' '''
@@ -152,13 +165,15 @@ if '__main__' == __name__:
parser = OptionParser() parser = OptionParser()
set_cmd_options(parser) set_cmd_options(parser)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
VERBOSE_MODE = options.verbose if options.verbose:
print("[b10-ddns] Warning: -v verbose option is ignored at this point.")
ddns_server = DDNSServer() ddns_server = DDNSServer()
set_signal_handler() logger.debug(10, DDNS_STOPPED_BY_KEYBOARD)
set_signal_handler(create_signal_handler(ddns_server))
ddns_server.run() ddns_server.run()
except KeyboardInterrupt: except KeyboardInterrupt:
logger.INFO(DDNS_STOPPED_BY_KEYBOARD) logger.info(DDNS_STOPPED_BY_KEYBOARD)
except SessionError as e: except SessionError as e:
logger.error(DDNS_CC_SESSION_ERROR, str(e)) logger.error(DDNS_CC_SESSION_ERROR, str(e))
except ModuleCCSessionError as e: except ModuleCCSessionError as e:
@@ -167,7 +182,3 @@ if '__main__' == __name__:
logger.error(DDNS_CONFIG_ERROR, str(e)) logger.error(DDNS_CONFIG_ERROR, str(e))
except SessionTimeout as e: except SessionTimeout as e:
logger.error(DDNS_CC_SESSION_TIMEOUT_ERROR) logger.error(DDNS_CC_SESSION_TIMEOUT_ERROR)
if ddns_server:
ddns_server.shutdown()

View File

@@ -17,10 +17,55 @@
import unittest import unittest
import isc import isc
import ddns
import isc.config
class TestInitialization(unittest.TestCase): class MyCCSession(isc.config.ConfigData):
def test_noop(self): '''Fake session with minimal interface compliance'''
self.assertTrue(True) 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__": if __name__== "__main__":
isc.log.resetUnitTestRootLogger() isc.log.resetUnitTestRootLogger()