Parcourir la source

[2439] Provide an rrset collection from Diff

Let the Diff pass an rrset collection from within the internal updater.
Michal 'vorner' Vaner il y a 12 ans
Parent
commit
f0ad7b6307
2 fichiers modifiés avec 46 ajouts et 1 suppressions
  1. 13 0
      src/lib/python/isc/xfrin/diff.py
  2. 33 1
      src/lib/python/isc/xfrin/tests/diff_tests.py

+ 13 - 0
src/lib/python/isc/xfrin/diff.py

@@ -584,3 +584,16 @@ class Diff:
             if rr.get_name() == name:
             if rr.get_name() == name:
                 new_rrsets.append(rr)
                 new_rrsets.append(rr)
         return result, new_rrsets, flags
         return result, new_rrsets, flags
+
+    def get_rrset_collection(self):
+        '''
+        This first applies all changes to the data source. Then it creates
+        and returns an RRsetCollection on top of the corresponding zone
+        updater and returns it. Notice it might be impossible to apply more
+        changes after that.
+
+        This must not be called after a commit, or it'd throw ValueError.
+        '''
+        # Apply itself will check it is not yet commited.
+        self.apply()
+        return self.__updater.get_rrset_collection()

+ 33 - 1
src/lib/python/isc/xfrin/tests/diff_tests.py

@@ -16,7 +16,7 @@
 import isc.log
 import isc.log
 import unittest
 import unittest
 from isc.datasrc import ZoneFinder
 from isc.datasrc import ZoneFinder
-from isc.dns import Name, RRset, RRClass, RRType, RRTTL, Rdata
+from isc.dns import Name, RRset, RRClass, RRType, RRTTL, Rdata, RRsetCollection
 from isc.xfrin.diff import Diff, NoSuchZone
 from isc.xfrin.diff import Diff, NoSuchZone
 
 
 class TestError(Exception):
 class TestError(Exception):
@@ -1087,6 +1087,38 @@ class DiffTest(unittest.TestCase):
             self.__check_find_all_call(diff.find_all, self.__rrset3,
             self.__check_find_all_call(diff.find_all, self.__rrset3,
                                        rcode)
                                        rcode)
 
 
+    class Collection:
+        '''
+        Our own mock RRsetCollection. We don't use it, just pass it through.
+        This is to implement the below method.
+        '''
+        # Any idea why python doesn't agree with inheriting from
+        # dns.RRsetCollection?
+        pass
+
+    def get_rrset_collection(self):
+        '''
+        Part of pretending to be the zone updater. This returns the rrset
+        collection (a mock one, unuseable) for the updater.
+        '''
+        return self.Collection()
+
+    def test_get_rrset_collection(self):
+        '''
+        Test the diff can return corresponding rrset collection. Test
+        it applies the data first.
+        '''
+        diff = Diff(self, Name('example.org'), single_update_mode=True)
+        diff.add_data(self.__rrset_soa)
+        collection = diff.get_rrset_collection()
+        # Check it is commited
+        self.assertEqual(1, len(self.__data_operations))
+        self.assertEqual('add', self.__data_operations[0][0])
+        # Check the returned one is actually RRsetCollection
+        self.assertTrue(collection, self.Collection)
+        # We don't call anything on the collection. It's just the mock from
+        # above, so it wouldn't be any good.
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     isc.log.init("bind10")
     isc.log.init("bind10")
     isc.log.resetUnitTestRootLogger()
     isc.log.resetUnitTestRootLogger()