コード例 #1
0
ファイル: datasrc_test.py プロジェクト: Absolight/bundy
def test_findall_common(self, tested):
    """
    Common part of the find_all test. It tests a find_all method on the passed
    object.
    """
    # Some "failure" responses
    result, rrset, _ = tested.find_all(bundy.dns.Name("www.sql1.example.com"),
                                       ZoneFinder.FIND_DEFAULT)
    self.assertEqual(ZoneFinder.DELEGATION, result)
    expected = RRset(Name('sql1.example.com.'), RRClass.IN, RRType.NS,
                     RRTTL(3600))
    expected.add_rdata(Rdata(RRType.NS, RRClass.IN,
                             'dns01.example.com.'))
    expected.add_rdata(Rdata(RRType.NS, RRClass.IN,
                             'dns02.example.com.'))
    expected.add_rdata(Rdata(RRType.NS, RRClass.IN,
                             'dns03.example.com.'))
    self.assertTrue(rrsets_equal(expected, rrset))

    result, rrset, _ = tested.find_all(bundy.dns.Name("nxdomain.example.com"),
                                       ZoneFinder.FIND_DEFAULT)
    self.assertEqual(ZoneFinder.NXDOMAIN, result)
    self.assertIsNone(None, rrset)

    # A success. It should return the list now.
    # This also tests we can ommit the options parameter
    result, rrsets, _ = tested.find_all(bundy.dns.Name("mix.example.com."))
    self.assertEqual(ZoneFinder.SUCCESS, result)
    self.assertEqual(2, len(rrsets))
    rrsets.sort(key=lambda rrset: rrset.get_type().to_text())
    expected = [
        RRset(Name('mix.example.com.'), RRClass.IN, RRType.A,
              RRTTL(3600)),
        RRset(Name('mix.example.com.'), RRClass.IN, RRType.AAAA,
              RRTTL(3600))
    ]
    expected[0].add_rdata(Rdata(RRType.A, RRClass.IN, "192.0.2.1"))
    expected[0].add_rdata(Rdata(RRType.A, RRClass.IN, "192.0.2.2"))
    expected[1].add_rdata(Rdata(RRType.AAAA, RRClass.IN,
                                "2001:db8::1"))
    expected[1].add_rdata(Rdata(RRType.AAAA, RRClass.IN,
                                "2001:db8::2"))
    for (rrset, exp) in zip(rrsets, expected):
        self.assertTrue(rrsets_equal(exp, rrset))

    # Check the reference counts on them. The getrefcount returns one more,
    # as for the reference in its own parameter - see its docs.

    # Two - one for the variable, one for parameter
    self.assertEqual(2, sys.getrefcount(rrsets))
    for rrset in rrsets:
        # 3 - one as the element of list, one for the rrset variable
        # and one for the parameter.
        self.assertEqual(3, sys.getrefcount(rrset))
コード例 #2
0
ファイル: datasrc_test.py プロジェクト: Absolight/bundy
 def test_journal_reader(self):
     # This is a straightforward port of the C++ 'journalReader' test
     self.make_simple_diff(create_soa(1234))
     result, self.reader = self.dsc.get_journal_reader(self.zname, 1234,
                                                       1235)
     self.assertEqual(ZoneJournalReader.SUCCESS, result)
     self.assertNotEqual(None, self.reader)
     rrsets_equal(create_soa(1234), self.reader.get_next_diff())
     rrsets_equal(create_soa(1235), self.reader.get_next_diff())
     self.assertEqual(None, self.reader.get_next_diff())
     self.assertRaises(ValueError, self.reader.get_next_diff)
コード例 #3
0
 def test_journal_reader(self):
     # This is a straightforward port of the C++ 'journalReader' test
     self.make_simple_diff(create_soa(1234))
     result, self.reader = self.dsc.get_journal_reader(
         self.zname, 1234, 1235)
     self.assertEqual(ZoneJournalReader.SUCCESS, result)
     self.assertNotEqual(None, self.reader)
     rrsets_equal(create_soa(1234), self.reader.get_next_diff())
     rrsets_equal(create_soa(1235), self.reader.get_next_diff())
     self.assertEqual(None, self.reader.get_next_diff())
     self.assertRaises(ValueError, self.reader.get_next_diff)
