From: Peter van Dijk Date: Thu, 26 Aug 2021 10:27:07 +0000 (+0200) Subject: dnsdist test: generate CDB files X-Git-Tag: dnsdist-1.7.0-alpha1~49^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10673%2Fhead;p=thirdparty%2Fpdns.git dnsdist test: generate CDB files --- diff --git a/regression-tests.dnsdist/kvs.cdb.1 b/regression-tests.dnsdist/kvs.cdb.1 deleted file mode 100644 index 4d3ba74a9e..0000000000 Binary files a/regression-tests.dnsdist/kvs.cdb.1 and /dev/null differ diff --git a/regression-tests.dnsdist/kvs.cdb.2 b/regression-tests.dnsdist/kvs.cdb.2 deleted file mode 100644 index abd9648bb7..0000000000 Binary files a/regression-tests.dnsdist/kvs.cdb.2 and /dev/null differ diff --git a/regression-tests.dnsdist/requirements.txt b/regression-tests.dnsdist/requirements.txt index 99b8454c55..afa9fa76ec 100644 --- a/regression-tests.dnsdist/requirements.txt +++ b/regression-tests.dnsdist/requirements.txt @@ -7,3 +7,4 @@ pysnmp>=4.3.4 future>=0.17.1 pycurl>=7.43.0 lmdb>=0.95 +cdbx==0.1.2 diff --git a/regression-tests.dnsdist/test_CDB.py b/regression-tests.dnsdist/test_CDB.py index 89026290f2..2ed764ce86 100644 --- a/regression-tests.dnsdist/test_CDB.py +++ b/regression-tests.dnsdist/test_CDB.py @@ -1,12 +1,21 @@ #!/usr/bin/env python +import cdbx import unittest import dns import os -import shutil import socket import time from dnsdisttests import DNSDistTest +def writeCDB(fname, variant=1): + cdb = cdbx.CDB.make(fname+'.tmp') + cdb.add(socket.inet_aton(f'127.0.0.{variant}'), b'this is the value of the source address tag') + cdb.add(b'\x05qname\x03cdb\x05tests\x08powerdns\x03com\x00', b'this is the value of the qname tag') + cdb.add(b'\x06suffix\x03cdb\x05tests\x08powerdns\x03com\x00', b'this is the value of the suffix tag') + cdb.add(b'this is the value of the qname tag', b'this is the value of the second tag') + cdb.commit().close() + os.rename(fname+'.tmp', fname) + @unittest.skipIf('SKIP_CDB_TESTS' in os.environ, 'CDB tests are disabled') class CDBTest(DNSDistTest): @@ -53,7 +62,7 @@ class TestCDBSimple(CDBTest): @classmethod def setUpCDB(cls): - shutil.copyfile('kvs.cdb.1', cls._cdbFileName) + writeCDB(cls._cdbFileName, 1) @classmethod def setUpClass(cls): @@ -138,7 +147,7 @@ class TestCDBReload(CDBTest): @classmethod def setUpCDB(cls): - shutil.copyfile('kvs.cdb.1', cls._cdbFileName) + writeCDB(cls._cdbFileName, 1) @classmethod def setUpClass(cls): @@ -174,8 +183,8 @@ class TestCDBReload(CDBTest): self.assertTrue(receivedResponse) self.assertEqual(expectedResponse, receivedResponse) - # switch to the second DB which has no entry for 127.0.0.1 - shutil.copyfile('kvs.cdb.2', self._cdbFileName) + # write a new CDB which has no entry for 127.0.0.1 + writeCDB(self._cdbFileName, 2) # wait long enough for the CDB database to be reloaded time.sleep(self._cdbRefreshDelay + 1)