Exemplo n.º 1
0
 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.
     """
     self.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)
         rrset2 = RRset(Name('a.example.org.'), self.__rrclass,
                               self.__type, RRTTL(6000))
         rrset2.add_rdata(Rdata(self.__type, self.__rrclass, '192.10.2.3'))
         diff.add_data(rrset2)
         # They should get compacted together and complain.
         diff.compact()
         self.assertEqual(1, len(diff.get_buffer()))
         # The TTL stays on the first value, no matter if smaller or bigger
         # ones come later.
         self.assertEqual(self.__ttl, diff.get_buffer()[0][1].get_ttl())
         self.assertTrue(self.__warn_called)
     finally:
         isc.xfrin.diff.logger = self.orig_logger
Exemplo n.º 2
0
 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())
     # By default journaling is disabled
     self.assertFalse(self.__journaling_enabled)
Exemplo n.º 3
0
    def test_get_buffer(self):
        '''
        Test that the getters raise when used in the wrong mode
        '''
        diff_multi = Diff(self, Name('example.org.'), single_update_mode=False)
        self.assertRaises(ValueError, diff_multi.get_single_update_buffers)
        self.assertEqual([], diff_multi.get_buffer())

        diff_single = Diff(self, Name('example.org.'), single_update_mode=True)
        self.assertRaises(ValueError, diff_single.get_buffer)
        self.assertEqual(([], []), diff_single.get_single_update_buffers())
Exemplo n.º 4
0
 def test_autoapply(self):
     """
     Test the apply is called all by itself after 100 tasks are added.
     """
     diff = Diff(self, Name('example.org.'))
     # A method to check the apply is called _after_ the 100th element
     # is added. We don't use it anywhere else, so we define it locally
     # as lambda function
     def check():
         self.assertEqual(100, len(diff.get_buffer()))
         self.__mock_apply()
     orig_apply = diff.apply
     diff.apply = check
     # If we put 99, nothing happens yet
     for i in range(0, 99):
         diff.add_data(self.__rrset1)
     expected = [('add', self.__rrset1)] * 99
     self.assertEqual(expected, diff.get_buffer())
     self.assertFalse(self.__apply_called)
     # Now we push the 100th and it should call the apply method
     # This will _not_ flush the data yet, as we replaced the method.
     # It, however, would in the real life.
     diff.add_data(self.__rrset1)
     # Now the apply method (which is replaced by our check) should
     # have been called. If it wasn't, this is false. If it was, but
     # still with 99 elements, the check would complain
     self.assertTrue(self.__apply_called)
     # Reset the buffer by calling the original apply.
     orig_apply()
     self.assertEqual([], diff.get_buffer())
     # Similar with delete
     self.__apply_called = False
     for i in range(0, 99):
         diff.delete_data(self.__rrset2)
     expected = [('delete', self.__rrset2)] * 99
     self.assertEqual(expected, diff.get_buffer())
     self.assertFalse(self.__apply_called)
     diff.delete_data(self.__rrset2)
     self.assertTrue(self.__apply_called)
Exemplo n.º 5
0
 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.delete_data(self.__rrset2)
     dlist = [('add', self.__rrset1), ('delete', 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())
Exemplo n.º 6
0
    def test_rrsig_ttl(self):
        '''Similar to the previous test, but for RRSIGs of different covered
        types.

        They shouldn't be compacted.

        '''
        diff = Diff(self, Name('example.org.'))
        rrsig1 = RRset(Name('example.org'), self.__rrclass,
                       RRType.RRSIG(), RRTTL(3600))
        rrsig1.add_rdata(Rdata(RRType.RRSIG(), self.__rrclass,
                               'A 5 3 3600 20000101000000 20000201000000 ' +
                               '0 example.org. FAKEFAKEFAKE'))
        diff.add_data(rrsig1)
        rrsig2 = RRset(Name('example.org'), self.__rrclass,
                       RRType.RRSIG(), RRTTL(1800))
        rrsig2.add_rdata(Rdata(RRType.RRSIG(), self.__rrclass,
                               'AAAA 5 3 3600 20000101000000 20000201000000 ' +
                               '1 example.org. FAKEFAKEFAKE'))
        diff.add_data(rrsig2)
        diff.compact()
        self.assertEqual(2, len(diff.get_buffer()))
Exemplo n.º 7
0
    def test_compact(self):
        """
        Test the compaction works as expected, eg. it compacts only consecutive
        changes of the same operation and on the same domain/type.

        The test case checks that it does merge them, but also puts some
        different operations "in the middle", changes the type and name and
        places the same kind of change further away of each other to see they
        are not merged in that case.
        """
        diff = Diff(self, Name('example.org.'))
        # Check we can do a compact on empty data, it shouldn't break
        diff.compact()
        self.assertEqual([], diff.get_buffer())
        # This data is the way it should look like after the compact
        # ('operation', 'domain.prefix', 'type', ['rdata', 'rdata'])
        # The notes say why the each of consecutive can't be merged
        data = [
            ('add', 'a', 'A', ['192.0.2.1', '192.0.2.2']),
            # Different type.
            ('add', 'a', 'AAAA', ['2001:db8::1', '2001:db8::2']),
            # Different operation
            ('delete', 'a', 'AAAA', ['2001:db8::3']),
            # Different domain
            ('delete', 'b', 'AAAA', ['2001:db8::4']),
            # This does not get merged with the first, even if logically
            # possible. We just don't do this.
            ('add', 'a', 'A', ['192.0.2.3'])
            ]
        # Now, fill the data into the diff, in a "flat" way, one by one
        for (op, nprefix, rrtype, rdata) in data:
            name = Name(nprefix + '.example.org.')
            rrtype_obj = RRType(rrtype)
            for rdatum in rdata:
                rrset = RRset(name, self.__rrclass, rrtype_obj, self.__ttl)
                rrset.add_rdata(Rdata(rrtype_obj, self.__rrclass, rdatum))
                if op == 'add':
                    diff.add_data(rrset)
                else:
                    diff.delete_data(rrset)
        # Compact it
        diff.compact()
        # Now check they got compacted. They should be in the same order as
        # pushed inside. So it should be the same as data modulo being in
        # the rrsets and isc.dns objects.
        def check():
            buf = diff.get_buffer()
            self.assertEqual(len(data), len(buf))
            for (expected, received) in zip(data, buf):
                (eop, ename, etype, edata) = expected
                (rop, rrrset) = received
                self.assertEqual(eop, rop)
                ename_obj = Name(ename + '.example.org.')
                self.assertEqual(ename_obj, rrrset.get_name())
                # We check on names to make sure they are printed nicely
                self.assertEqual(etype, str(rrrset.get_type()))
                rdata = rrrset.get_rdata()
                self.assertEqual(len(edata), len(rdata))
                # It should also preserve the order
                for (edatum, rdatum) in zip(edata, rdata):
                    self.assertEqual(edatum, str(rdatum))
        check()
        # Try another compact does nothing, but survives
        diff.compact()
        check()