コード例 #4
0
def test_findall_common(self, tested):
    """
    Common part of the find_all test. It tests a find_all method on the passed
    object.
    """
    # Some "failure" responses
    result, rrset, _ = tested.find_all(bundy.dns.Name("www.sql1.example.com"),
                                       ZoneFinder.FIND_DEFAULT)
    self.assertEqual(ZoneFinder.DELEGATION, result)
    expected = RRset(Name('sql1.example.com.'), RRClass.IN, RRType.NS,
                     RRTTL(3600))
    expected.add_rdata(Rdata(RRType.NS, RRClass.IN, 'dns01.example.com.'))
    expected.add_rdata(Rdata(RRType.NS, RRClass.IN, 'dns02.example.com.'))
    expected.add_rdata(Rdata(RRType.NS, RRClass.IN, 'dns03.example.com.'))
    self.assertTrue(rrsets_equal(expected, rrset))

    result, rrset, _ = tested.find_all(bundy.dns.Name("nxdomain.example.com"),
                                       ZoneFinder.FIND_DEFAULT)
    self.assertEqual(ZoneFinder.NXDOMAIN, result)
    self.assertIsNone(None, rrset)

    # A success. It should return the list now.
    # This also tests we can ommit the options parameter
    result, rrsets, _ = tested.find_all(bundy.dns.Name("mix.example.com."))
    self.assertEqual(ZoneFinder.SUCCESS, result)
    self.assertEqual(2, len(rrsets))
    rrsets.sort(key=lambda rrset: rrset.get_type().to_text())
    expected = [
        RRset(Name('mix.example.com.'), RRClass.IN, RRType.A, RRTTL(3600)),
        RRset(Name('mix.example.com.'), RRClass.IN, RRType.AAAA, RRTTL(3600))
    ]
    expected[0].add_rdata(Rdata(RRType.A, RRClass.IN, "192.0.2.1"))
    expected[0].add_rdata(Rdata(RRType.A, RRClass.IN, "192.0.2.2"))
    expected[1].add_rdata(Rdata(RRType.AAAA, RRClass.IN, "2001:db8::1"))
    expected[1].add_rdata(Rdata(RRType.AAAA, RRClass.IN, "2001:db8::2"))
    for (rrset, exp) in zip(rrsets, expected):
        self.assertTrue(rrsets_equal(exp, rrset))

    # Check the reference counts on them. The getrefcount returns one more,
    # as for the reference in its own parameter - see its docs.

    # Two - one for the variable, one for parameter
    self.assertEqual(2, sys.getrefcount(rrsets))
    for rrset in rrsets:
        # 3 - one as the element of list, one for the rrset variable
        # and one for the parameter.
        self.assertEqual(3, sys.getrefcount(rrset))
コード例 #5
0
ファイル: datasrc_test.py プロジェクト: Absolight/bundy
 def test_iterator_soa(self):
     dsc = bundy.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
     iterator = dsc.get_iterator(bundy.dns.Name("sql1.example.com."))
     expected_soa = bundy.dns.RRset(bundy.dns.Name("sql1.example.com."),
                                  bundy.dns.RRClass.IN,
                                  bundy.dns.RRType.SOA,
                                  bundy.dns.RRTTL(3600))
     expected_soa.add_rdata(bundy.dns.Rdata(bundy.dns.RRType.SOA,
                                          bundy.dns.RRClass.IN,
                                          "master.example.com. " +
                                          "admin.example.com. 678 " +
                                          "3600 1800 2419200 7200"))
     self.assertTrue(rrsets_equal(expected_soa, iterator.get_soa()))
コード例 #6
0
 def test_iterator_soa(self):
     dsc = bundy.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
     iterator = dsc.get_iterator(bundy.dns.Name("sql1.example.com."))
     expected_soa = bundy.dns.RRset(bundy.dns.Name("sql1.example.com."),
                                    bundy.dns.RRClass.IN,
                                    bundy.dns.RRType.SOA,
                                    bundy.dns.RRTTL(3600))
     expected_soa.add_rdata(
         bundy.dns.Rdata(
             bundy.dns.RRType.SOA, bundy.dns.RRClass.IN,
             "master.example.com. " + "admin.example.com. 678 " +
             "3600 1800 2419200 7200"))
     self.assertTrue(rrsets_equal(expected_soa, iterator.get_soa()))
コード例 #7
0
ファイル: datasrc_test.py プロジェクト: Absolight/bundy
    def test_journal_reader_large_journal(self):
        # This is a straightforward port of the C++ 'readLargeJournal' test.
        # In this test we use the ZoneJournalReader object as a Python
        # iterator.
        updater = self.dsc.get_updater(self.zname, False, True)
        expected = []
        for i in range(0, 100):
            rrset = create_soa(1234 + i)
            updater.delete_rrset(rrset)
            expected.append(rrset)

            rrset = create_soa(1234 + i + 1)
            updater.add_rrset(rrset)
            expected.append(rrset)

        updater.commit()
        _, self.reader = self.dsc.get_journal_reader(self.zname, 1234, 1334)
        self.assertNotEqual(None, self.reader)
        i = 0
        for rr in self.reader:
            self.assertNotEqual(len(expected), i)
            rrsets_equal(expected[i], rr)
            i += 1
        self.assertEqual(len(expected), i)
コード例 #8
0
    def test_journal_reader_large_journal(self):
        # This is a straightforward port of the C++ 'readLargeJournal' test.
        # In this test we use the ZoneJournalReader object as a Python
        # iterator.
        updater = self.dsc.get_updater(self.zname, False, True)
        expected = []
        for i in range(0, 100):
            rrset = create_soa(1234 + i)
            updater.delete_rrset(rrset)
            expected.append(rrset)

            rrset = create_soa(1234 + i + 1)
            updater.add_rrset(rrset)
            expected.append(rrset)

        updater.commit()
        _, self.reader = self.dsc.get_journal_reader(self.zname, 1234, 1334)
        self.assertNotEqual(None, self.reader)
        i = 0
        for rr in self.reader:
            self.assertNotEqual(len(expected), i)
            rrsets_equal(expected[i], rr)
            i += 1
        self.assertEqual(len(expected), i)
コード例 #9
0
ファイル: datasrc_test.py プロジェクト: Absolight/bundy
def check_for_rrset(expected_rrsets, rrset):
    for cur_rrset in expected_rrsets[:]:
        if rrsets_equal(cur_rrset, rrset):
            expected_rrsets.remove(cur_rrset)
            return True
    return False
コード例 #10
0
def check_for_rrset(expected_rrsets, rrset):
    for cur_rrset in expected_rrsets[:]:
        if rrsets_equal(cur_rrset, rrset):
            expected_rrsets.remove(cur_rrset)
            return True
    return False