Browse Source

[2855] Add BIND10Server._shutdown_module() method for shutdown processing

Mukund Sivaraman 12 years ago
parent
commit
489316fd74

+ 11 - 0
src/lib/python/isc/server_common/bind10_server.py.in

@@ -54,6 +54,12 @@ class BIND10Server:
                      interest on remote modules, etc.  If it raises an
                      exception, the server will be immediately stopped.
                      Parameter: None, Return: None
+      _shutdown_module: can be optionally defined for module-specific
+                        finalization. This is called right before the
+                        module CC session is stopped. If it raises an
+                        exception, the server shutdown will still
+                        continue.
+                        Parameter: None, Return: None
 
     """
     # Will be set to True when the server should stop and shut down.
@@ -181,6 +187,7 @@ class BIND10Server:
                 # propagate it)
                 self._mod_cc.check_command(True)
 
+        self._shutdown_module()
         self._mod_cc.send_stopping()
 
     def _command_handler(self, cmd, args):
@@ -202,6 +209,10 @@ class BIND10Server:
         """The default implementation of the module specific initialization"""
         pass
 
+    def _shutdown_module(self):
+        """The default implementation of the module specific finalization"""
+        pass
+
     def watch_fileno(self, fileno, rcallback=None, wcallback=None, \
                          xcallback=None):
         """Register the fileno for the internal select() call.

+ 10 - 0
src/lib/python/isc/server_common/tests/bind10_server_test.py

@@ -166,6 +166,16 @@ class TestBIND10Server(unittest.TestCase):
         self.assertTrue(self.__server.shutdown)
         self.assertEqual((0, None), isc.config.parse_answer(answer))
 
+    def test_run_with_shutdown_module(self):
+        """Check run() with module specific shutdown method."""
+        self.shutdown_called = False
+        def check_called():
+            self.shutdown_called = True
+        self.__server.__shutdown = True
+        self.__server._shutdown_module = check_called
+        self.assertEqual(0, self.__server.run('test'))
+        self.assertTrue(self.shutdown_called)
+
     def test_other_command(self):
         self.__server._mod_command_handler = self.__server.mod_command_handler
         answer = self.__server._command_handler('other command', None)