Browse Source

[213] Use component.kill instead of os.kill

And add a test to see it.
Michal 'vorner' Vaner 13 years ago
parent
commit
44160936a4
2 changed files with 28 additions and 3 deletions
  1. 3 3
      src/bin/bind10/bind10_src.py.in
  2. 25 0
      src/bin/bind10/tests/bind10_test.py.in

+ 3 - 3
src/bin/bind10/bind10_src.py.in

@@ -345,7 +345,7 @@ class BoB:
 
         for pid in self.processes:
             logger.info(BIND10_KILL_PROCESS, self.processes[pid].name())
-            os.kill(self.processes[pid].pid(), signal.SIGTERM)
+            self.processes[pid].kill()
         self.processes = {}
         if self._component_configurator.running():
             self._component_configurator.shutdown()
@@ -652,7 +652,7 @@ class BoB:
             logger.info(BIND10_SEND_SIGTERM, component.name(),
                         component.pid())
             try:
-                os.kill(component.pid(), signal.SIGTERM)
+                component.kill()
             except OSError:
                 # ignore these (usually ESRCH because the child
                 # finally exited)
@@ -675,7 +675,7 @@ class BoB:
                 logger.info(BIND10_SEND_SIGKILL, component.name(),
                             component.pid())
                 try:
-                    os.kill(component.pid(), signal.SIGKILL)
+                    component.kill(True)
                 except OSError:
                     # ignore these (usually ESRCH because the child
                     # finally exited)

+ 25 - 0
src/bin/bind10/tests/bind10_test.py.in

@@ -311,6 +311,31 @@ class TestBossComponents(unittest.TestCase):
         bob._component_configurator.shutdown = orig
         self.assertTrue(self.__called)
 
+    def test_kills(self):
+        """
+        Test that the boss kills processes which don't want to stop.
+        """
+        bob = MockBob()
+        killed = []
+        class ImmortalComponent:
+            """
+            An immortal component. It does not stop when it is told so
+            (anyway it is not told so). It does not die if it is killed
+            the first time. It dies only when killed forcefully.
+            """
+            def kill(self, forcefull=False):
+                killed.append(forcefull)
+                if forcefull:
+                    bob.processes = {}
+            def pid(self):
+                return 1
+            def name(self):
+                return "Immortal"
+        bob.processes = {}
+        bob.register_process(1, ImmortalComponent())
+        bob.shutdown()
+        self.assertEqual([False, True], killed)
+
     def test_init_config(self):
         """
         Test initial configuration is loaded.