Browse Source

[213] Start the sockcreator the new way

Michal 'vorner' Vaner 13 years ago
parent
commit
296a70859c

+ 13 - 2
src/bin/bind10/bind10_src.py.in

@@ -68,6 +68,7 @@ import isc.net.parse
 import isc.log
 from isc.log_messages.bind10_messages import *
 import isc.bind10.sockcreator
+import isc.bind10.component
 
 isc.log.init("b10-boss")
 logger = isc.log.Logger("boss")
@@ -250,6 +251,13 @@ class BoB:
         self.cmdctl_port = cmdctl_port
         self.brittle = brittle
         self.sockcreator = None
+        self.__component_configurator = isc.bind10.component.Configurator(self)
+        self.__core_components = {
+            'sockcreator': {
+                'kind': 'core',
+                'special': 'sockcreator'
+            }
+        }
 
     def config_handler(self, new_config):
         # If this is initial update, don't do anything now, leave it to startup
@@ -372,6 +380,7 @@ class BoB:
             logger.info(BIND10_KILL_PROCESS, self.processes[pid].name)
             self.processes[pid].process.kill()
         self.processes = {}
+        self.__component_configurator.shutdown()
 
     def read_bind10_config(self):
         """
@@ -599,8 +608,7 @@ class BoB:
             Starts up all the processes.  Any exception generated during the
             starting of the processes is handled by the caller.
         """
-        # The socket creator first, as it is the only thing that needs root
-        self.start_creator()
+        self.__component_configurator.startup(self.__core_components)
         # TODO: Once everything uses the socket creator, we can drop root
         # privileges right now
 
@@ -693,6 +701,7 @@ class BoB:
         self.cc_session.group_sendmsg(cmd, "Zonemgr", "Zonemgr")
         self.cc_session.group_sendmsg(cmd, "Stats", "Stats")
         self.cc_session.group_sendmsg(cmd, "StatsHttpd", "StatsHttpd")
+        self.__component_configurator.shutdown()
         # Terminate the creator last
         self.stop_creator()
 
@@ -725,6 +734,8 @@ class BoB:
     def stop_zonemgr(self):
         self.stop_process('b10-zonemgr', 'Zonemgr')
 
+    def shutdown(self, exitcode=0):
+
     def shutdown(self):
         """Stop the BoB instance."""
         logger.info(BIND10_SHUTDOWN)

+ 11 - 8
src/bin/bind10/tests/bind10_test.py.in

@@ -14,6 +14,7 @@
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 from bind10_src import ProcessInfo, BoB, parse_args, dump_pid, unlink_pid_file, _BASETIME
+from isc.bind10.component import Component
 
 # XXX: environment tests are currently disabled, due to the preprocessor
 #      setup that we have now complicating the environment
@@ -173,6 +174,13 @@ class TestBoB(unittest.TestCase):
         self.assertEqual(bob.command_handler("__UNKNOWN__", None),
                          isc.config.ccsession.create_answer(1, "Unknown command"))
 
+class TestComponent(Component):
+    def start_internal(self):
+        pass
+
+    def stop_internal(self, Kill=False):
+        pass
+
 # Class for testing the BoB without actually starting processes.
 # This is used for testing the start/stop components routines and
 # the BoB commands.
@@ -199,13 +207,7 @@ class MockBob(BoB):
         self.cmdctl = False
         self.c_channel_env = {}
         self.processes = { }
-        self.creator = False
-
-    def start_creator(self):
-        self.creator = True
-
-    def stop_creator(self, kill=False):
-        self.creator = False
+        isc.bind10.component.specials['sockcreator'] = TestComponent
 
     def read_bind10_config(self):
         # Configuration options are set directly
@@ -350,7 +352,6 @@ class TestStartStopProcessesBob(unittest.TestCase):
         self.assertEqual(bob.msgq, core)
         self.assertEqual(bob.cfgmgr, core)
         self.assertEqual(bob.ccsession, core)
-        self.assertEqual(bob.creator, core)
         self.assertEqual(bob.auth, auth)
         self.assertEqual(bob.resolver, resolver)
         self.assertEqual(bob.xfrout, auth)
@@ -590,6 +591,8 @@ class TestStartStopProcessesBob(unittest.TestCase):
         self.check_started_dhcp(bob, False, False)
 
         # v6 only enabled
+        bob = MockBob()
+        self.check_preconditions(bob)
         bob.cfg_start_dhcp6 = True
         bob.cfg_start_dhcp4 = False
         bob.start_all_processes()

+ 1 - 2
src/lib/python/isc/bind10/component.py

@@ -167,8 +167,7 @@ class SockCreator(Component):
         self.__boss = boss
 
     def start_internal(self):
-        self.__boss.curproc = 'b10-sockcreator'
-        print( LIBEXECDIR)
+        self._boss.curproc = 'b10-sockcreator'
         self.__creator = isc.bind10.sockcreator.Creator(LIBEXECDIR + ':' +
                                                         os.environ['PATH'])