Parcourir la source

[master] Merge branch 'trac1520'

Jelte Jansen il y a 13 ans
Parent
commit
0f18039bc7

+ 3 - 1
src/lib/python/isc/config/config_data.py

@@ -589,8 +589,10 @@ class MultiConfigData:
             if item_type == "list" and (all or first):
                 spec_part_list = spec_part['list_item_spec']
                 list_value, status = self.get_value(identifier)
+                # If not set, and no default, lists will show up as 'None',
+                # but it's better to treat it as an empty list then
                 if list_value is None:
-                    raise isc.cc.data.DataNotFoundError(identifier + " not found")
+                    list_value = []
 
                 if type(list_value) != list:
                     # the identifier specified a single element

+ 4 - 2
src/lib/python/isc/config/tests/config_data_test.py

@@ -596,8 +596,10 @@ class TestMultiConfigData(unittest.TestCase):
 
         module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec24.spec")
         self.mcd.set_specification(module_spec)
-        self.assertRaises(isc.cc.data.DataNotFoundError,
-                          self.mcd.get_value_maps, "/Spec24/item", 4)
+        # optional list item that is not set should return as empty list
+        maps = self.mcd.get_value_maps("/Spec24/item", 4)
+        self.assertEqual([{'default': False, 'type': 'list', 'name': 'Spec24/item', 'value': [], 'modified': False}], maps)
+
         self.mcd._set_current_config({ "Spec24": { "item": [] } })
         maps = self.mcd.get_value_maps("/Spec24/item")
         self.assertEqual([{'default': False, 'modified': False, 'name': 'Spec24/item', 'type': 'list', 'value': []}], maps)