Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
fb20b8bb
Commit
fb20b8bb
authored
Jan 19, 2012
by
Michal 'vorner' Vaner
Browse files
[1454] Various minor tweaks based on review
Like renaming variables, rewording comments, improving log messages.
parent
0458ade8
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/bin/ddns/ddns.py.in
View file @
fb20b8bb
...
...
@@ -35,7 +35,7 @@ import signal
isc.log.init("b10-ddns")
logger = isc.log.Logger("ddns")
DBG_ACTIVITY
= logger.DBGLVL_TRACE_BASIC
TRACE_BASIC
= logger.DBGLVL_TRACE_BASIC
DATA_PATH = bind10_config.DATA_PATH
if "B10_FROM_SOURCE" in os.environ:
...
...
@@ -89,8 +89,8 @@ class DDNSServer:
self._config_data = self._cc.get_full_config()
self._cc.start()
self._shutdown = False
# List of the sessions where we get the
packe
ts
self._sock
et_
sessions = {}
# List of the session
receiver
s where we get the
reques
ts
self._socksession
_receiver
s = {}
def config_handler(self, new_config):
'''Update config data.'''
...
...
@@ -137,38 +137,38 @@ class DDNSServer:
"""
socket = self._listen_socket.accept()
fileno = socket.fileno()
logger.debug(
DBG_ACTIVITY
, DDNS_NEW_CONN, fileno)
session
= isc.util.io.socketsession.SocketSessionReceiver(socket)
self._sock
et_
sessions[fileno] = (socket,
session
)
logger.debug(
TRACE_BASIC
, DDNS_NEW_CONN, fileno
, socket.getpeername()
)
receiver
= isc.util.io.socketsession.SocketSessionReceiver(socket)
self._socksession
_receiver
s[fileno] = (socket,
receiver
)
def handle_request(self, request):
"""
This is called whenever a new DDNS request comes. Here the magic
happens, the rest is either subroutines of the magic or the accounting
around it that calls it from time to time.
This is the place where the actual DDNS processing is done. Other
methods are either subroutines of this method or methods doing the
uninteresting "accounting" stuff, like accepting socket,
initialization, etc.
It is called with the request being session as received from
SocketSessionReceiver, e
g
. tuple
SocketSessionReceiver,
i.
e. tuple
(socket, local_address, remote_address, data).
"""
# TODO: Implement the magic
pass
def handle_
incoming
(self, fileno):
def handle_
session
(self, fileno):
"""
Handle incoming event on the socket with given fileno.
"""
logger.debug(
DBG_ACTIVITY, DDNS_INCOMING
, fileno)
(socket,
session
) = self._sock
et_
sessions[fileno]
logger.debug(
TRACE_BASIC, DDNS_SESSION
, fileno)
(socket,
receiver
) = self._socksession
_receiver
s[fileno]
try:
request = session.pop()
self.handle_request(request)
self.handle_request(receiver.pop())
except isc.util.io.socketsession.SocketSessionError as se:
# No matter why this failed, the connection is in unknown, possibly
# broken state. So, we close the socket and remove the
session
.
# broken state. So, we close the socket and remove the
receiver
.
logger.warn(DDNS_DROP_CONN, fileno, se)
del self._socket_sessions[fileno]
socket.close()
del self._socksession_receivers[fileno]
def run(self):
'''
...
...
@@ -203,7 +203,7 @@ class DDNSServer:
elif fileno == listen_fileno:
self.accept()
else:
self.handle_
incoming
(fileno)
self.handle_
session
(fileno)
self.shutdown_cleanup()
logger.info(DDNS_STOPPED)
...
...
src/bin/ddns/ddns_messages.mes
View file @
fb20b8bb
...
...
@@ -39,11 +39,6 @@ authoritative server shuts down, the connection would get closed. It also
can mean the system is busy and can't keep up or that the other side got
confused and sent bad data.
% DDNS_INCOMING incoming activity on file descriptor %1
A debug message, informing there's some activity on the given file descriptor.
It will be either a request or the file descriptor will be closed. See
following log messages to see what of it.
% DDNS_MODULECC_SESSION_ERROR error encountered by configuration/command module: %1
There was a problem in the lower level module handling configuration and
control commands. This could happen for various reasons, but the most likely
...
...
@@ -51,9 +46,11 @@ cause is that the configuration database contains a syntax error and ddns
failed to start at initialization. A detailed error message from the module
will also be displayed.
% DDNS_NEW_CONN new connection on file descriptor %1
% DDNS_NEW_CONN new connection on file descriptor %1
from %2
Debug message. We received a connection and we are going to start handling
requests from it.
requests from it. The file descriptor number and the address where the request
comes from is logged. The connection is over a unix domain socket and is likely
coming from a b10-auth process.
% DDNS_RECEIVED_SHUTDOWN_COMMAND shutdown command received
The ddns process received a shutdown command from the command channel
...
...
@@ -63,6 +60,11 @@ and will now shut down.
The ddns process has successfully started and is now ready to receive commands
and updates.
% DDNS_SESSION session arrived on file descriptor %1
A debug message, informing there's some activity on the given file descriptor.
It will be either a request or the file descriptor will be closed. See
following log messages to see what of it.
% DDNS_SHUTDOWN ddns server shutting down
The ddns process is shutting down. It will no longer listen for new commands
or updates. Any command or update that is being addressed at this moment will
...
...
src/bin/ddns/tests/ddns_test.py
View file @
fb20b8bb
...
...
@@ -25,16 +25,18 @@ import isc.util.io.socketsession
class
FakeSocket
:
"""
A fake socket. It only provides a file number.
A fake socket. It only provides a file number
, peer name and accept method
.
"""
def
__init__
(
self
,
fileno
):
self
.
__fileno
=
fileno
def
fileno
(
self
):
return
self
.
__fileno
def
getpeername
(
self
):
return
"fake_unix_socket"
def
accept
(
self
):
return
FakeSocket
(
self
.
__fileno
+
1
)
class
FakeSession
:
class
FakeSession
Receiver
:
"""
A fake socket session receiver, for our tests.
"""
...
...
@@ -96,7 +98,7 @@ class TestDDNSServer(unittest.TestCase):
cc_session
=
MyCCSession
()
self
.
assertFalse
(
cc_session
.
_started
)
self
.
ddns_server
=
ddns
.
DDNSServer
(
cc_session
)
self
.
cc_session
=
cc_session
self
.
__
cc_session
=
cc_session
self
.
assertTrue
(
cc_session
.
_started
)
self
.
__select_expected
=
None
self
.
__select_answer
=
None
...
...
@@ -184,7 +186,7 @@ class TestDDNSServer(unittest.TestCase):
Test the check_command is called when there's something on the
socket.
"""
self
.
cc_session
.
check_command
=
self
.
__hook
self
.
__
cc_session
.
check_command
=
self
.
__hook
self
.
__select_expected
=
([
1
,
2
],
[],
[],
None
)
self
.
__select_answer
=
([
1
],
[],
[])
self
.
ddns_server
.
run
()
...
...
@@ -200,25 +202,30 @@ class TestDDNSServer(unittest.TestCase):
Test that we can accept a new connection.
"""
# There's nothing before the accept
ddns
.
isc
.
util
.
io
.
socketsession
.
SocketSessionReceiver
=
FakeSession
self
.
assertEqual
({},
self
.
ddns_server
.
_socket_sessions
)
ddns
.
isc
.
util
.
io
.
socketsession
.
SocketSessionReceiver
=
\
FakeSessionReceiver
self
.
assertEqual
({},
self
.
ddns_server
.
_socksession_receivers
)
self
.
ddns_server
.
accept
()
# Now the new socket session receiver is stored in the dict
self
.
assertEqual
([
3
],
list
(
self
.
ddns_server
.
_socket_sessions
.
keys
()))
(
socket
,
session
)
=
self
.
ddns_server
.
_socket_sessions
[
3
]
# The 3 comes from _listen_socket.accept() - _listen_socket has
# fileno 2 and accept returns socket with fileno increased by one.
self
.
assertEqual
([
3
],
list
(
self
.
ddns_server
.
_socksession_receivers
.
keys
()))
(
socket
,
receiver
)
=
self
.
ddns_server
.
_socksession_receivers
[
3
]
self
.
assertTrue
(
isinstance
(
socket
,
FakeSocket
))
self
.
assertEqual
(
3
,
socket
.
fileno
())
self
.
assertTrue
(
isinstance
(
session
,
FakeSession
))
self
.
assertEqual
(
socket
,
session
.
socket
())
self
.
assertTrue
(
isinstance
(
receiver
,
FakeSession
Receiver
))
self
.
assertEqual
(
socket
,
receiver
.
socket
())
def
test_incoming_called
(
self
):
"""
Test the run calls handle_
incoming
when there's something on the
Test the run calls handle_
session
when there's something on the
socket.
"""
socket
=
FakeSocket
(
3
)
self
.
ddns_server
.
_socket_sessions
=
{
3
:
(
socket
,
FakeSession
(
socket
))}
self
.
ddns_server
.
handle_incoming
=
self
.
__hook
self
.
ddns_server
.
_socksession_receivers
=
\
{
3
:
(
socket
,
FakeSessionReceiver
(
socket
))}
self
.
ddns_server
.
handle_session
=
self
.
__hook
self
.
__select_expected
=
([
1
,
2
,
3
],
[],
[],
None
)
self
.
__select_answer
=
([
3
],
[],
[])
self
.
ddns_server
.
run
()
...
...
@@ -226,47 +233,47 @@ class TestDDNSServer(unittest.TestCase):
self
.
assertIsNone
(
self
.
__select_answer
)
self
.
assertEqual
(
3
,
self
.
__hook_called
)
def
test_handle_
incoming
_ok
(
self
):
def
test_handle_
session
_ok
(
self
):
"""
Test the handle_
incoming
pops the
session
and calls handle_request
Test the handle_
session
pops the
receiver
and calls handle_request
when everything is OK.
"""
socket
=
FakeSocket
(
3
)
session
=
FakeSession
(
socket
)
receiver
=
FakeSession
Receiver
(
socket
)
# It doesn't really matter what data we use here, it is only passed
# through the code
param
=
(
FakeSocket
(
4
),
(
'127.0.0.1'
,
1234
),
(
'127.0.0.1'
,
1235
),
'Some data'
)
def
pop
():
return
param
# Prepare data into the
session
session
.
pop
=
pop
self
.
ddns_server
.
_sock
et_
sessions
=
{
3
:
(
socket
,
session
)}
# Prepare data into the
receiver
receiver
.
pop
=
pop
self
.
ddns_server
.
_socksession
_receiver
s
=
{
3
:
(
socket
,
receiver
)}
self
.
ddns_server
.
handle_request
=
self
.
__hook
# Call it
self
.
ddns_server
.
handle_
incoming
(
3
)
self
.
ddns_server
.
handle_
session
(
3
)
# The popped data are passed into the handle_request
self
.
assertEqual
(
param
,
self
.
__hook_called
)
# The
session
s are kept the same
self
.
assertEqual
({
3
:
(
socket
,
session
)},
self
.
ddns_server
.
_sock
et_
sessions
)
# The
receiver
s are kept the same
self
.
assertEqual
({
3
:
(
socket
,
receiver
)},
self
.
ddns_server
.
_socksession
_receiver
s
)
def
test_handle_
incoming
_fail
(
self
):
def
test_handle_
session
_fail
(
self
):
"""
Test the handle_
incoming
removes (and closes) the socket and
session
when the
session
complains.
Test the handle_
session
removes (and closes) the socket and
receiver
when the
receiver
complains.
"""
socket
=
FakeSocket
(
3
)
session
=
FakeSession
(
socket
)
receiver
=
FakeSession
Receiver
(
socket
)
def
pop
():
raise
isc
.
util
.
io
.
socketsession
.
SocketSessionError
(
'Test error'
)
session
.
pop
=
pop
receiver
.
pop
=
pop
socket
.
close
=
self
.
__hook
self
.
__hook_called
=
False
self
.
ddns_server
.
_sock
et_
sessions
=
{
3
:
(
socket
,
session
)}
self
.
ddns_server
.
handle_
incoming
(
3
)
# The "dead"
session
is removed
self
.
assertEqual
({},
self
.
ddns_server
.
_sock
et_
sessions
)
self
.
ddns_server
.
_socksession
_receiver
s
=
{
3
:
(
socket
,
receiver
)}
self
.
ddns_server
.
handle_
session
(
3
)
# The "dead"
receiver
is removed
self
.
assertEqual
({},
self
.
ddns_server
.
_socksession
_receiver
s
)
# Close is called with no parameter, so the default None
self
.
assertIsNone
(
self
.
__hook_called
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment