Browse Source

[1344] and don't be too lenient

Jelte Jansen 13 years ago
parent
commit
8b5b28cdbd

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

@@ -650,8 +650,16 @@ class MultiConfigData:
             cur_value, status = self.get_value(cur_id_part + id)
             # Check if the value was there in the first place
             if status == MultiConfigData.NONE and cur_id_part != "/":
-                # In case the element we are inspecting did not have any value set, was optional, *and* had no default, we do not want to error when trying to set it
-                if not 'item_default' in spec_part and 'item_optional' in spec_part and spec_part['item_optional']:
+                # In case the element we are setting did not have any 
+                # value set, was optional, *and* had no default, we do not 
+                # want to error when trying to set it
+                # (this only goes for the 'final' element, if higher-level
+                # ones do not appear to exist, it is a failure, hence the
+                # final comparison)
+                if not 'item_default' in spec_part and\
+                   'item_optional' in spec_part and\
+                   spec_part['item_optional'] and\
+                   cur_id_part + id == identifier:
                     pass
                 else:
                     raise isc.cc.data.DataNotFoundError(id_part +

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

@@ -794,6 +794,11 @@ class TestUIModuleCCSession(unittest.TestCase):
         self.assertEqual({ 'new': {'first': 3, 'second': "foo" }}, value)
         self.assertEqual(status, uccs.LOCAL)
 
+        # make sure using a bad name still fails
+        self.assertRaises(isc.cc.data.DataNotFoundError, uccs.set_value,
+                          "/Spec32/named_set_item2/doesnotexist/first", 3)
+
+
     def test_commit(self):
         fake_conn = fakeUIConn()
         uccs = self.create_uccs2(fake_conn)