Commit 2b0ef32a authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2676] Convert DDNS to use rpc_call

Just a straight-forward conversion.
parent 104a04b3
......@@ -32,7 +32,6 @@ import isc.util.cio.socketsession
import isc.server_common.tsig_keyring
from isc.server_common.dns_tcp import DNSTCPContext
from isc.datasrc import DataSourceClient
from isc.server_common.auth_command import auth_loadzone_command
import select
import time
import errno
......@@ -544,12 +543,9 @@ class DDNSServer:
def __notify_start_forwarder(self):
'''Notify auth that DDNS Update messages can now be forwarded'''
try:
seq = self._cc._session.group_sendmsg(create_command(
"start_ddns_forwarder"), AUTH_MODULE_NAME)
answer, _ = self._cc._session.group_recvmsg(False, seq)
rcode, error_msg = parse_answer(answer)
if rcode != 0:
logger.error(DDNS_START_FORWARDER_ERROR, error_msg)
self._cc.rpc_call("start_ddns_forwarder", AUTH_MODULE_NAME)
except RPCError as e:
logger.error(DDNS_START_FORWARDER_ERROR, e)
except (SessionTimeout, SessionError, ProtocolError) as ex:
logger.error(DDNS_START_FORWARDER_FAIL, ex)
......@@ -558,28 +554,25 @@ class DDNSServer:
'''
try:
seq = self._cc._session.group_sendmsg(create_command(
"stop_ddns_forwarder"), AUTH_MODULE_NAME)
answer, _ = self._cc._session.group_recvmsg(False, seq)
rcode, error_msg = parse_answer(answer)
if rcode != 0:
logger.error(DDNS_STOP_FORWARDER_ERROR, error_msg)
self._cc.rpc_call("stop_ddns_forwarder", AUTH_MODULE_NAME)
except RPCError as e:
logger.error(DDNS_STOP_FORWARDER_ERROR, e)
except (SessionTimeout, SessionError, ProtocolError) as ex:
logger.error(DDNS_STOP_FORWARDER_FAIL, ex)
def __notify_auth(self, zname, zclass):
'''Notify auth of the update, if necessary.'''
msg = auth_loadzone_command(self._cc, zname, zclass)
if msg is not None:
self.__notify_update(AUTH_MODULE_NAME, msg, zname, zclass)
param = {'origin': zname.to_text(), 'class': zclass.to_text()}
self.__notify_update(AUTH_MODULE_NAME, 'loadzone', param, zname,
zclass)
def __notify_xfrout(self, zname, zclass):
'''Notify xfrout of the update.'''
param = {'zone_name': zname.to_text(), 'zone_class': zclass.to_text()}
msg = create_command('notify', param)
self.__notify_update(XFROUT_MODULE_NAME, msg, zname, zclass)
self.__notify_update(XFROUT_MODULE_NAME, 'notify', param, zname,
zclass)
def __notify_update(self, modname, msg, zname, zclass):
def __notify_update(self, modname, command, params, zname, zclass):
'''Notify other module of the update.
Note that we use blocking communication here. While the internal
......@@ -599,18 +592,14 @@ class DDNSServer:
'''
try:
seq = self._cc._session.group_sendmsg(msg, modname)
answer, _ = self._cc._session.group_recvmsg(False, seq)
rcode, error_msg = parse_answer(answer)
except (SessionTimeout, SessionError, ProtocolError) as ex:
rcode = 1
error_msg = str(ex)
if rcode == 0:
# FIXME? Do we really need to wait for the answer here? Shouldn't
# this be some kind of notification instead?
self._cc.rpc_call(command, modname, params=params)
logger.debug(TRACE_BASIC, DDNS_UPDATE_NOTIFY, modname,
ZoneFormatter(zname, zclass))
else:
except (SessionTimeout, SessionError, ProtocolError, RPCError) as ex:
logger.error(DDNS_UPDATE_NOTIFY_FAIL, modname,
ZoneFormatter(zname, zclass), error_msg)
ZoneFormatter(zname, zclass), ex)
def handle_session(self, fileno):
"""Handle incoming session on the socket with given fileno.
......
......@@ -191,7 +191,7 @@ class FakeKeyringModule:
'''Simply return the predefined TSIG keyring unconditionally.'''
return TEST_TSIG_KEYRING
class MyCCSession(isc.config.ConfigData):
class MyCCSession(isc.config.ModuleCCSession):
'''Fake session with minimal interface compliance.'''
# faked CC sequence used in group_send/recvmsg
......@@ -276,7 +276,8 @@ class MyCCSession(isc.config.ConfigData):
'secondary_zones')
return seczone_default, True
def group_sendmsg(self, msg, group):
def group_sendmsg(self, msg, group, instance='*', to='*',
want_answer=False):
# remember the passed parameter, and return dummy sequence
self._sent_msg.append((msg, group))
if self._sendmsg_exception is not None:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment