Browse Source

[1217] extend wrapper for individual_rrs argument

Jelte Jansen 13 years ago
parent
commit
687b0e5483

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

@@ -89,7 +89,7 @@ None\n\
 ";
 ";
 
 
 const char* const DataSourceClient_getIterator_doc = "\
 const char* const DataSourceClient_getIterator_doc = "\
-get_iterator(name) -> ZoneIterator\n\
+get_iterator(name, individual_rrs=False) -> ZoneIterator\n\
 \n\
 \n\
 Returns an iterator to the given zone.\n\
 Returns an iterator to the given zone.\n\
 \n\
 \n\
@@ -111,6 +111,8 @@ anything else.\n\
 Parameters:\n\
 Parameters:\n\
   isc.dns.Name The name of zone apex to be traversed. It doesn't do\n\
   isc.dns.Name The name of zone apex to be traversed. It doesn't do\n\
                nearest match as find_zone.\n\
                nearest match as find_zone.\n\
+  individual_rrs If this is True (default is False), each RR will be\n\
+                 as a separate RRset\n\
 \n\
 \n\
 Return Value(s): Pointer to the iterator.\n\
 Return Value(s): Pointer to the iterator.\n\
 ";
 ";

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

@@ -83,11 +83,19 @@ DataSourceClient_findZone(PyObject* po_self, PyObject* args) {
 PyObject*
 PyObject*
 DataSourceClient_getIterator(PyObject* po_self, PyObject* args) {
 DataSourceClient_getIterator(PyObject* po_self, PyObject* args) {
     s_DataSourceClient* const self = static_cast<s_DataSourceClient*>(po_self);
     s_DataSourceClient* const self = static_cast<s_DataSourceClient*>(po_self);
-    PyObject *name_obj;
-    if (PyArg_ParseTuple(args, "O!", &name_type, &name_obj)) {
+    PyObject* name_obj;
+    PyObject* individual_rrs_obj = NULL;
+    if (PyArg_ParseTuple(args, "O!|O", &name_type, &name_obj,
+                         &individual_rrs_obj)) {
         try {
         try {
+            bool individual_rrs = false;
+            if (individual_rrs_obj != NULL &&
+                PyObject_IsTrue(individual_rrs_obj)) {
+                individual_rrs = true;
+            }
             return (createZoneIteratorObject(
             return (createZoneIteratorObject(
-                self->cppobj->getInstance().getIterator(PyName_ToName(name_obj)),
+                self->cppobj->getInstance().getIterator(PyName_ToName(name_obj),
+                                                        individual_rrs),
                 po_self));
                 po_self));
         } catch (const isc::NotImplemented& ne) {
         } catch (const isc::NotImplemented& ne) {
             PyErr_SetString(getDataSourceException("NotImplemented"),
             PyErr_SetString(getDataSourceException("NotImplemented"),

+ 42 - 3
src/lib/python/isc/datasrc/tests/datasrc_test.py

@@ -63,7 +63,7 @@ def check_for_rrset(expected_rrsets, rrset):
 
 
 class DataSrcClient(unittest.TestCase):
 class DataSrcClient(unittest.TestCase):
 
 
-    def test_constructors(self):
+    def test_(self):
         # can't construct directly
         # can't construct directly
         self.assertRaises(TypeError, isc.datasrc.ZoneIterator)
         self.assertRaises(TypeError, isc.datasrc.ZoneIterator)
 
 
@@ -87,7 +87,7 @@ class DataSrcClient(unittest.TestCase):
 
 
         # for RRSIGS, the TTL's are currently modified. This test should
         # for RRSIGS, the TTL's are currently modified. This test should
         # start failing when we fix that.
         # start failing when we fix that.
-        rrs = dsc.get_iterator(isc.dns.Name("sql1.example.com."))
+        rrs = dsc.get_iterator(isc.dns.Name("sql1.example.com."), True)
 
 
         # we do not know the order in which they are returned by the iterator
         # we do not know the order in which they are returned by the iterator
         # but we do want to check them, so we put all records into one list
         # but we do want to check them, so we put all records into one list
@@ -114,7 +114,10 @@ class DataSrcClient(unittest.TestCase):
                      "256 3 5 AwEAAdYdRhBAEY67R/8G1N5AjGF6asIiNh/pNGeQ8xDQP13J"+
                      "256 3 5 AwEAAdYdRhBAEY67R/8G1N5AjGF6asIiNh/pNGeQ8xDQP13J"+
                      "N2lo+sNqWcmpYNhuVqRbLB+mamsU1XcCICSBvAlSmfz/ZUdafX23knAr"+
                      "N2lo+sNqWcmpYNhuVqRbLB+mamsU1XcCICSBvAlSmfz/ZUdafX23knAr"+
                      "TlALxMmspcfdpqun3Yr3YYnztuj06rV7RqmveYckWvAUXVYMSMQZfJ30"+
                      "TlALxMmspcfdpqun3Yr3YYnztuj06rV7RqmveYckWvAUXVYMSMQZfJ30"+
-                     "5fs0dE/xLztL/CzZ",
+                     "5fs0dE/xLztL/CzZ"
+                  ])
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.DNSKEY(), isc.dns.RRTTL(3600), [
                      "257 3 5 AwEAAbaKDSa9XEFTsjSYpUTHRotTS9Tz3krfDucugW5UokGQ"+
                      "257 3 5 AwEAAbaKDSa9XEFTsjSYpUTHRotTS9Tz3krfDucugW5UokGQ"+
                      "KC26QlyHXlPTZkC+aRFUs/dicJX2kopndLcnlNAPWiKnKtrsFSCnIJDB"+
                      "KC26QlyHXlPTZkC+aRFUs/dicJX2kopndLcnlNAPWiKnKtrsFSCnIJDB"+
                      "ZIyvcKq+9RXmV3HK3bUdHnQZ88IZWBRmWKfZ6wnzHo53kdYKAemTErkz"+
                      "ZIyvcKq+9RXmV3HK3bUdHnQZ88IZWBRmWKfZ6wnzHo53kdYKAemTErkz"+
@@ -127,7 +130,15 @@ class DataSrcClient(unittest.TestCase):
                   isc.dns.RRType.NS(), isc.dns.RRTTL(3600),
                   isc.dns.RRType.NS(), isc.dns.RRTTL(3600),
                   [
                   [
                     "dns01.example.com.",
                     "dns01.example.com.",
+                  ])
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.NS(), isc.dns.RRTTL(3600),
+                  [
                     "dns02.example.com.",
                     "dns02.example.com.",
+                  ])
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.NS(), isc.dns.RRTTL(3600),
+                  [
                     "dns03.example.com."
                     "dns03.example.com."
                   ])
                   ])
         add_rrset(expected_rrset_list, name, rrclass,
         add_rrset(expected_rrset_list, name, rrclass,
@@ -137,9 +148,19 @@ class DataSrcClient(unittest.TestCase):
                   ])
                   ])
         # For RRSIGS, we can't add the fake data through the API, so we
         # For RRSIGS, we can't add the fake data through the API, so we
         # simply pass no rdata at all (which is skipped by the check later)
         # simply pass no rdata at all (which is skipped by the check later)
+        # Since we passed individual_rrs = True to get_iterator, each RRSIG
+        # will be returned as a separate RRset, so add them all one at a time
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
         add_rrset(expected_rrset_list, name, rrclass,
         add_rrset(expected_rrset_list, name, rrclass,
                   isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
                   isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
         add_rrset(expected_rrset_list, name, rrclass,
         add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.RRSIG(), isc.dns.RRTTL(7200), None)
+        add_rrset(expected_rrset_list, name, rrclass,
                   isc.dns.RRType.SOA(), isc.dns.RRTTL(3600),
                   isc.dns.RRType.SOA(), isc.dns.RRTTL(3600),
                   [
                   [
                      "master.example.com. admin.example.com. 678 3600 1800 2419200 7200"
                      "master.example.com. admin.example.com. 678 3600 1800 2419200 7200"
@@ -158,6 +179,8 @@ class DataSrcClient(unittest.TestCase):
                   ])
                   ])
         add_rrset(expected_rrset_list, name, rrclass,
         add_rrset(expected_rrset_list, name, rrclass,
                   isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
                   isc.dns.RRType.RRSIG(), isc.dns.RRTTL(3600), None)
+        add_rrset(expected_rrset_list, name, rrclass,
+                  isc.dns.RRType.RRSIG(), isc.dns.RRTTL(7200), None)
 
 
         # rrs is an iterator, but also has direct get_next_rrset(), use
         # rrs is an iterator, but also has direct get_next_rrset(), use
         # the latter one here
         # the latter one here
@@ -179,10 +202,26 @@ class DataSrcClient(unittest.TestCase):
         # instead of failing?
         # instead of failing?
         self.assertRaises(isc.datasrc.Error, rrs.get_next_rrset)
         self.assertRaises(isc.datasrc.Error, rrs.get_next_rrset)
 
 
+        # Without an individual_rrs argument, it should return 55 RRsets
+        dsc = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
         rrets = dsc.get_iterator(isc.dns.Name("example.com"))
         rrets = dsc.get_iterator(isc.dns.Name("example.com"))
         # there are more than 80 RRs in this zone... let's just count them
         # there are more than 80 RRs in this zone... let's just count them
         # (already did a full check of the smaller zone above)
         # (already did a full check of the smaller zone above)
         self.assertEqual(55, len(list(rrets)))
         self.assertEqual(55, len(list(rrets)))
+
+        # same test, but now with explicit False argument for individual_rrs
+        dsc = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
+        rrets = dsc.get_iterator(isc.dns.Name("example.com"), False)
+        # there are more than 80 RRs in this zone... let's just count them
+        # (already did a full check of the smaller zone above)
+        self.assertEqual(55, len(list(rrets)))
+
+        # Count should be 84 if we request individual records
+        dsc = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
+        rrets = dsc.get_iterator(isc.dns.Name("example.com"), True)
+        # there are more than 80 RRs in this zone... let's just count them
+        # (already did a full check of the smaller zone above)
+        self.assertEqual(84, len(list(rrets)))
         # TODO should we catch this (iterating past end) and just return None
         # TODO should we catch this (iterating past end) and just return None
         # instead of failing?
         # instead of failing?
         self.assertRaises(isc.datasrc.Error, rrs.get_next_rrset)
         self.assertRaises(isc.datasrc.Error, rrs.get_next_rrset)