Browse Source

[2854] complete _setup_module() with adding datasrc config.

JINMEI Tatuya 12 years ago
parent
commit
a66549d445

+ 15 - 2
src/bin/memmgr/memmgr.py.in

@@ -22,8 +22,9 @@ import signal
 sys.path.append('@@PYTHONPATH@@')
 import isc.log
 #from isc.log import DBGLVL_TRACE_BASIC
+from isc.config import ModuleSpecError, ModuleCCSessionError
 from isc.log_messages.memmgr_messages import *
-from isc.server_common.bind10_server import BIND10Server
+from isc.server_common.bind10_server import BIND10Server, BIND10ServerFatal
 
 MODULE_NAME = 'memmgr'
 
@@ -95,7 +96,19 @@ class Memmgr(BIND10Server):
 
     def _setup_module(self):
         """Module specific initialization for BIND10Server."""
-        pass
+        try:
+            # memmgr isn't usable if data source is not configured, and
+            # as long as cfgmgr is ready there's no timing issue.  So we
+            # immediately shut it down if it's missing.  See ddns.py.in
+            # about exceptions to catch.
+            self.mod_ccsession.add_remote_config_by_name(
+                'data_sources', self._datasrc_config_handler)
+        except (ModuleSpecError, ModuleCCSessionError) as ex:
+            logger.error(MEMMGR_NO_DATASRC_CONF, ex)
+            raise BIND10ServerFatal('failed to setup memmgr module')
+
+    def _datasrc_config_handler(self, new_config, config_data):
+        return
 
 if '__main__' == __name__:
     mgr = Memmgr()

+ 7 - 0
src/bin/memmgr/memmgr_messages.mes

@@ -24,3 +24,10 @@ updates applied, and the daemon keeps running with the previous configuration.
 % MEMMGR_CONFIG_UPDATE received new configuration
 A debug message.  The memmgr daemon receives configuratiopn updates
 and is now applying them to its running configurations.
+
+% MEMMGR_NO_DATASRC_CONF failed to add data source configuration: %1
+The memmgr daemon tried to incorporate data source configuration
+on its startup but failed to do so.  The most likely cause of this
+is that data sources are not simply configured.  If so, they must be.
+The memmgr daemon cannot do any meaningful work without data sources,
+so it immediately terminates itself.

+ 28 - 0
src/bin/memmgr/tests/memmgr_test.py

@@ -29,10 +29,17 @@ class MyCCSession(MockModuleCCSession, isc.config.ConfigData):
         specfile = os.environ['B10_FROM_BUILD'] + '/src/bin/memmgr/memmgr.spec'
         module_spec = isc.config.module_spec_from_file(specfile)
         isc.config.ConfigData.__init__(self, module_spec)
+        self.add_remote_params = [] # for inspection
+        self.add_remote_exception = None # to raise exception from the method
 
     def start(self):
         pass
 
+    def add_remote_config_by_name(self, mod_name, handler):
+        if self.add_remote_exception is not None:
+            raise self.add_remote_exception
+        self.add_remote_params.append((mod_name, handler))
+
 class MockMemmgr(memmgr.Memmgr):
     def _setup_ccsession(self):
         orig_cls = isc.config.ModuleCCSession
@@ -106,6 +113,27 @@ class TestMemmgr(unittest.TestCase):
         self.assertEqual(1, answer[0])
         self.assertIsNotNone(re.search('not writable', answer[1]))
 
+    def test_setup_module(self):
+        # _setup_module should add data_sources remote module with
+        # expected parameters.
+        self.__mgr._setup_ccsession()
+        self.assertEqual([], self.__mgr.mod_ccsession.add_remote_params)
+        self.__mgr._setup_module()
+        self.assertEqual([('data_sources',
+                           self.__mgr._datasrc_config_handler)],
+                         self.__mgr.mod_ccsession.add_remote_params)
+
+        # If data source isn't configured it's considered fatal.
+        self.__mgr.mod_ccsession.add_remote_exception = \
+            isc.config.ModuleCCSessionError('faked exception')
+        self.assertRaises(isc.server_common.bind10_server.BIND10ServerFatal,
+                          self.__mgr._setup_module)
+
+        self.__mgr.mod_ccsession.add_remote_exception = \
+            isc.config.ModuleSpecError('faked exception')
+        self.assertRaises(isc.server_common.bind10_server.BIND10ServerFatal,
+                          self.__mgr._setup_module)
+
 if __name__== "__main__":
     isc.log.resetUnitTestRootLogger()
     unittest.main()