BIND 10 trac213, updated. e23b6b271c892905c9a14386aee502610502bba4 [213] Kill method for component

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Oct 24 18:04:24 UTC 2011


The branch, trac213 has been updated
       via  e23b6b271c892905c9a14386aee502610502bba4 (commit)
       via  e7a16b2735b09c0d5b55375e3091fa886940fc40 (commit)
      from  8da9b5298d5cbd0df840240e71460d047f4da808 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e23b6b271c892905c9a14386aee502610502bba4
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Oct 24 20:02:29 2011 +0200

    [213] Kill method for component

commit e7a16b2735b09c0d5b55375e3091fa886940fc40
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Oct 24 12:55:09 2011 +0200

    [213] Return something from config_handler
    
    Even when there's an error

-----------------------------------------------------------------------

Summary of changes:
 src/bin/bind10/bind10_src.py.in                   |   10 ++++++----
 src/bin/bind10/tests/bind10_test.py.in            |    7 +++----
 src/lib/python/isc/bind10/component.py            |   11 +++++++++++
 src/lib/python/isc/bind10/special_component.py    |    4 ++++
 src/lib/python/isc/bind10/tests/component_test.py |   13 +++++++++++++
 5 files changed, 37 insertions(+), 8 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index 4ce35c0..9ff45be 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -283,10 +283,12 @@ class BoB:
             return
         logger.debug(DBG_COMMANDS, BIND10_RECEIVED_NEW_CONFIGURATION,
                      new_config)
-        if 'components' in new_config:
-            self.__propagate_component_config(new_config['components'])
-        answer = isc.config.ccsession.create_answer(0)
-        return answer
+        try:
+            if 'components' in new_config:
+                self.__propagate_component_config(new_config['components'])
+            return isc.config.ccsession.create_answer(0)
+        except Exception as e:
+            return isc.config.ccsession.create_answer(1, str(e))
 
     def get_processes(self):
         pids = list(self.processes.keys())
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index 3118db3..9523241 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -298,10 +298,9 @@ class TestBossComponents(unittest.TestCase):
         # Check a configuration that messes up the core components is rejected.
         compconf = dict(self.__compconfig)
         compconf['msgq'] = { 'process': 'echo' }
-        # Is it OK to raise, or should it catch also and convert to error
-        # answer?
-        self.assertRaises(Exception, bob.config_handler,
-                          {'components': compconf})
+        result = bob.config_handler({'components': compconf})
+        # Check it rejected it
+        self.assertEqual(1, result['result'][0])
 
         # Stop it
         orig = bob._component_configurator.shutdown
diff --git a/src/lib/python/isc/bind10/component.py b/src/lib/python/isc/bind10/component.py
index 9e28305..6969244 100644
--- a/src/lib/python/isc/bind10/component.py
+++ b/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
diff --git a/src/lib/python/isc/bind10/special_component.py b/src/lib/python/isc/bind10/special_component.py
index 41e8e13..1ada70f 100644
--- a/src/lib/python/isc/bind10/special_component.py
+++ b/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
diff --git a/src/lib/python/isc/bind10/tests/component_test.py b/src/lib/python/isc/bind10/tests/component_test.py
index 11aee9c..3f3bb87 100644
--- a/src/lib/python/isc/bind10/tests/component_test.py
+++ b/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.




More information about the bind10-changes mailing list