Browse Source

[1457] added test, and check for dupe rrs

Jelte Jansen 13 years ago
parent
commit
929f452fc9
2 changed files with 50 additions and 6 deletions
  1. 9 1
      src/lib/python/isc/ddns/session.py
  2. 41 5
      src/lib/python/isc/ddns/tests/session_tests.py

+ 9 - 1
src/lib/python/isc/ddns/session.py

@@ -473,6 +473,14 @@ class UpdateSession:
                 return Rcode.FORMERR()
         return Rcode.NOERROR()
 
+    def __do_update_add_single_rr(self, diff, rr, existing_rrset):
+        # helper for __do_update_add_rrs_to_rrset, only add the
+        # rr if it is not present yet
+        # (note that rr here is already a single-rr rrset)
+        rr_rdata = rr.get_rdata()[0]
+        if not rr_rdata in existing_rrset.get_rdata():
+            diff.add_data(rr)
+
     def __do_update_add_rrs_to_rrset(self, datasrc_client, diff, rrset):
         # For a number of cases, we may need to remove data in the zone
         # (note; SOA is handled separately by __do_update, so that one
@@ -500,7 +508,7 @@ class UpdateSession:
             # are special Update equality rules such as for WKS, and
             # we do have support for the type, this is where the check
             # (and potential delete) would go.
-        rrset_as_rrs(rrset, diff.add_data, rrset)
+        rrset_as_rrs(rrset, self.__do_update_add_single_rr, diff, rrset, orig_rrset)
 
     def __do_update_delete_rrset(self, datasrc_client, zname, diff, rrset):
         _, finder = datasrc_client.find_zone(rrset.get_name())

+ 41 - 5
src/lib/python/isc/ddns/tests/session_tests.py

@@ -995,13 +995,27 @@ class SessionTest(unittest.TestCase):
                                isc.dns.RRType.A(),
                                extended_a_rrset)
 
-        # Now delete those two again
+        # Adding the same RRsets should not make a difference.
+        self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_a ])
+
+        self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,
+                               isc.dns.Name("www.example.org"),
+                               isc.dns.RRType.A(),
+                               extended_a_rrset)
+
+        # Now delete those two, and we should end up with the original RRset
         self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_rrset_part ])
         self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,
                                isc.dns.Name("www.example.org"),
                                isc.dns.RRType.A(),
                                orig_a_rrset)
 
+        # 'Deleting' them again should make no difference
+        self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_rrset_part ])
+        self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,
+                               isc.dns.Name("www.example.org"),
+                               isc.dns.RRType.A(),
+                               orig_a_rrset)
 
         # Check that if we update the SOA, it is updated to our value
         self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_soa2 ])
@@ -1013,7 +1027,18 @@ class SessionTest(unittest.TestCase):
     def test_update_delete_name(self):
         self.initialize_update_rrsets()
 
-        # And delete the entire name
+        # First check it is there
+        self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,
+                               isc.dns.Name("www.example.org"),
+                               isc.dns.RRType.A())
+
+        # Delete the entire name
+        self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_name ])
+        self.check_inzone_data(isc.datasrc.ZoneFinder.NXDOMAIN,
+                               isc.dns.Name("www.example.org"),
+                               isc.dns.RRType.A())
+
+        # Should still be gone after pointless second delete
         self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_name ])
         self.check_inzone_data(isc.datasrc.ZoneFinder.NXDOMAIN,
                                isc.dns.Name("www.example.org"),
@@ -1048,6 +1073,7 @@ class SessionTest(unittest.TestCase):
                                               orig_ns_rrset.get_class(),
                                               "ns3.example.org."))
 
+        # When we are done, we should have a reduced NS rrset
         short_ns_rrset = isc.dns.RRset(isc.dns.Name("example.org"),
                                        TEST_RRCLASS,
                                        isc.dns.RRType.NS(),
@@ -1061,6 +1087,11 @@ class SessionTest(unittest.TestCase):
                                isc.dns.Name("example.org"),
                                isc.dns.RRType.NS(),
                                orig_ns_rrset)
+        # We will delete the MX record later in this test, so let's make
+        # sure that it exists (we do not care about its value)
+        self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,
+                               isc.dns.Name("example.org"),
+                               isc.dns.RRType.MX())
 
         # Check that we cannot delete the SOA record by direction deletion
         #self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_soa_del ])
@@ -1069,8 +1100,9 @@ class SessionTest(unittest.TestCase):
                                isc.dns.RRType.SOA(),
                                orig_soa_rrset)
 
-        # And that soa and NS at apex are not deleted if you delete the apex by name
-        #self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_name_apex ])
+        # If we delete everything at the apex, the SOA and NS rrsets should be
+        # untouched
+        self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_name_apex ])
         self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,
                                isc.dns.Name("example.org"),
                                isc.dns.RRType.SOA(),
@@ -1079,8 +1111,12 @@ class SessionTest(unittest.TestCase):
                                isc.dns.Name("example.org"),
                                isc.dns.RRType.NS(),
                                orig_ns_rrset)
+        # but the MX should be gone
+        self.check_inzone_data(isc.datasrc.ZoneFinder.NXRRSET,
+                               isc.dns.Name("example.org"),
+                               isc.dns.RRType.MX())
 
-        # And if we delete the NS at the apex specifically, it should still
+        # If we delete the NS at the apex specifically, it should still
         # keep one record
         self.check_full_handle_result(Rcode.NOERROR(), [ self.rrset_update_del_rrset_ns ])
         self.check_inzone_data(isc.datasrc.ZoneFinder.SUCCESS,