BIND 10 trac1259, updated. 9b23d60d6f58b18da3995dc3e090d7fd63233bcc [1259] The commit of transaction
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Sep 29 12:44:42 UTC 2011
The branch, trac1259 has been updated
via 9b23d60d6f58b18da3995dc3e090d7fd63233bcc (commit)
via 4bb4081381b39c563707c03818a0f9d16ef7846f (commit)
via eef5b0eb5defdd22ef5e351213ab66531f788c5d (commit)
via e7f1ead205f2dc13d6fd6e2a28b121794ca281be (commit)
via 638674c480d47cf957a8b4f7d61dda3320c881ff (commit)
via 0a22b98c05bf5032c190fbfdf9fefceac3597411 (commit)
via f59415a8b5ee951dd298eaf8eecaa21e8955851c (commit)
via 4e458fc15b5c236e1cc44565f6af313753e87a26 (commit)
via e2eca96f1876a72fc8c121c9204d49cb7e9eaeb7 (commit)
via 85455b6e2f7063b10bae9938de1b70f5d319911e (commit)
via 66e1420d30f8e71e867a3b5b0a73ead1156d5660 (commit)
from 16cc75f764b6ea509f386c261b472e282cd606ed (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9b23d60d6f58b18da3995dc3e090d7fd63233bcc
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 14:38:31 2011 +0200
[1259] The commit of transaction
commit 4bb4081381b39c563707c03818a0f9d16ef7846f
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 14:34:26 2011 +0200
[1259] Test for the commit, first part
Only the commit itself, not yet that the rest of operations get disabled
by it.
commit eef5b0eb5defdd22ef5e351213ab66531f788c5d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 14:31:19 2011 +0200
[1259] The apply method
commit e7f1ead205f2dc13d6fd6e2a28b121794ca281be
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 14:26:26 2011 +0200
[1259] Tests for the apply method
With the minimal dependencies on the other methods, except for adding
and removing.
commit 638674c480d47cf957a8b4f7d61dda3320c881ff
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 14:25:16 2011 +0200
[1259] Little interface update on Diff
It now has the compact method, which is used internally mostly, but can
be called explicitly.
Also a note about exception was added.
commit 0a22b98c05bf5032c190fbfdf9fefceac3597411
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 13:52:56 2011 +0200
[1259] Test for remove_data
commit f59415a8b5ee951dd298eaf8eecaa21e8955851c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 13:47:35 2011 +0200
[1259] Adding data
commit 4e458fc15b5c236e1cc44565f6af313753e87a26
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 13:40:25 2011 +0200
[1259] Test for add_data
commit e2eca96f1876a72fc8c121c9204d49cb7e9eaeb7
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 13:23:47 2011 +0200
[1259] Add the buffer into diff
commit 85455b6e2f7063b10bae9938de1b70f5d319911e
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 13:14:36 2011 +0200
[1259] Creation of the Diff
commit 66e1420d30f8e71e867a3b5b0a73ead1156d5660
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Sep 29 13:11:44 2011 +0200
[1259] Test for creating of the diff
-----------------------------------------------------------------------
Summary of changes:
src/lib/python/isc/xfrin/diff.py | 63 +++++++-
src/lib/python/isc/xfrin/tests/Makefile.am | 2 +-
src/lib/python/isc/xfrin/tests/diff_tests.py | 211 ++++++++++++++++++++++++++
3 files changed, 270 insertions(+), 6 deletions(-)
create mode 100644 src/lib/python/isc/xfrin/tests/diff_tests.py
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/xfrin/diff.py b/src/lib/python/isc/xfrin/diff.py
index d910938..38b0e10 100644
--- a/src/lib/python/isc/xfrin/diff.py
+++ b/src/lib/python/isc/xfrin/diff.py
@@ -50,7 +50,25 @@ class Diff:
You can also expect isc.datasrc.Error or isc.datasrc.NotImplemented
exceptions.
"""
- pass
+ self.__updater = datasource.get_updater(zone, False)
+ if self.__updater is None:
+ # The no such zone case
+ raise NoSuchZone("Zone " + str(zone) +
+ " does not exist in the data source " +
+ str(datasource))
+ self.__buffer = []
+
+ def __data_common(self, rr, operation):
+ """
+ Schedules an operation with rr.
+
+ It does all the real work of add_data and remove_data, including
+ all checks.
+ """
+ if rr.get_rdata_count() != 1:
+ raise ValueError('The rrset must contain exactly 1 Rdata, but ' +
+ 'it holds ' + str(rr.get_rdata_count()))
+ self.__buffer.append((operation, rr))
def add_data(self, rr):
"""
@@ -60,7 +78,7 @@ class Diff:
If this is not the case or if the diff was already commited, this
raises the ValueError exception.
"""
- pass
+ self.__data_common(rr, 'add')
def remove_data(self, rr):
"""
@@ -70,6 +88,17 @@ class Diff:
If this is not the case or if the diff was already commited, this
raises the ValueError exception.
"""
+ self.__data_common(rr, 'remove')
+
+ def compact(self):
+ """
+ Tries to compact the operations in buffer a little by putting some of
+ the operations together, forming RRsets with more than one RR.
+
+ This is called by apply before putting the data into datasource.
+
+ It is currently empty and needs implementing.
+ """
pass
def apply(self):
@@ -85,9 +114,21 @@ class Diff:
This raises ValueError if the diff was already commited.
- It also can raise isc.datasrc.Error.
+ It also can raise isc.datasrc.Error. If that happens, you should stop
+ using this object and abort the modification.
"""
- pass
+ # First, compact the data
+ self.compact()
+ # Then pass the data inside the data source
+ for (operation, rrset) in self.__buffer:
+ if operation == 'add':
+ self.__updater.add_rrset(rrset)
+ elif operation == 'remove':
+ self.__updater.remove_rrset(rrset)
+ else:
+ raise ValueError('Unknown operation ' + operation)
+ # As everything is already in, drop the buffer
+ self.__buffer = []
def commit(self):
"""
@@ -97,4 +138,16 @@ class Diff:
This might raise isc.datasrc.Error.
"""
- pass
+ self.apply()
+ self.__updater.commit()
+
+ def get_buffer(self):
+ """
+ Returns the current buffer of changes not yet passed into the data
+ source. It is in a form like [('add', rrset), ('remove', rrset),
+ ('remove', rrset), ...].
+
+ Probably useful only for testing and introspection purposes. Don't
+ modify the list.
+ """
+ return self.__buffer
diff --git a/src/lib/python/isc/xfrin/tests/Makefile.am b/src/lib/python/isc/xfrin/tests/Makefile.am
index 64d6409..e5325fc 100644
--- a/src/lib/python/isc/xfrin/tests/Makefile.am
+++ b/src/lib/python/isc/xfrin/tests/Makefile.am
@@ -1,5 +1,5 @@
PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
-PYTESTS =
+PYTESTS = diff_tests.py
EXTRA_DIST = $(PYTESTS)
# If necessary (rare cases), explicitly specify paths to dynamic libraries
diff --git a/src/lib/python/isc/xfrin/tests/diff_tests.py b/src/lib/python/isc/xfrin/tests/diff_tests.py
new file mode 100644
index 0000000..2735401
--- /dev/null
+++ b/src/lib/python/isc/xfrin/tests/diff_tests.py
@@ -0,0 +1,211 @@
+# Copyright (C) 2011 Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import isc.log
+import unittest
+from isc.dns import Name, RRset, RRClass, RRType, RRTTL, Rdata
+from isc.xfrin.diff import Diff, NoSuchZone
+
+class DiffTest(unittest.TestCase):
+ """
+ Tests for the isc.xfrin.diff.Diff class.
+
+ It also plays role of a data source and an updater, so it can manipulate
+ some test variables while being called.
+ """
+ def setUp(self):
+ """
+ This sets internal variables so we can see nothing was called yet.
+
+ It also creates some variables used in multiple tests.
+ """
+ # Track what was called already
+ self.__updater_requested = False
+ self.__compact_called = False
+ self.__data_operations = []
+ self.__apply_called = False
+ self.__commit_called = False
+ # Some common values
+ self.__rrclass = RRClass.IN()
+ self.__type = RRType.A()
+ self.__ttl = RRTTL(3600)
+ # And RRsets
+ # Create two valid rrsets
+ self.__rrset1 = RRset(Name('a.example.org.'), self.__rrclass,
+ self.__type, self.__ttl)
+ self.__rdata = Rdata(self.__type, self.__rrclass, '192.0.2.1')
+ self.__rrset1.add_rdata(self.__rdata)
+ self.__rrset2 = RRset(Name('b.example.org.'), self.__rrclass,
+ self.__type, self.__ttl)
+ self.__rrset2.add_rdata(self.__rdata)
+ # And two invalid
+ self.__rrset_empty = RRset(Name('empty.example.org.'), self.__rrclass,
+ self.__type, self.__ttl)
+ self.__rrset_multi = RRset(Name('multi.example.org.'), self.__rrclass,
+ self.__type, self.__ttl)
+ self.__rrset_multi.add_rdata(self.__rdata)
+ self.__rrset_multi.add_rdata(Rdata(self.__type, self.__rrclass,
+ '192.0.2.2'))
+
+ def __mock_compact(self):
+ """
+ This can be put into the diff to hook into its compact method and see
+ if it gets called.
+ """
+ self.__compact_called = True
+
+ def __mock_apply(self):
+ """
+ This can be put into the diff to hook into its apply method and see
+ it gets called.
+ """
+ self.__apply_called = True
+
+ def commit(self):
+ """
+ This is part of pretending to be a zone updater. This notes the commit
+ was called.
+ """
+ self.__commit_called = True
+
+ def add_rrset(self, rrset):
+ """
+ This one is part of pretending to be a zone updater. It writes down
+ addition of an rrset was requested.
+ """
+ self.__data_operations.append(('add', rrset))
+
+ def remove_rrset(self, rrset):
+ """
+ This one is part of pretending to be a zone updater. It writes down
+ removal of an rrset was requested.
+ """
+ self.__data_operations.append(('remove', rrset))
+
+ def get_updater(self, zone_name, replace):
+ """
+ This one pretends this is the data source client and serves
+ getting an updater.
+
+ If zone_name is 'none.example.org.', it returns None, otherwise
+ it returns self.
+ """
+ # The diff should not delete the old data.
+ self.assertFalse(replace)
+ self.__updater_requested = True
+ # Pretend this zone doesn't exist
+ if zone_name == Name('none.example.org.'):
+ return None
+ else:
+ return self
+
+ def test_create(self):
+ """
+ This test the case when the diff is successfuly created. It just
+ tries it does not throw and gets the updater.
+ """
+ diff = Diff(self, Name('example.org.'))
+ self.assertTrue(self.__updater_requested)
+ self.assertEqual([], diff.get_buffer())
+
+ def test_create_nonexist(self):
+ """
+ Try to create a diff on a zone that doesn't exist. This should
+ raise a correct exception.
+ """
+ self.assertRaises(NoSuchZone, Diff, self, Name('none.example.org.'))
+ self.assertTrue(self.__updater_requested)
+
+ def __data_common(self, diff, method, name):
+ """
+ Common part of test for test_add and test_remove.
+ """
+ # Try putting there the bad data first
+ self.assertRaises(ValueError, method, self.__rrset_empty)
+ self.assertRaises(ValueError, method, self.__rrset_multi)
+ # They were not added
+ self.assertEqual([], diff.get_buffer())
+ # Add some proper data
+ method(self.__rrset1)
+ method(self.__rrset2)
+ dlist = [(name, self.__rrset1), (name, self.__rrset2)]
+ self.assertEqual(dlist, diff.get_buffer())
+ # Check the data are not destroyed by raising an exception because of
+ # bad data
+ self.assertRaises(ValueError, method, self.__rrset_empty)
+ self.assertEqual(dlist, diff.get_buffer())
+
+ def test_add(self):
+ """
+ Try to add few items into the diff and see they are stored in there.
+
+ Also try passing an rrset that has differnt amount of RRs than 1.
+ """
+ diff = Diff(self, Name('example.org.'))
+ self.__data_common(diff, diff.add_data, 'add')
+
+ def test_remove(self):
+ """
+ Try scheduling removal of few items into the diff and see they are
+ stored in there.
+
+ Also try passing an rrset that has different amount of RRs than 1.
+ """
+ diff = Diff(self, Name('example.org.'))
+ self.__data_common(diff, diff.remove_data, 'remove')
+
+ def test_apply(self):
+ """
+ Schedule few additions and check the apply works by passing the
+ data into the updater.
+ """
+ # Prepare the diff
+ diff = Diff(self, Name('example.org.'))
+ diff.add_data(self.__rrset1)
+ diff.remove_data(self.__rrset2)
+ dlist = [('add', self.__rrset1), ('remove', self.__rrset2)]
+ self.assertEqual(dlist, diff.get_buffer())
+ # Do the apply, hook the compact method
+ diff.compact = self.__mock_compact
+ diff.apply()
+ # It should call the compact
+ self.assertTrue(self.__compact_called)
+ # And pass the data. Our local history of what happened is the same
+ # format, so we can check the same way
+ self.assertEqual(dlist, self.__data_operations)
+ # And the buffer in diff should become empty, as everything
+ # got inside.
+ self.assertEqual([], diff.get_buffer())
+
+ def test_commit(self):
+ """
+ If we call a commit, it should first apply whatever changes are
+ left (we hook into that instead of checking the effect) and then
+ the commit on the updater should have been called.
+
+ Then we check it raises value error for whatever operation we try.
+ """
+ diff = Diff(self, Name('example.org.'))
+ diff.add_data(self.__rrset1)
+ diff.apply = self.__mock_apply
+ diff.commit()
+ self.assertTrue(self.__apply_called)
+ self.assertTrue(self.__commit_called)
+ # The data should be handled by apply which we replaced.
+ self.assertEqual([], self.__data_operations)
+
+if __name__ == "__main__":
+ isc.log.init("bind10")
+ unittest.main()
More information about the bind10-changes
mailing list