]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[640] rename stop()
authorJelte Jansen <jelte@isc.org>
Thu, 2 Feb 2012 13:45:31 +0000 (14:45 +0100)
committerJelte Jansen <jelte@isc.org>
Thu, 2 Feb 2012 13:45:31 +0000 (14:45 +0100)
14 files changed:
src/bin/bind10/bind10_src.py.in
src/bin/cmdctl/cmdctl.py.in
src/bin/ddns/ddns.py.in
src/bin/ddns/tests/ddns_test.py
src/bin/stats/stats.py.in
src/bin/stats/stats_httpd.py.in
src/bin/xfrin/tests/xfrin_test.py
src/bin/xfrin/xfrin.py.in
src/bin/xfrout/xfrout.py.in
src/bin/zonemgr/tests/zonemgr_test.py
src/bin/zonemgr/zonemgr.py.in
src/lib/python/isc/config/ccsession.py
src/lib/python/isc/config/tests/ccsession_test.py
src/lib/python/isc/testutils/ccsession_mock.py

index 5c7dc9380ca6ca2705de66dabd50d9b3b88107ad..805275a060edbd68a230dc32a1b0496448623eb3 100755 (executable)
@@ -684,7 +684,7 @@ class BoB:
         # 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:
index ca3e1ea9ebff190e1d5e8ac284f2181546284abd..0628f1f1fe982db238d890df18b408a5c3262ac0 100755 (executable)
@@ -319,7 +319,7 @@ class CommandControl():
         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
 
index f13c1bb9f89bf69396435e8182f30369f8895dc5..22e4e9c49800e92352f0760efe9bcb30b6db1096 100755 (executable)
@@ -153,7 +153,7 @@ class DDNSServer:
         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):
         """
index e63ef34d1a0957faca94152312e8e7adccf5f032..395aacc512ab662c58e62a16b92d2cad1b5bb22d 100755 (executable)
@@ -64,7 +64,7 @@ class MyCCSession(isc.config.ConfigData):
         '''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
 
index a3612a2266f4ac56dab4c8cb79e2a5e1dd7089d8..537cf49e8e86f8e376668d441eb0da760469a696 100755 (executable)
@@ -188,7 +188,7 @@ class Stats:
             while self.running:
                 self.mccs.check_command(False)
         finally:
-            self.mccs.stop()
+            self.mccs.send_stopping()
 
     def config_handler(self, new_config):
         """
index 5afb4fbab81d60635c17ab23fb7d6e3dc48305fc..c9bd0f5c889f402cfbc68df9aee008fa10a737ea 100644 (file)
@@ -203,7 +203,7 @@ class StatsHttpd:
         """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()
index 99e0522cf3c3f2fec5fb103f8988dbf76dbc9868..89e4d9668fb56e183f8e94e3eb27c39aeb20ef14 100644 (file)
@@ -20,6 +20,7 @@ import socket
 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
@@ -105,10 +106,7 @@ class XfrinTestException(Exception):
 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
@@ -120,9 +118,6 @@ class MockCC():
         if identifier == "zones/use_ixfr":
             return False
 
-    def stop(self):
-        self.stop_called = True
-
 class MockDataSourceClient():
     '''A simple mock data source client.
 
@@ -2058,9 +2053,9 @@ class TestXfrin(unittest.TestCase):
         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):
index 0cd63c0ac449ddd5be449942de2063d3c0e012d7..b59c2b6c78c9cd71a278d33a8150b3f5f060df6b 100755 (executable)
@@ -1224,7 +1224,7 @@ class Xfrin:
         ''' 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():
index eb124c97bd7f21f0beed654a448416fdb2880f9b..1540e6b36f5bae0865bfc9d7c031d1180a360b68 100755 (executable)
@@ -969,7 +969,7 @@ class XfroutServer:
 
         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:
index 600453dd17f89d6449b34f4fa1d61440aa391b49..29924c81fb96f1d6a991c51093564effa89c3b16 100644 (file)
@@ -20,6 +20,7 @@ import unittest
 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")
@@ -48,10 +49,11 @@ class MySession():
     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":
@@ -683,6 +685,12 @@ class TestZonemgr(unittest.TestCase):
         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
 
index 4060bb59d618858f858c78481dac41556d2d3a53..7b16f1bf2acca373c14e4b57efb94230dc40afcd 100755 (executable)
@@ -658,8 +658,11 @@ class Zonemgr:
 
     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
 
index 10ebc1c4d71040d34cbf4011953269aa526810a5..476ba1e1d2156c21393f22a89d01db786912968e 100644 (file)
@@ -211,12 +211,20 @@ class ModuleCCSession(ConfigData):
         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
@@ -380,21 +388,6 @@ class ModuleCCSession(ConfigData):
             # 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"""
index 081d3e90145544b6fb5bf53092795de661b4aa56..df39550de4a1e78e125f2c129d17a04434ba14d0 100644 (file)
@@ -257,7 +257,7 @@ class TestModuleCCSession(unittest.TestCase):
         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))
index c974be9d77776a3e2ca8de079011c29f89c815e0..cc6020badb5ad33dfee38809b5b745d194a1caca 100644 (file)
@@ -19,7 +19,7 @@ class MockModuleCCSession():
         self.stopped = False
         self.closed = False
 
-    def stop(self):
+    def send_stopping(self):
         self.stopped = True
 
     def close(self):