Example #1
0
    def test_add_delete_same(self):
        '''
        Test that if a record is added, then deleted, it is not added to
        both buffers, but remove from the addition, and vice versa
        '''
        diff = Diff(self, Name('example.org.'), single_update_mode=True)
        # Need SOA records first
        diff.delete_data(self.__rrset_soa)
        diff.add_data(self.__rrset_soa)

        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(1, len(additions))

        diff.add_data(self.__rrset1)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(2, len(additions))

        diff.delete_data(self.__rrset1)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(1, len(additions))

        diff.delete_data(self.__rrset2)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(2, len(deletions))
        self.assertEqual(1, len(additions))

        diff.add_data(self.__rrset2)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(1, len(additions))
Example #2
0
    def test_add_delete_same(self):
        '''
        Test that if a record is added, then deleted, it is not added to
        both buffers, but remove from the addition, and vice versa
        '''
        diff = Diff(self, Name('example.org.'), single_update_mode=True)
        # Need SOA records first
        diff.delete_data(self.__rrset_soa)
        diff.add_data(self.__rrset_soa)

        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(1, len(additions))

        diff.add_data(self.__rrset1)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(2, len(additions))

        diff.delete_data(self.__rrset1)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(1, len(additions))

        diff.delete_data(self.__rrset2)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(2, len(deletions))
        self.assertEqual(1, len(additions))

        diff.add_data(self.__rrset2)
        deletions, additions = diff.get_single_update_buffers()
        self.assertEqual(1, len(deletions))
        self.assertEqual(1, len(additions))
Example #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())
Example #4
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())
Example #5
0
    def test_single_update_mode(self):
        '''
        Test single-update mode. In this mode, updates and deletes can
        be done in any order, but there may only be one changeset.
        For both updates and deletes, exactly one SOA rr must be given,
        and it must be the first change.
        '''

        # full rrset for A (to check compact())
        txt = RRset(Name('c.example.org.'), self.__rrclass, RRType.TXT,
                    RRTTL(3600))
        txt.add_rdata(Rdata(txt.get_type(), txt.get_class(), "one"))
        txt.add_rdata(Rdata(txt.get_type(), txt.get_class(), "two"))
        txt.add_rdata(Rdata(txt.get_type(), txt.get_class(), "three"))
        a = RRset(Name('d.example.org.'), self.__rrclass, RRType.A,
                  RRTTL(3600))
        a.add_rdata(Rdata(a.get_type(), a.get_class(), "192.0.2.1"))
        a.add_rdata(Rdata(a.get_type(), a.get_class(), "192.0.2.2"))

        diff = Diff(self, Name('example.org.'), single_update_mode=True)

        # adding a first should fail
        self.assertRaises(ValueError, diff.add_data, a)
        # But soa should work
        diff.add_data(self.__rrset_soa)
        # And then A should as well
        diff.add_data(self.__rrset3)
        diff.add_data(self.__rrset4)
        diff.add_data(self.__rrset5)
        # But another SOA should fail again
        self.assertRaises(ValueError, diff.add_data, self.__rrset_soa)

        # Same for delete
        self.assertRaises(ValueError, diff.delete_data, self.__rrset6)
        diff.delete_data(self.__rrset_soa)
        diff.delete_data(self.__rrset6)
        diff.delete_data(self.__rrset7)
        self.assertRaises(ValueError, diff.delete_data, self.__rrset_soa)

        # Not compacted yet, so the buffers should be as we
        # filled them
        (delbuf, addbuf) = diff.get_single_update_buffers()
        self.assertEqual([('delete', self.__rrset_soa),
                          ('delete', self.__rrset6),
                          ('delete', self.__rrset7)], delbuf)
        self.assertEqual([('add', self.__rrset_soa), ('add', self.__rrset3),
                          ('add', self.__rrset4), ('add', self.__rrset5)],
                         addbuf)

        # Compact should compact the A records in both buffers
        diff.compact()
        (delbuf, addbuf) = diff.get_single_update_buffers()
        # need rrset equality again :/
        self.assertEqual(2, len(delbuf))
        self.assertEqual(2, len(delbuf[0]))
        self.assertEqual('delete', delbuf[0][0])
        self.assertEqual(self.__rrset_soa.to_text(), delbuf[0][1].to_text())
        self.assertEqual(2, len(delbuf[1]))
        self.assertEqual('delete', delbuf[1][0])
        self.assertEqual(a.to_text(), delbuf[1][1].to_text())

        self.assertEqual(2, len(addbuf))
        self.assertEqual(2, len(addbuf[0]))
        self.assertEqual('add', addbuf[0][0])
        self.assertEqual(self.__rrset_soa.to_text(), addbuf[0][1].to_text())
        self.assertEqual(2, len(addbuf[1]))
        self.assertEqual('add', addbuf[1][0])
        self.assertEqual(txt.to_text(), addbuf[1][1].to_text())

        # Apply should reset the buffers
        diff.apply()
        (delbuf, addbuf) = diff.get_single_update_buffers()
        self.assertEqual([], delbuf)
        self.assertEqual([], addbuf)

        # Now the change has been applied, and the buffers are cleared,
        # Adding non-SOA records should fail again.
        self.assertRaises(ValueError, diff.add_data, a)
        self.assertRaises(ValueError, diff.delete_data, a)
