Browse Source

[1429] Creation of the cache

Michal 'vorner' Vaner 13 years ago
parent
commit
d9b851b96c

+ 14 - 0
src/bin/bind10/bind10_src.py.in

@@ -72,6 +72,7 @@ import isc.log
 from isc.log_messages.bind10_messages import *
 import isc.bind10.component
 import isc.bind10.special_component
+import isc.bind10.socket_cache
 
 isc.log.init("b10-boss")
 logger = isc.log.Logger("boss")
@@ -241,6 +242,7 @@ class BoB:
         # If -v was set, enable full debug logging.
         if self.verbose:
             logger.set_severity("DEBUG", 99)
+        self._socket_cache = None
 
     def __propagate_component_config(self, config):
         comps = dict(config)
@@ -828,6 +830,18 @@ class BoB:
         """
         pass
 
+    def insert_creator(self, creator):
+        """
+        Registeres a socket creator into the boss. The socket creator is not
+        used directly, but through a cache. The cache is created in this
+        method.
+
+        If called more than once, it raises a ValueError.
+        """
+        if self._socket_cache is not None:
+            raise ValueError("A creator was inserted previously")
+        self._socket_cache = isc.bind10.socket_cache.Cache(creator)
+
 # global variables, needed for signal handlers
 options = None
 boss_of_bind = None

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

@@ -28,6 +28,7 @@ from isc.net.addr import IPAddr
 import time
 import isc
 import isc.log
+import isc.bind10.socket_cache
 
 from isc.testutils.parse_args import TestOptParser, OptsError
 
@@ -109,6 +110,21 @@ class TestBoB(unittest.TestCase):
         self.assertEqual(bob.uid, None)
         self.assertEqual(bob.username, None)
         self.assertEqual(bob.nocache, False)
+        self.assertIsNone(bob._socket_cache)
+
+    def test_insert_creator(self):
+        """
+        Test the call to insert_creator. First time, the cache is created
+        with the passed creator. The next time, it throws an exception.
+        """
+        bob = BoB()
+        # The cache doesn't use it at start, so just create an empty class
+        class Creator: pass
+        creator = Creator()
+        bob.insert_creator(creator)
+        self.assertIsInstance(bob._socket_cache, isc.bind10.socket_cache.Cache)
+        self.assertEqual(creator, bob._socket_cache._creator)
+        self.assertRaises(ValueError, bob.insert_creator, creator)
 
     def test_init_alternate_socket(self):
         bob = BoB("alt_socket_file")

+ 3 - 1
src/lib/python/isc/bind10/socket_cache.py

@@ -54,7 +54,9 @@ class Cache:
         (isc.bind10.sockcreator.Creator) which will be used to create yet
         uncached sockets.
         """
-        pass
+        # Full implementation and tests are in #1427. This is just because
+        # of a boss test.
+        self._creator = creator
 
     def get_token(self, protocol, address, port, share_mode, share_name):
         """

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

@@ -42,6 +42,7 @@ class SockCreator(BaseComponent):
         self.__creator = isc.bind10.sockcreator.Creator(LIBEXECDIR + ':' +
                                                         os.environ['PATH'])
         self._boss.register_process(self.pid(), self)
+        self._boss.insert_creator(self.__creator)
         self._boss.log_started(self.pid())
 
     def _stop_internal(self):