BIND 10 trac213-incremental, updated. 9b9a92fc3d9cd1e37166f04284a922f9ab220bbe [213] Some tests for Component

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Nov 2 21:47:14 UTC 2011


The branch, trac213-incremental has been updated
       via  9b9a92fc3d9cd1e37166f04284a922f9ab220bbe (commit)
       via  bd938be1cafae39233d0a8357a4e10b383f7de37 (commit)
       via  e7d5e8f78ebad76b695e48fc2780babba6ec07d5 (commit)
       via  0166b44b81851c687d85e4f3fd87ffb0e92c6d58 (commit)
      from  5038c63b05eaee1bda68346899ac3f6baf5fbe56 (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 9b9a92fc3d9cd1e37166f04284a922f9ab220bbe
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 2 22:46:23 2011 +0100

    [213] Some tests for Component

commit bd938be1cafae39233d0a8357a4e10b383f7de37
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 2 22:06:05 2011 +0100

    [213] Document a parameter

commit e7d5e8f78ebad76b695e48fc2780babba6ec07d5
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 2 22:03:37 2011 +0100

    [213] Documentation about breaking our own recommendation

commit 0166b44b81851c687d85e4f3fd87ffb0e92c6d58
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 2 22:00:47 2011 +0100

    [213] Removed duplicate in docs

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

Summary of changes:
 src/bin/bind10/bind10_src.py.in                   |    5 +++
 src/lib/python/isc/bind10/component.py            |   15 +--------
 src/lib/python/isc/bind10/special_component.py    |   17 +++++++++-
 src/lib/python/isc/bind10/tests/component_test.py |   33 ++++++++++++++++++++-
 4 files changed, 54 insertions(+), 16 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index 22882dd..2bee1a5 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -617,8 +617,13 @@ class BoB:
         """
         Put another process into boss to watch over it.  When the process
         dies, the info.failed() is called with the exit code.
+
+        It is expected the info is a isc.bind10.component.BaseComponent
+        subclass (or anything having the same interface).
         """
         if '_procinfo' in dir(info):
+            # FIXME: This is temporary and the interface of the component
+            # doesn't guarantee the existence.
             self.processes[pid] = info._procinfo
         else:
             # XXX: a short term hack.  This is the sockcreator.
diff --git a/src/lib/python/isc/bind10/component.py b/src/lib/python/isc/bind10/component.py
index 8eefcba..603653b 100644
--- a/src/lib/python/isc/bind10/component.py
+++ b/src/lib/python/isc/bind10/component.py
@@ -315,19 +315,8 @@ class Component(BaseComponent):
         - `process` is the name of the process to start.
         - `boss` the boss object to plug into. The component needs to plug
           into it to know when it failed, etc.
-        - `kind` is the kind of component. It may be one of:
-          * 'core' means the system can't run without it and it can't be
-            safely restarted. If it does not start, the system is brought
-            down. If it crashes, the system is turned off as well (with
-            non-zero exit status).
-          * 'needed' means the system is able to restart the component,
-            but it is vital part of the service (like auth server). If
-            it fails to start or crashes in less than 10s after the first
-            startup, the system is brought down. If it crashes later on,
-            it is restarted.
-          * 'dispensable' means the component should be running, but if it
-            doesn't start or crashes for some reason, the system simply tries
-            to restart it and keeps running.
+        - `kind` is the kind of component. Refer to the documentation of
+          BaseComponent for details.
         - `address` is the address on message bus. It is used to ask it to
             shut down at the end. If you specialize the class for a component
             that is shut down differently, it might be None.
diff --git a/src/lib/python/isc/bind10/special_component.py b/src/lib/python/isc/bind10/special_component.py
index d05eeee..a366fd8 100644
--- a/src/lib/python/isc/bind10/special_component.py
+++ b/src/lib/python/isc/bind10/special_component.py
@@ -62,8 +62,21 @@ class Msgq(Component):
                            boss.start_msgq)
 
     def _stop_internal(self):
-        pass # Wait for the boss to actually kill it. There's no stop command.
-             # This is a hackish way, though
+        """
+        We can't really stop the message queue, as many processes may need
+        it for their shutdown and it doesn't have a shutdown command anyway.
+        But as it is stateless, it's OK to kill it.
+
+        So we disable this method (as the only time it could be called is
+        during shutdown) and wait for the boss to kill it in the next shutdown
+        step.
+
+        This actually breaks the recommendation at Component we shouldn't
+        override its methods one by one. This is a special case, because
+        we don't provide a different implementation, we completely disable
+        the method by providing an empty one. This can't hurt the internals.
+        """
+        pass
 
 class CfgMgr(Component):
     def __init__(self, process, boss, kind, address=None, params=None):
diff --git a/src/lib/python/isc/bind10/tests/component_test.py b/src/lib/python/isc/bind10/tests/component_test.py
index c959983..eef2b0f 100644
--- a/src/lib/python/isc/bind10/tests/component_test.py
+++ b/src/lib/python/isc/bind10/tests/component_test.py
@@ -103,6 +103,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         self.__start_called = False
         self.__stop_called = False
         self.__failed_called = False
+        self.__registered_processes = {}
 
     def __start(self):
         """
@@ -435,10 +436,40 @@ class ComponentTests(BossUtils, unittest.TestCase):
         We do not try to kill a running component, as we should not start
         it during unit tests.
         """
-        component = Component(self, 'component', 'needed')
+        component = Component('component', self, 'needed')
         component.kill()
         component.kill(True)
 
+    def register_process(self, pid, process):
+        """
+        Part of pretending to be a boss
+        """
+        self.__registered_processes[pid] = process
+
+    def test_component_attributes(self):
+        """
+        Test the default attributes of Component (not BaseComponent) and
+        some of the methods we might be allowed to call.
+        """
+        class TestProcInfo:
+            def __init__(self):
+                self.pid = 42
+        component = Component('component', self, 'needed', 'Address',
+                              ['hello'], TestProcInfo)
+        self.assertEqual('component', component._process)
+        self.assertEqual('component', component.name())
+        self.assertIsNone(component._procinfo)
+        self.assertIsNone(component.pid())
+        self.assertEqual(['hello'], component._params)
+        self.assertEqual('Address', component._address)
+        self.assertFalse(component.running())
+        self.assertEqual({}, self.__registered_processes)
+        component.start()
+        self.assertTrue(component.running())
+        self.assertIsInstance(component._procinfo, TestProcInfo)
+        self.assertEqual(42, component.pid())
+        self.assertEqual(component, self.__registered_processes.get(42))
+
 class TestComponent(BaseComponent):
     """
     A test component. It does not start any processes or so, it just logs




More information about the bind10-changes mailing list