From: Jelte Jansen Date: Fri, 10 Aug 2012 12:12:14 +0000 (+0200) Subject: [2184] Fix issue of null default value X-Git-Tag: trac2351_base~65^2~34^2~1^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e93ff50b09f9bb0a121fd4336102f1875d89ac3;p=thirdparty%2Fkea.git [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' --- diff --git a/src/lib/config/tests/testdata/spec40.spec b/src/lib/config/tests/testdata/spec40.spec index f778fc09a2..6fbec10f3f 100644 --- a/src/lib/config/tests/testdata/spec40.spec +++ b/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 } ] } diff --git a/src/lib/python/isc/config/config_data.py b/src/lib/python/isc/config/config_data.py index 3a28c6b5d5..2bc6edbee3 100644 --- a/src/lib/python/isc/config/config_data.py +++ b/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, diff --git a/src/lib/python/isc/config/tests/ccsession_test.py b/src/lib/python/isc/config/tests/ccsession_test.py index c08edcc67f..0101d50fb1 100644 --- a/src/lib/python/isc/config/tests/ccsession_test.py +++ b/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()