Browse Source

[2184] Fix issue of null default value

Found another issue which became more apparent now (but I think we've seen before); get_default_value() returns None if there is no default set, however, in some cases, None can be the actual default (datasources params for instance).

This fix makes sure a default value of None is not confused with no value at all (which resulted in the error 'Error: data_sources/classes/IN[X]/params not found'
Jelte Jansen 13 years ago
parent
commit
7e93ff50b0

+ 9 - 0
src/lib/config/tests/testdata/spec40.spec

@@ -6,6 +6,15 @@
         "item_type": "any",
         "item_optional": false,
         "item_default": "asdf"
+      },
+      { "item_name": "item2",
+        "item_type": "any",
+        "item_optional": true
+      },
+      { "item_name": "item3",
+        "item_type": "any",
+        "item_optional": true,
+        "item_default": null
       }
     ]
   }

+ 10 - 2
src/lib/python/isc/config/config_data.py

@@ -556,7 +556,6 @@ class MultiConfigData:
             if 'item_default' in spec:
                 # one special case, named_set
                 if spec['item_type'] == 'named_set':
-                    print("is " + id_part + " in named set?")
                     return spec['item_default']
                 else:
                     return spec['item_default']
@@ -585,6 +584,14 @@ class MultiConfigData:
             value = self.get_default_value(identifier)
             if value is not None:
                 return value, self.DEFAULT
+            else:
+                # get_default_value returns None for both
+                # the cases where there is no default, and where
+                # it is set to null, so we need to catch the latter
+                spec_part = self.find_spec_part(identifier)
+                if spec_part and 'item_default' in spec_part and\
+                   spec_part['item_default'] is None:
+                    return None, self.DEFAULT
         return None, self.NONE
 
     def _append_value_item(self, result, spec_part, identifier, all, first = False):
@@ -650,7 +657,8 @@ class MultiConfigData:
                                                 all)
             else:
                 value, status = self.get_value(identifier)
-                if status == self.NONE and not spec_part['item_optional']:
+                if status == self.NONE and not spec_part['item_optional']:# and\
+                   #not ('item_default' in spec_part):
                     raise isc.cc.data.DataNotFoundError(identifier + " not found")
 
                 entry = _create_value_map_entry(identifier,

+ 12 - 0
src/lib/python/isc/config/tests/ccsession_test.py

@@ -1020,6 +1020,18 @@ class TestUIModuleCCSession(unittest.TestCase):
         self.assertRaises(isc.cc.data.DataTypeError,
                           uccs.remove_value, "Spec2/item5", None)
 
+    # Check that the difference between no default and default = null
+    # is recognized
+    def test_default_null(self):
+        fake_conn = fakeUIConn()
+        uccs = self.create_uccs(fake_conn, "spec40.spec")
+        (value, status) = uccs.get_value("/Spec40/item2")
+        self.assertIsNone(value)
+        self.assertEqual(uccs.NONE, status)
+        (value, status) = uccs.get_value("/Spec40/item3")
+        self.assertIsNone(value)
+        self.assertEqual(uccs.DEFAULT, status)
+
     # Test adding and removing values for type = any
     def test_add_remove_value_any(self):
         fake_conn = fakeUIConn()