Parcourir la source

[2854] changed the return type of get_reset_param() from string to dict.

as it will probably be more convenient.
JINMEI Tatuya il y a 12 ans
Parent
commit
361853d37c

+ 9 - 7
src/lib/python/isc/memmgr/datasrc_info.py

@@ -14,7 +14,6 @@
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import os
-import json
 
 class SegmentInfoError(Exception):
     """An exception raised for general errors in the SegmentInfo class."""
@@ -80,11 +79,14 @@ class SegmentInfo:
     def get_reset_param(self, user_type):
         """Return parameters to reset the zone table memory segment.
 
-        It returns a json expression in string that contains parameters for
-        the specified type of user to reset a zone table segment with
-        isc.datasrc.ConfigurableClientList.reset_memory_segment().
-        It can also be passed to the user module as part of command
-        parameters.
+        It returns a dict object that consists of parameter mappings
+        (string to parameter value) for the specified type of user to
+        reset a zone table segment with
+        isc.datasrc.ConfigurableClientList.reset_memory_segment().  It
+        can also be passed to the user module as part of command
+        parameters.  Note that reset_memory_segment() takes a json
+        expression encoded as a string, so the return value of this method
+        will have to be converted with json.dumps().
 
         Each subclass must implement this method.
 
@@ -142,7 +144,7 @@ class MappedSegmentInfo(SegmentInfo):
         if ver is None:
             return None
         mapped_file = self.__mapped_file_base + '.' + str(ver)
-        return json.dumps({'mapped-file': mapped_file})
+        return {'mapped-file': mapped_file}
 
     def switch_versions(self):
         # Swith the versions as noted in the constructor.

+ 2 - 3
src/lib/python/isc/memmgr/tests/datasrc_info_tests.py

@@ -13,7 +13,6 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-import json
 import os
 import unittest
 
@@ -52,7 +51,7 @@ class TestSegmentInfo(unittest.TestCase):
         if expected_ver is None:
             self.assertIsNone(self.__sgmt_info.get_reset_param(user_type))
             return
-        param = json.loads(self.__sgmt_info.get_reset_param(user_type))
+        param = self.__sgmt_info.get_reset_param(user_type)
         self.assertEqual(self.__mapped_file_dir +
                          '/zone-IN-0-sqlite3-mapped.' + str(expected_ver),
                          param['mapped-file'])
@@ -124,7 +123,7 @@ class TestDataSrcInfo(unittest.TestCase):
         # Check if the initial state of (mapped) segment info object has
         # expected values.
         self.assertIsNone(sgmt_info.get_reset_param(SegmentInfo.READER))
-        param = json.loads(sgmt_info.get_reset_param(SegmentInfo.WRITER))
+        param = sgmt_info.get_reset_param(SegmentInfo.WRITER)
         self.assertEqual(writer_file, param['mapped-file'])
 
     def test_init(self):