Browse Source

[1262] Allow the diff to remove old data

Michal 'vorner' Vaner 13 years ago
parent
commit
017b4e1bcc
2 changed files with 14 additions and 4 deletions
  1. 4 3
      src/lib/python/isc/xfrin/diff.py
  2. 10 1
      src/lib/python/isc/xfrin/tests/diff_tests.py

+ 4 - 3
src/lib/python/isc/xfrin/diff.py

@@ -40,19 +40,20 @@ class Diff:
     the changes to underlying data source right away, but keeps them for
     the changes to underlying data source right away, but keeps them for
     a while.
     a while.
     """
     """
-    def __init__(self, datasource, zone):
+    def __init__(self, datasource, zone, replace=False):
         """
         """
         Initializes the diff to a ready state. It checks the zone exists
         Initializes the diff to a ready state. It checks the zone exists
         in the datasource and if not, NoSuchZone is raised. This also creates
         in the datasource and if not, NoSuchZone is raised. This also creates
         a transaction in the data source.
         a transaction in the data source.
 
 
         The datasource is the one containing the zone. Zone is isc.dns.Name
         The datasource is the one containing the zone. Zone is isc.dns.Name
-        object representing the name of the zone (its apex).
+        object representing the name of the zone (its apex). If replace is true,
+        the content of the whole zone is wiped out before applying the diff.
 
 
         You can also expect isc.datasrc.Error or isc.datasrc.NotImplemented
         You can also expect isc.datasrc.Error or isc.datasrc.NotImplemented
         exceptions.
         exceptions.
         """
         """
-        self.__updater = datasource.get_updater(zone, False)
+        self.__updater = datasource.get_updater(zone, replace)
         if self.__updater is None:
         if self.__updater is None:
             # The no such zone case
             # The no such zone case
             raise NoSuchZone("Zone " + str(zone) +
             raise NoSuchZone("Zone " + str(zone) +

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

@@ -37,6 +37,7 @@ class DiffTest(unittest.TestCase):
         self.__data_operations = []
         self.__data_operations = []
         self.__apply_called = False
         self.__apply_called = False
         self.__commit_called = False
         self.__commit_called = False
+        self.__should_replace = False
         # Some common values
         # Some common values
         self.__rrclass = RRClass.IN()
         self.__rrclass = RRClass.IN()
         self.__type = RRType.A()
         self.__type = RRType.A()
@@ -103,7 +104,7 @@ class DiffTest(unittest.TestCase):
         it returns self.
         it returns self.
         """
         """
         # The diff should not delete the old data.
         # The diff should not delete the old data.
-        self.assertFalse(replace)
+        self.assertEqual(self.__should_replace, replace)
         self.__updater_requested = True
         self.__updater_requested = True
         # Pretend this zone doesn't exist
         # Pretend this zone doesn't exist
         if zone_name == Name('none.example.org.'):
         if zone_name == Name('none.example.org.'):
@@ -322,6 +323,14 @@ class DiffTest(unittest.TestCase):
         diff.compact()
         diff.compact()
         check()
         check()
 
 
+    def test_relpace(self):
+        """
+        Test that when we want to replace the whole zone, it is propagated.
+        """
+        self.__should_replace = True
+        diff = Diff(self, "example.org.", True)
+        self.assertTrue(self.__updater_requested)
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     isc.log.init("bind10")
     isc.log.init("bind10")
     unittest.main()
     unittest.main()