Browse Source

[213] Kill method for component

Michal 'vorner' Vaner 13 years ago
parent
commit
e23b6b271c

+ 11 - 0
src/lib/python/isc/bind10/component.py

@@ -269,6 +269,17 @@ class Component:
         """
         return self._procinfo.pid if self._procinfo else None
 
+    def kill(self):
+        """
+        The component should be forcefully killed. This does not change the
+        internal state, it just kills the external process and expects a
+        failure to be reported when the process really dies.
+
+        If it isn't running, it does nothing.
+        """
+        if self._procinfo:
+            self._procinfo.kill()
+
 class Configurator:
     """
     This thing keeps track of configuration changes and starts and stops

+ 4 - 0
src/lib/python/isc/bind10/special_component.py

@@ -44,6 +44,10 @@ class SockCreator(Component):
         """
         return self.__creator.pid() if self.__creator else None
 
+    def kill(self):
+        if self.__creator:
+            self.__creator.kill()
+
 class Msgq(Component):
     """
     The message queue. Starting is passed to boss, stopping is not supported

+ 13 - 0
src/lib/python/isc/bind10/tests/component_test.py

@@ -424,6 +424,16 @@ class ComponentTests(BossUtils, unittest.TestCase):
             component = component_type('none', self, 'needed')
             self.assertIsNone(component.pid())
 
+    def test_kill_unstarted(self):
+        """
+        Try to kill the component if it's not started. Should not fail.
+
+        We do not try to kill a running component, as we should not start
+        it during unit tests.
+        """
+        component = Component(self, 'component', 'needed')
+        component.kill()
+
 class TestComponent(Component):
     """
     A test component. It does not start any processes or so, it just logs
@@ -458,6 +468,9 @@ class TestComponent(Component):
     def _failed_internal(self):
         self.log('failed')
 
+    def kill(self):
+        self.log('killed')
+
 class FailComponent(Component):
     """
     A mock component that fails whenever it is started.