From: Mukund Sivaraman Date: Fri, 21 Jun 2013 13:51:54 +0000 (+0530) Subject: [2855] Add BIND10Server._shutdown_module() method for shutdown processing X-Git-Tag: bind10-1.2.0beta1-release~371^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=489316fd7418436e94de387ce9477c18e2b4da59;p=thirdparty%2Fkea.git [2855] Add BIND10Server._shutdown_module() method for shutdown processing --- diff --git a/src/lib/python/isc/server_common/bind10_server.py.in b/src/lib/python/isc/server_common/bind10_server.py.in index 89e051d275..f46d7724c3 100644 --- a/src/lib/python/isc/server_common/bind10_server.py.in +++ b/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. diff --git a/src/lib/python/isc/server_common/tests/bind10_server_test.py b/src/lib/python/isc/server_common/tests/bind10_server_test.py index 45d84f801a..f93eed6395 100755 --- a/src/lib/python/isc/server_common/tests/bind10_server_test.py +++ b/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)