Parcourir la source

[1515] Don't crash when printing exception

The thing should be converted to string properly
Michal 'vorner' Vaner il y a 13 ans
Parent
commit
ff1a0cd96f

+ 21 - 0
src/lib/config/tests/testdata/spec39.spec

@@ -0,0 +1,21 @@
+{
+  "module_spec": {
+    "module_name": "Spec39",
+    "config_data": [
+      { "item_name": "list",
+        "item_type": "list",
+        "item_optional": false,
+        "item_default": [],
+        "list_item_spec": {
+          "item_name": "list_item",
+          "item_type": "boolean",
+          "item_optional": false,
+          "item_default": false
+        }
+      }
+    ],
+    "commands": [],
+    "statistics": []
+  }
+}
+

+ 2 - 2
src/lib/python/isc/config/ccsession.py

@@ -451,9 +451,9 @@ class UIModuleCCSession(MultiConfigData):
             cur_list.append(value)
             self.set_value(identifier, cur_list)
         else:
-            raise isc.cc.data.DataAlreadyPresentError(value +
+            raise isc.cc.data.DataAlreadyPresentError(str(value) +
                                                       " already in "
-                                                      + identifier)
+                                                      + str(identifier))
 
     def _add_value_to_named_set(self, identifier, value, item_value):
         if type(value) != str:

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

@@ -701,6 +701,12 @@ class TestUIModuleCCSession(unittest.TestCase):
         fake_conn.set_get_answer('/config_data', { 'version': BIND10_CONFIG_DATA_VERSION })
         return UIModuleCCSession(fake_conn)
 
+    def create_uccs_listtest(self, fake_conn):
+        module_spec = isc.config.module_spec_from_file(self.spec_file("spec39.spec"))
+        fake_conn.set_get_answer('/module_spec', { module_spec.get_module_name(): module_spec.get_full_spec()})
+        fake_conn.set_get_answer('/config_data', { 'version': BIND10_CONFIG_DATA_VERSION })
+        return UIModuleCCSession(fake_conn)
+
     def test_init(self):
         fake_conn = fakeUIConn()
         fake_conn.set_get_answer('/module_spec', {})
@@ -732,6 +738,7 @@ class TestUIModuleCCSession(unittest.TestCase):
         self.assertEqual({}, uccs._local_changes)
         uccs.add_value("Spec2/item5", "foo")
         self.assertEqual({'Spec2': {'item5': ['a', 'b', 'foo']}}, uccs._local_changes)
+        self.assertEqual({'Spec2': {'item5': ['a', 'b', 'foo']}}, uccs._local_changes)
         uccs.remove_value("Spec2/item5", "foo")
         self.assertEqual({'Spec2': {'item5': ['a', 'b']}}, uccs._local_changes)
         uccs._local_changes = {'Spec2': {'item5': []}}
@@ -751,6 +758,14 @@ class TestUIModuleCCSession(unittest.TestCase):
         self.assertRaises(isc.cc.data.DataTypeError,
                           uccs.remove_value, "Spec2/item5", None)
 
+    def test_add_dup_value(self):
+        fake_conn = fakeUIConn()
+        uccs = self.create_uccs_listtest(fake_conn)
+
+        uccs.add_value("Spec39/list")
+        self.assertRaises(isc.cc.data.DataAlreadyPresentError, uccs.add_value,
+                          "Spec39/list")
+
     def test_add_remove_value_named_set(self):
         fake_conn = fakeUIConn()
         uccs = self.create_uccs_named_set(fake_conn)