Parcourir la source

[2854] added to BIND10Server a hook for module-specific initialization.

JINMEI Tatuya il y a 12 ans
Parent
commit
94f2a0246e

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

@@ -48,6 +48,12 @@ class BIND10Server:
                             command handlers as specified in ModuleCCSession.
                             must be exception free; errors should be signaled
                             by the return value.
+      _setup_module: can be optionally defined for module-specific
+                     initialization.  This is called after the module CC
+                     session has started, and can be used for registering
+                     interest on remote modules, etc.  If it raises an
+                     exception, the server will be immediatelly stopped.
+                     Parameter: None, Return: None
 
     """
     # Will be set to True when the server should stop and shut down.
@@ -160,6 +166,10 @@ class BIND10Server:
         """The default implementation of the module specific command handler"""
         return isc.config.create_answer(1, "Unknown command: " + str(cmd))
 
+    def _setup_module(self):
+        """The default implementation of the module specific initilization"""
+        pass
+
     def run(self, module_name):
         """Start the server and let it run until it's told to stop.
 
@@ -183,6 +193,7 @@ class BIND10Server:
             signal.signal(signal.SIGTERM, shutdown_sighandler)
             signal.signal(signal.SIGINT, shutdown_sighandler)
             self._setup_ccsession()
+            self._setup_module()
             self._run_internal()
             logger.info(PYSERVER_COMMON_SERVER_STOPPED, self.__module_name)
             return 0

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

@@ -145,6 +145,16 @@ class TestBIND10Server(unittest.TestCase):
         self.assertEqual(self.__server.mod_ccsession.command_handler_param,
                          self.__server._command_handler)
 
+    def test_run_with_setup_module(self):
+        """Check run() with module specific setup method."""
+        self.setup_called = False
+        def check_called():
+            self.setup_called = True
+        self.__server._run_internal = lambda: None
+        self.__server._setup_module = check_called
+        self.assertEqual(0, self.__server.run('test'))
+        self.assertTrue(self.setup_called)
+
     def test_shutdown_command(self):
         answer = self.__server._command_handler('shutdown', None)
         self.assertTrue(self.__server.shutdown)