# really necessary, but this is done to reflect that boss is also
# 'just' a module.
if self.ccs is not None:
- self.ccs.stop()
+ self.ccs.send_stopping()
# try using the BIND 10 request to stop
try:
elif command == ccsession.COMMAND_SHUTDOWN:
#When cmdctl get 'shutdown' command from boss,
#shutdown the outer httpserver.
- self._module_cc.stop()
+ self._module_cc.send_stopping()
self._httpserver.shutdown()
self._serving = False
Currently, it only causes the ModuleCCSession to send a message that
this module is stopping.
'''
- self._cc.stop()
+ self._cc.send_stopping()
def accept(self):
"""
'''Called by DDNSServer initialization, but not used in tests'''
self._started = True
- def stop(self):
+ def send_stopping(self):
'''Called by shutdown code'''
self._stopped = True
while self.running:
self.mccs.check_command(False)
finally:
- self.mccs.stop()
+ self.mccs.send_stopping()
def config_handler(self, new_config):
"""
"""Closes a ModuleCCSession object"""
if self.mccs is None:
return
- self.mccs.stop()
+ self.mccs.send_stopping()
logger.debug(DBG_STATHTTPD_INIT, STATHTTPD_CLOSING_CC_SESSION)
self.mccs.close()
import sys
import io
from isc.testutils.tsigctx_mock import MockTSIGContext
+from isc.testutils.ccsession_mock import MockModuleCCSession
from isc.testutils.rrset_utils import *
from xfrin import *
import xfrin
class XfrinTestTimeoutException(Exception):
pass
-class MockCC():
- def __init__(self):
- self.stop_called = False
-
+class MockCC(MockModuleCCSession):
def get_default_value(self, identifier):
# The returned values should be identical to the spec file
# XXX: these should be retrieved from the spec file
if identifier == "zones/use_ixfr":
return False
- def stop(self):
- self.stop_called = True
-
class MockDataSourceClient():
'''A simple mock data source client.
self.args['tsig_key'] = ''
def tearDown(self):
- self.assertFalse(self.xfr._module_cc.stop_called);
+ self.assertFalse(self.xfr._module_cc.stopped);
self.xfr.shutdown()
- self.assertTrue(self.xfr._module_cc.stop_called);
+ self.assertTrue(self.xfr._module_cc.stopped);
sys.stderr= self.stderr_backup
def _do_parse_zone_name_class(self):
''' shutdown the xfrin process. the thread which is doing xfrin should be
terminated.
'''
- self._module_cc.stop()
+ self._module_cc.send_stopping()
self._shutdown_event.set()
main_thread = threading.currentThread()
for th in threading.enumerate():
global xfrout_server
xfrout_server = None #Avoid shutdown is called twice
- self._cc.stop()
+ self._cc.send_stopping()
self._shutdown_event.set()
self._notifier.shutdown()
if self._unix_socket_server:
import os
import tempfile
from zonemgr import *
+from isc.testutils.ccsession_mock import MockModuleCCSession
ZONE_NAME_CLASS1_IN = ("example.net.", "IN")
ZONE_NAME_CLASS1_CH = ("example.net.", "CH")
def group_recvmsg(self, nonblock, seq):
return None, None
-class FakeCCSession(isc.config.ConfigData):
+class FakeCCSession(isc.config.ConfigData, MockModuleCCSession):
def __init__(self):
module_spec = isc.config.module_spec_from_file(SPECFILE_LOCATION)
ConfigData.__init__(self, module_spec)
+ MockModuleCCSession.__init__(self)
def get_remote_config_value(self, module_name, identifier):
if module_name == "Auth" and identifier == "database_file":
self.zonemgr._config_data_check(config_data3)
self.assertEqual(0.5, config_data3.get("refresh_jitter"))
+ def test_shutdown(self):
+ self.assertFalse(self.zonemgr._module_cc.stopped)
+ self.zonemgr._shutdown_event.set()
+ self.zonemgr.run()
+ self.assertTrue(self.zonemgr._module_cc.stopped)
+
def tearDown(self):
pass
def run(self):
self.running = True
- while not self._shutdown_event.is_set():
- self._module_cc.check_command(False)
+ try:
+ while not self._shutdown_event.is_set():
+ self._module_cc.check_command(False)
+ finally:
+ self._module_cc.send_stopping()
zonemgrd = None
self.__send_spec()
self.__request_config()
- def stop(self):
- """Inform the system that the module using this ModuleCCSession
- is stopping. This call will only cause a 'stopping'
- message to be sent to the ConfigManager, it does not clear or
- free any resources."""
- self.__send_stopping()
+ def send_stopping(self):
+ """Sends a 'stopping' message to the configuration manager. This
+ message is just an FYI, and no response is expected. Any errors
+ when sending this message (for instance if the msgq session has
+ previously been closed) are logged, but ignored."""
+ msg = create_command(COMMAND_MODULE_STOPPING,
+ self.get_module_spec().get_full_spec())
+ try:
+ self._session.group_sendmsg(msg, "ConfigManager")
+ except isc.cc.session.SessionError as se:
+ # If the session was previously closed, obvously trying to send
+ # a message fails. (TODO: check if session is open so we can
+ # error on real problems?)
+ logger.error(CONFIG_SESSION_STOPPING_FAILED, str(se))
def get_socket(self):
"""Returns the socket from the command channel session. This
# TODO: log an error?
pass
- def __send_stopping(self):
- """Sends a 'stopping' message to the configuration manager. This
- message is just an FYI, and no response is expected. Any errors
- when sending this message (for instance if the msgq session has
- previously been closed) are logged, but ignored."""
- msg = create_command(COMMAND_MODULE_STOPPING,
- self.get_module_spec().get_full_spec())
- try:
- self._session.group_sendmsg(msg, "ConfigManager")
- except isc.cc.session.SessionError as se:
- # If the session was previously closed, obvously trying to send
- # a message fails. (TODO: check if session is open so we can
- # error on real problems?)
- logger.error(CONFIG_SESSION_STOPPING_FAILED, str(se))
-
def __request_config(self):
"""Asks the configuration manager for the current configuration, and call the config handler if set.
Raises a ModuleCCSessionError if there is no answer from the configuration manager"""
self.assertTrue("Spec1" in fake_session.subscriptions)
self.assertEqual(len(fake_session.message_queue), 0)
- mccs.stop()
+ mccs.send_stopping()
self.assertEqual(len(fake_session.message_queue), 1)
self.assertEqual({'command': ['stopping', {'module_name': 'Spec1'}]},
fake_session.get_message('ConfigManager', None))
self.stopped = False
self.closed = False
- def stop(self):
+ def send_stopping(self):
self.stopped = True
def close(self):