Browse Source

[1209] a related bug fix in the python datasrc wrapper:
DataSourceClient.get_updater must return None when it cannot find the zone.
Otherwise the returned updater would be incomplete and would subseuqently
cause a disruption (such as program crash).

JINMEI Tatuya 13 years ago
parent
commit
982f6e4d7e

+ 1 - 1
src/lib/python/isc/datasrc/client_inc.cc

@@ -110,7 +110,7 @@ Return an updater to make updates to a specific zone.\n\
 The RR class of the zone is the one that the client is expected to\n\
 The RR class of the zone is the one that the client is expected to\n\
 handle (see the detailed description of this class).\n\
 handle (see the detailed description of this class).\n\
 \n\
 \n\
-If the specified zone is not found via the client, a NULL pointer will\n\
+If the specified zone is not found via the client, a None object will\n\
 be returned; in other words a completely new zone cannot be created\n\
 be returned; in other words a completely new zone cannot be created\n\
 using an updater. It must be created beforehand (even if it's an empty\n\
 using an updater. It must be created beforehand (even if it's an empty\n\
 placeholder) in a way specific to the underlying data source.\n\
 placeholder) in a way specific to the underlying data source.\n\

+ 6 - 3
src/lib/python/isc/datasrc/client_python.cc

@@ -120,9 +120,12 @@ DataSourceClient_getUpdater(PyObject* po_self, PyObject* args) {
         PyBool_Check(replace_obj)) {
         PyBool_Check(replace_obj)) {
         bool replace = (replace_obj != Py_False);
         bool replace = (replace_obj != Py_False);
         try {
         try {
-            return (createZoneUpdaterObject(
-                        self->cppobj->getUpdater(PyName_ToName(name_obj),
-                                                 replace)));
+            ZoneUpdaterPtr updater =
+                self->cppobj->getUpdater(PyName_ToName(name_obj), replace);
+            if (!updater) {
+                return (Py_None);
+            }
+            return (createZoneUpdaterObject(updater));
         } catch (const isc::NotImplemented& ne) {
         } catch (const isc::NotImplemented& ne) {
             PyErr_SetString(getDataSourceException("NotImplemented"),
             PyErr_SetString(getDataSourceException("NotImplemented"),
                             ne.what());
                             ne.what());

+ 5 - 0
src/lib/python/isc/datasrc/tests/datasrc_test.py

@@ -383,6 +383,11 @@ class DataSrcUpdater(unittest.TestCase):
         self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
         self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
                          rrset.to_text())
                          rrset.to_text())
 
 
+    def test_update_for_no_zone(self):
+        dsc = isc.datasrc.DataSourceClient(WRITE_ZONE_DB_FILE)
+        self.assertEqual(None,
+                         dsc.get_updater(isc.dns.Name("notexistent.example"),
+                                         True))
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     isc.log.init("bind10")
     isc.log.init("bind10")