Browse Source

[2854] added get_clients_map to DataSrcClientsMgr to use in memmgr.

JINMEI Tatuya 12 years ago
parent
commit
1b1c061696

+ 19 - 0
src/lib/python/isc/server_common/datasrc_clients_mgr.py

@@ -61,6 +61,25 @@ class DataSrcClientsMgr:
         self.__clients_map = {}
         self.__map_lock = threading.Lock()
 
+    def get_clients_map(self):
+        """Returns a dict from RR class to ConfigurableClientList.
+
+        It corresponds to the generation of data source configuration at the
+        time of the call.  It can be safely called while reconfigure() is
+        called from another thread.
+
+        The mapping of the dict should be considered "frozen"; the caller
+        shouldn't modify the mapping (it can use the mapped objects in a
+        way modifying its internal state).
+
+        Note: in a future version we may also need to return the
+        "generation ID" of the corresponding configuration so the caller
+        application can handle migration between generations gradually.
+
+        """
+        with self.__map_lock:
+            return self.__clients_map
+
     def get_client_list(self, rrclass):
         """Return the configured ConfigurableClientList for the RR class.
 

+ 22 - 5
src/lib/python/isc/server_common/tests/datasrc_clients_mgr_test.py

@@ -79,12 +79,11 @@ class DataSrcClientsMgrTest(unittest.TestCase):
                           self.__mgr.reconfigure, {"classes": {"IN": 42}})
         self.assertIsNotNone(self.__mgr.get_client_list(RRClass.CH))
 
-    def test_reconfig_while_using_old(self):
-        """Check datasrc client and finder can work even after list is gone."""
-        self.__mgr.reconfigure(DEFAULT_CONFIG)
-        clist = self.__mgr.get_client_list(RRClass.CH)
-        self.__mgr.reconfigure({"classes": {"IN": []}})
+    def check_client_list_content(self, clist):
+        """Some set of checks on given data source client list.
 
+        Used by a couple of tests below.
+        """
         datasrc_client, finder, exact = clist.find(Name('bind'))
         self.assertTrue(exact)
 
@@ -104,6 +103,24 @@ class DataSrcClientsMgrTest(unittest.TestCase):
         rrsets = datasrc_client.get_iterator(Name('bind'))
         self.assertNotEqual(0, len(list(rrsets)))
 
+    def test_reconfig_while_using_old(self):
+        """Check datasrc client and finder can work even after list is gone."""
+        self.__mgr.reconfigure(DEFAULT_CONFIG)
+        clist = self.__mgr.get_client_list(RRClass.CH)
+        self.__mgr.reconfigure({"classes": {"IN": []}})
+        self.check_client_list_content(clist)
+
+    def test_get_clients_map(self):
+        # This is basically a trivial getter, so it should be sufficient
+        # to check we can call it as we expect.
+        self.__mgr.reconfigure(DEFAULT_CONFIG)
+        clients_map = self.__mgr.get_clients_map()
+        self.assertEqual(2, len(clients_map)) # should contain 'IN' and 'CH'
+
+        # Check the retrieved map is usable even after further reconfig().
+        self.__mgr.reconfigure({"classes": {"IN": []}})
+        self.check_client_list_content(clients_map[RRClass.CH])
+
 if __name__ == "__main__":
     isc.log.init("bind10")
     isc.log.resetUnitTestRootLogger()