Example #6
0
    def test_single_update_mode(self):
        '''
        Test single-update mode. In this mode, updates and deletes can
        be done in any order, but there may only be one changeset.
        For both updates and deletes, exactly one SOA rr must be given,
        and it must be the first change.
        '''

        # full rrset for A (to check compact())
        txt = RRset(Name('c.example.org.'), self.__rrclass, RRType.TXT,
                    RRTTL(3600))
        txt.add_rdata(Rdata(txt.get_type(), txt.get_class(), "one"))
        txt.add_rdata(Rdata(txt.get_type(), txt.get_class(), "two"))
        txt.add_rdata(Rdata(txt.get_type(), txt.get_class(), "three"))
        a = RRset(Name('d.example.org.'), self.__rrclass, RRType.A,
                  RRTTL(3600))
        a.add_rdata(Rdata(a.get_type(), a.get_class(), "192.0.2.1"))
        a.add_rdata(Rdata(a.get_type(), a.get_class(), "192.0.2.2"))

        diff = Diff(self, Name('example.org.'), single_update_mode=True)

        # adding a first should fail
        self.assertRaises(ValueError, diff.add_data, a)
        # But soa should work
        diff.add_data(self.__rrset_soa)
        # And then A should as well
        diff.add_data(self.__rrset3)
        diff.add_data(self.__rrset4)
        diff.add_data(self.__rrset5)
        # But another SOA should fail again
        self.assertRaises(ValueError, diff.add_data, self.__rrset_soa)

        # Same for delete
        self.assertRaises(ValueError, diff.delete_data, self.__rrset6)
        diff.delete_data(self.__rrset_soa)
        diff.delete_data(self.__rrset6)
        diff.delete_data(self.__rrset7)
        self.assertRaises(ValueError, diff.delete_data, self.__rrset_soa)

        # Not compacted yet, so the buffers should be as we
        # filled them
        (delbuf, addbuf) = diff.get_single_update_buffers()
        self.assertEqual([('delete', self.__rrset_soa),
                          ('delete', self.__rrset6),
                          ('delete', self.__rrset7)], delbuf)
        self.assertEqual([('add', self.__rrset_soa),
                          ('add', self.__rrset3),
                          ('add', self.__rrset4),
                          ('add', self.__rrset5)], addbuf)

        # Compact should compact the A records in both buffers
        diff.compact()
        (delbuf, addbuf) = diff.get_single_update_buffers()
        # need rrset equality again :/
        self.assertEqual(2, len(delbuf))
        self.assertEqual(2, len(delbuf[0]))
        self.assertEqual('delete', delbuf[0][0])
        self.assertEqual(self.__rrset_soa.to_text(), delbuf[0][1].to_text())
        self.assertEqual(2, len(delbuf[1]))
        self.assertEqual('delete', delbuf[1][0])
        self.assertEqual(a.to_text(), delbuf[1][1].to_text())

        self.assertEqual(2, len(addbuf))
        self.assertEqual(2, len(addbuf[0]))
        self.assertEqual('add', addbuf[0][0])
        self.assertEqual(self.__rrset_soa.to_text(), addbuf[0][1].to_text())
        self.assertEqual(2, len(addbuf[1]))
        self.assertEqual('add', addbuf[1][0])
        self.assertEqual(txt.to_text(), addbuf[1][1].to_text())

        # Apply should reset the buffers
        diff.apply()
        (delbuf, addbuf) = diff.get_single_update_buffers()
        self.assertEqual([], delbuf)
        self.assertEqual([], addbuf)

        # Now the change has been applied, and the buffers are cleared,
        # Adding non-SOA records should fail again.
        self.assertRaises(ValueError, diff.add_data, a)
        self.assertRaises(ValueError, diff.delete_data, a)