Browse Source

[1259] Log when TTLs don't match

Michal 'vorner' Vaner 13 years ago
parent
commit
519720d9c6

+ 1 - 1
src/lib/python/isc/Makefile.am

@@ -1,5 +1,5 @@
 SUBDIRS = datasrc cc config dns log net notify util testutils acl bind10
-SUBDIRS += log_messages xfrin
+SUBDIRS += xfrin log_messages
 
 python_PYTHON = __init__.py
 

+ 2 - 0
src/lib/python/isc/log_messages/Makefile.am

@@ -11,6 +11,7 @@ EXTRA_DIST += zonemgr_messages.py
 EXTRA_DIST += cfgmgr_messages.py
 EXTRA_DIST += config_messages.py
 EXTRA_DIST += notify_out_messages.py
+EXTRA_DIST += libxfrin_messages.py
 
 CLEANFILES = __init__.pyc
 CLEANFILES += bind10_messages.pyc
@@ -23,6 +24,7 @@ CLEANFILES += zonemgr_messages.pyc
 CLEANFILES += cfgmgr_messages.pyc
 CLEANFILES += config_messages.pyc
 CLEANFILES += notify_out_messages.pyc
+CLEANFILES += libxfrin_messages.pyc
 
 CLEANDIRS = __pycache__
 

+ 1 - 0
src/lib/python/isc/log_messages/libxfrin_messages.py

@@ -0,0 +1 @@
+from work.libxfrin_messages import *

+ 11 - 0
src/lib/python/isc/xfrin/Makefile.am

@@ -1,6 +1,17 @@
 SUBDIRS = . tests
 
 python_PYTHON = __init__.py diff.py
+BUILT_SOURCES = $(PYTHON_LOGMSGPKG_DIR)/work/libxfrin_messages.py
+nodist_pylogmessage_PYTHON = $(PYTHON_LOGMSGPKG_DIR)/work/libxfrin_messages.py
+pylogmessagedir = $(pyexecdir)/isc/log_messages/
+
+CLEANFILES = $(PYTHON_LOGMSGPKG_DIR)/work/libxfrin_messages.py
+CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/work/libxfrin_messages.pyc
+
+# Define rule to build logging source files from message file
+$(PYTHON_LOGMSGPKG_DIR)/work/libxfrin_messages.py: libxfrin_messages.mes
+	$(top_builddir)/src/lib/log/compiler/message \
+		-d $(PYTHON_LOGMSGPKG_DIR)/work -p $(srcdir)/libxfrin_messages.mes
 
 pythondir = $(pyexecdir)/isc/xfrin
 

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

@@ -19,6 +19,8 @@ it to the datasource.
 """
 
 import isc.dns
+import isc.log
+from isc.log_messages.libxfrin_messages import *
 
 class NoSuchZone(Exception):
     """
@@ -37,6 +39,8 @@ number.
 # If changing this, modify the tests accordingly as well.
 DIFF_APPLY_TRESHOLD = 100
 
+logger = isc.log.Logger('libxfrin')
+
 class Diff:
     """
     The class represents a diff against current state of datasource on
@@ -150,6 +154,9 @@ class Diff:
                                               rrset.get_class(),
                                               rrset.get_type(),
                                               rrset.get_ttl())))
+            if rrset.get_ttl() != buf[-1][1].get_ttl():
+                logger.warn(LIBXFRIN_DIFFERENT_TTL, rrset.get_ttl(),
+                            buf[-1][1].get_ttl())
             for rdatum in rrset.get_rdata():
                 buf[-1][1].add_rdata(rdatum)
         self.__buffer = buf

+ 22 - 0
src/lib/python/isc/xfrin/libxfrin_messages.mes

@@ -0,0 +1,22 @@
+# Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC 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.
+
+# No namespace declaration - these constants go in the global namespace
+# of the libxfrin_messages python module.
+
+% LIBXFRIN_DIFFERENT_TTL multiple data with different TTLs (%1, %2) on %3/%4
+The xfrin module received an update containing multiple rdata changes for the
+same RRset. But the TTLs of these don't match each other. The data will be put
+into the underlying data source. What happens with the TTLs is up to the
+data source.

+ 29 - 0
src/lib/python/isc/xfrin/tests/diff_tests.py

@@ -45,6 +45,7 @@ class DiffTest(unittest.TestCase):
         self.__apply_called = False
         self.__commit_called = False
         self.__broken_called = False
+        self.__warn_called = False
         # Some common values
         self.__rrclass = RRClass.IN()
         self.__type = RRType.A()
@@ -90,6 +91,13 @@ class DiffTest(unittest.TestCase):
         self.__broken_called = True
         raise TestError("Test error")
 
+    def warn(self, *args):
+        """
+        This is for checking the warn function was called, we replace the logger
+        in the tested module.
+        """
+        self.__warn_called = True
+
     def commit(self):
         """
         This is part of pretending to be a zone updater. This notes the commit
@@ -396,6 +404,27 @@ class DiffTest(unittest.TestCase):
         self.commit = self.__broken_operation
         self.__do_raise_test()
 
+    def test_ttl(self):
+        """
+        Test the TTL handling. A warn function should have been called if they
+        differ, but that's all, it should not crash or raise.
+        """
+        orig_logger = isc.xfrin.diff.logger
+        try:
+            isc.xfrin.diff.logger = self
+            diff = Diff(self, Name('example.org.'))
+            diff.add_data(self.__rrset1)
+            rrset2 = RRset(Name('a.example.org.'), self.__rrclass,
+                                  self.__type, RRTTL(120))
+            rrset2.add_rdata(Rdata(self.__type, self.__rrclass, '192.10.2.2'))
+            diff.add_data(rrset2)
+            # They should get compacted together and complain.
+            diff.compact()
+            self.assertEqual(1, len(diff.get_buffer()))
+            self.assertTrue(self.__warn_called)
+        finally:
+            isc.xfrin.diff.logger = orig_logger
+
 if __name__ == "__main__":
     isc.log.init("bind10")
     unittest.main()