Browse Source

[trac1010] additional tests an catches

Jelte Jansen 14 years ago
parent
commit
e90d2063e0

+ 1 - 2
src/lib/python/isc/config/tests/ccsession_test.py

@@ -616,8 +616,7 @@ class TestModuleCCSession(unittest.TestCase):
         self.assertRaises(TypeError, default_logconfig_handler);
         self.assertRaises(TypeError, default_logconfig_handler, 1);
 
-        spec = isc.config.module_spec_from_file(LOGGING_SPEC_FILE,
-                                                bind10_config.PLUGIN_PATHS)
+        spec = isc.config.module_spec_from_file(LOGGING_SPEC_FILE)
         config_data = ConfigData(spec)
 
         self.assertRaises(TypeError, default_logconfig_handler, 1, config_data)

+ 7 - 4
src/lib/python/isc/log/log.cc

@@ -196,7 +196,6 @@ isc::data::ElementPtr PyObjectToElement(PyObject* obj) {
         return isc::data::ElementPtr();
     } else {
         throw InternalError();
-        return isc::data::ElementPtr();
     }
 }
 
@@ -222,17 +221,21 @@ logConfigUpdate(PyObject*, PyObject* args) {
                                                config_data);
 
         Py_RETURN_NONE;
+    } catch (const isc::data::TypeError& de) {
+        PyErr_SetString(PyExc_TypeError, "argument 1 of log_config_update "
+                                         "is not a map of config data");
+    } catch (const isc::config::ModuleSpecError& mse) {
+        PyErr_SetString(PyExc_TypeError, "argument 2 of log_config_update "
+                                         "is not a correct module specification");
     } catch (const InternalError& ie) {
         PyErr_SetString(PyExc_TypeError, "argument passed to log_config_update "
                                          "is not a (compound) basic type");
-        return (NULL);
     } catch (const std::exception& e) {
         PyErr_SetString(PyExc_RuntimeError, e.what());
-        return (NULL);
     } catch (...) {
         PyErr_SetString(PyExc_RuntimeError, "Unknown C++ exception");
-        return (NULL);
     }
+    return (NULL);
 }
 
 PyMethodDef methods[] = {

+ 27 - 0
src/lib/python/isc/log/tests/log_test.py

@@ -52,6 +52,33 @@ class Manager(unittest.TestCase):
         # ignore errors like missing file?
         isc.log.init("root", "INFO", 0, "/no/such/file");
 
+    def test_log_config_update(self):
+        LOGGING_SPEC_FILE = "../../../../../bin/cfgmgr/plugins/logging.spec"
+        log_spec = isc.config.module_spec_from_file(LOGGING_SPEC_FILE).get_full_spec()
+
+        self.assertRaises(TypeError, isc.log.log_config_update)
+        self.assertRaises(TypeError, isc.log.log_config_update, 1)
+        self.assertRaises(TypeError, isc.log.log_config_update, 1, 1)
+        self.assertRaises(TypeError, isc.log.log_config_update, 1, 1, 1)
+
+        self.assertRaises(TypeError, isc.log.log_config_update, 1, log_spec)
+        self.assertRaises(TypeError, isc.log.log_config_update, [], log_spec)
+        self.assertRaises(TypeError, isc.log.log_config_update, "foo", log_spec)
+
+        # empty should pass
+        isc.log.log_config_update({}, log_spec)
+
+        # bad spec
+        self.assertRaises(TypeError, isc.log.log_config_update, {}, {"foo": "bar"})
+
+        # Try a correct one
+        log_conf = {"loggers":
+                       [{"name": "b10-xfrout", "output_options":
+                           [{"output": "/tmp/bind10.log",
+                                       "destination": "file",
+                                       "flush": True}]}]}
+        isc.log.log_config_update(log_conf, log_spec)
+
 class Logger(unittest.TestCase):
     def tearDown(self):
         isc.log.reset()