Browse Source

[trac565] config_handler calls start and stop

Michal 'vorner' Vaner 14 years ago
parent
commit
569afbc3c0
2 changed files with 43 additions and 22 deletions
  1. 27 2
      src/bin/bind10/bind10.py.in
  2. 16 20
      src/bin/bind10/tests/bind10_test.py

+ 27 - 2
src/bin/bind10/bind10.py.in

@@ -229,6 +229,29 @@ class BoB:
         if self.verbose:
             sys.stdout.write("[bind10] Handling new configuration: " +
                 str(new_config) + "\n")
+        if 'start_resolver' in new_config:
+            if new_config['start_resolver']:
+                if self.uid is not None:
+                    sys.stderr.write("[bind10] Starting resolver as a user," +
+                        "not root. This might fail.\n")
+                self.start_resolver(self.c_channel_env)
+            else:
+                self.stop_resolver()
+        if 'start_auth' in new_config:
+            if new_config['start_auth']:
+                if self.uid is not None:
+                    sys.stderr.write("[bind10] Starting auth as a user," +
+                        "not root. This might fail.\n")
+                self.start_auth(self.c_channel_env)
+                self.start_xfrout(self.c_channel_env)
+                self.start_xfrin(self.c_channel_env)
+                self.start_zonemgr(self.c_channel_env)
+            else:
+                self.stop_zonemgr()
+                self.stop_xfrin()
+                self.stop_xfrout()
+                self.stop_auth()
+
         answer = isc.config.ccsession.create_answer(0)
         return answer
         # TODO
@@ -477,11 +500,12 @@ class BoB:
         # XXX: we hardcode port 8080
         self.start_simple("b10-cmdctl", c_channel_env, 8080)
 
-    def start_all_processes(self, c_channel_env):
+    def start_all_processes(self):
         """
             Starts up all the processes.  Any exception generated during the
             starting of the processes is handled by the caller.
         """
+        c_channel_env = self.c_channel_env
         self.start_msgq(c_channel_env)
         self.start_cfgmgr(c_channel_env)
         self.start_ccsession(c_channel_env)
@@ -541,7 +565,8 @@ class BoB:
         # Start all processes.  If any one fails to start, kill all started
         # processes and exit with an error indication.
         try:
-            self.start_all_processes(c_channel_env)
+            self.c_channel_env = c_channel_env
+            self.start_all_processes()
         except Exception as e:
             self.kill_started_processes()
             return "Unable to start " + self.curproc + ": " + str(e)

+ 16 - 20
src/bin/bind10/tests/bind10_test.py

@@ -163,6 +163,7 @@ class StartAllProcessesBob(BoB):
         self.zonemgr = False
         self.stats = False
         self.cmdctl = False
+        self.c_channel_env = {}
 
     def read_bind10_config(self):
         # Configuration options are set directly
@@ -198,34 +199,34 @@ class StartAllProcessesBob(BoB):
     def start_cmdctl(self, c_channel_env):
         self.cmdctl = True
 
-    def stop_msgq(self, c_channel_env):
+    def stop_msgq(self):
         self.msgq = False
 
-    def stop_cfgmgr(self, c_channel_env):
+    def stop_cfgmgr(self):
         self.cfgmgr = False
 
-    def stop_ccsession(self, c_channel_env):
+    def stop_ccsession(self):
         self.ccsession = False
 
-    def stop_auth(self, c_channel_env):
+    def stop_auth(self):
         self.auth = False
 
-    def stop_resolver(self, c_channel_env):
+    def stop_resolver(self):
         self.resolver = False
 
-    def stop_xfrout(self, c_channel_env):
+    def stop_xfrout(self):
         self.xfrout = False
 
-    def stop_xfrin(self, c_channel_env):
+    def stop_xfrin(self):
         self.xfrin = False
 
-    def stop_zonemgr(self, c_channel_env):
+    def stop_zonemgr(self):
         self.zonemgr = False
 
-    def stop_stats(self, c_channel_env):
+    def stop_stats(self):
         self.stats = False
 
-    def stop_cmdctl(self, c_channel_env):
+    def stop_cmdctl(self):
         self.cmdctl = False
 
 class TestStartStopProcessesBob(unittest.TestCase):
@@ -316,11 +317,10 @@ class TestStartStopProcessesBob(unittest.TestCase):
         self.check_preconditions(bob)
 
         # Start processes and check what was started
-        c_channel_env = {}
         bob.cfg_start_auth = False
         bob.cfg_start_resolver = False
 
-        bob.start_all_processes(c_channel_env)
+        bob.start_all_processes()
         self.check_started_none(bob)
 
     # Checks the processes started when starting only the auth process
@@ -330,11 +330,10 @@ class TestStartStopProcessesBob(unittest.TestCase):
         self.check_preconditions(bob)
 
         # Start processes and check what was started
-        c_channel_env = {}
         bob.cfg_start_auth = True
         bob.cfg_start_resolver = False
 
-        bob.start_all_processes(c_channel_env)
+        bob.start_all_processes()
 
         self.check_started_auth(bob)
 
@@ -345,11 +344,10 @@ class TestStartStopProcessesBob(unittest.TestCase):
         self.check_preconditions(bob)
 
         # Start processes and check what was started
-        c_channel_env = {}
         bob.cfg_start_auth = False
         bob.cfg_start_resolver = True
 
-        bob.start_all_processes(c_channel_env)
+        bob.start_all_processes()
 
         self.check_started_resolver(bob)
 
@@ -360,11 +358,10 @@ class TestStartStopProcessesBob(unittest.TestCase):
         self.check_preconditions(bob)
 
         # Start processes and check what was started
-        c_channel_env = {}
         bob.cfg_start_auth = True
         bob.cfg_start_resolver = True
 
-        bob.start_all_processes(c_channel_env)
+        bob.start_all_processes()
 
         self.check_started_both(bob)
 
@@ -380,11 +377,10 @@ class TestStartStopProcessesBob(unittest.TestCase):
 
         # Start processes (nothing much should be started, as in
         # test_start_none)
-        c_channel_env = {}
         bob.cfg_start_auth = False
         bob.cfg_start_resolver = False
 
-        bob.start_all_processes(c_channel_env)
+        bob.start_all_processes()
         self.check_started_none(bob)
 
         # Enable both at once