Browse Source

[1429] _get_socket without error checking

Michal 'vorner' Vaner 13 years ago
parent
commit
b7ac17da54
2 changed files with 50 additions and 1 deletions
  1. 13 1
      src/bin/bind10/bind10_src.py.in
  2. 37 0
      src/bin/bind10/tests/bind10_test.py.in

+ 13 - 1
src/bin/bind10/bind10_src.py.in

@@ -244,6 +244,8 @@ class BoB:
         if self.verbose:
             logger.set_severity("DEBUG", 99)
         self._socket_cache = None
+        # TODO: To be filled in by #1428
+        self._socket_path = None
 
     def __propagate_component_config(self, config):
         comps = dict(config)
@@ -822,7 +824,17 @@ class BoB:
         Implementation of the get_socket CC command. It asks the cache
         to provide the token and sends the information back.
         """
-        pass
+        addr = isc.net.parse.addr_parse(args['address'])
+        port = isc.net.parse.port_parse(args['port'])
+        protocol = args['protocol']
+        share_mode = args['share_mode']
+        share_name = args['share_name']
+        token = self._socket_cache.get_token(protocol, addr, port, share_mode,
+                                             share_name)
+        return isc.config.ccsession.create_answer(0, {
+            'token': token,
+            'path': self._socket_path
+        })
 
     def socket_request_handler(self, token, unix_socket):
         """

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

@@ -113,6 +113,7 @@ class TestCacheCommands(unittest.TestCase):
         # Fake the cache here so we can pretend it is us and hijack the
         # calls to its methods.
         self.__boss._socket_cache = self
+        self.__boss._socket_path = '/socket/path'
         self.__raise_exception = None
         # What was and wasn't called.
         self.__drop_app_called = None
@@ -192,6 +193,42 @@ class TestCacheCommands(unittest.TestCase):
         self.assertEqual((42, 13), self.__send_fd_called)
         self.assertEqual(("token", 42), self.__get_socket_called)
 
+    def get_token(self, protocol, address, port, share_mode, share_name):
+        """
+        Part of pretending to be the cache. If there's anything in
+        __raise_exception, it is raised. Otherwise, the parameters are
+        logged into __get_token_called and a token is returned.
+        """
+        if self.__raise_exception is not None:
+            raise self.__raise_exception
+        self.__get_token_called = (protocol, address, port, share_mode,
+                                   share_name)
+        return "token"
+
+    def test_get_socket_ok(self):
+        """
+        Test the successful scenario of getting a socket.
+        """
+        args = {
+            "port": 53,
+            "address": "0.0.0.0",
+            "protocol": "UDP",
+            "share_mode": "ANY",
+            "share_name": "app"
+        }
+        result = self.__boss._get_socket(args)
+        [code, answer] = result['result']
+        self.assertEqual(0, code)
+        self.assertEqual({
+            'token': 'token',
+            'path': '/socket/path'
+        }, answer)
+        addr = self.__get_token_called[1]
+        self.assertIsInstance(addr, IPAddr)
+        self.assertEqual("0.0.0.0", str(addr))
+        self.assertEqual(("UDP", addr, 53, "ANY", "app"),
+                         self.__get_token_called)
+
 class TestBoB(unittest.TestCase):
     def test_init(self):
         bob = BoB()