From: Remi Gacogne Date: Thu, 14 Feb 2019 10:55:47 +0000 (+0100) Subject: dnsdist: Preserve configuration and log files in regression tests X-Git-Tag: auth-4.2.0-beta1~16^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aac2124be90dfc44e38bcfd0774b08c368ca3cf4;p=thirdparty%2Fpdns.git dnsdist: Preserve configuration and log files in regression tests --- diff --git a/regression-tests.dnsdist/.gitignore b/regression-tests.dnsdist/.gitignore index 8502da2174..c970bcaf65 100644 --- a/regression-tests.dnsdist/.gitignore +++ b/regression-tests.dnsdist/.gitignore @@ -2,17 +2,16 @@ /*.xml /*.pid /*.pyc -dnsdist_*.conf -DNSCryptResolver* -.dnsdist_history -.history -dnsdist.log +/DNSCryptResolver* +/.dnsdist_history +/.history /*_pb2.py /__pycache__/ -ca.key -ca.pem -ca.srl -server.chain -server.csr -server.key -server.pem +/ca.key +/ca.pem +/ca.srl +/server.chain +/server.csr +/server.key +/server.pem +/configs \ No newline at end of file diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index bda4b93212..e1df6cfa7d 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -46,7 +46,6 @@ class DNSDistTest(unittest.TestCase): _dnsdistStartupDelay = 2.0 _dnsdist = None _responsesCounter = {} - _shutUp = True _config_template = """ """ _config_params = ['_testServerPort'] @@ -69,16 +68,16 @@ class DNSDistTest(unittest.TestCase): cls._TCPResponder.start() @classmethod - def startDNSDist(cls, shutUp=True): + def startDNSDist(cls): print("Launching dnsdist..") - conffile = 'dnsdist_test.conf' + confFile = os.path.join('configs', 'dnsdist_%s.conf' % (cls.__name__)) params = tuple([getattr(cls, param) for param in cls._config_params]) print(params) - with open(conffile, 'w') as conf: + with open(confFile, 'w') as conf: conf.write("-- Autogenerated by dnsdisttests.py\n") conf.write(cls._config_template % params) - dnsdistcmd = [os.environ['DNSDISTBIN'], '-C', conffile, + dnsdistcmd = [os.environ['DNSDISTBIN'], '-C', confFile, '-l', '%s:%d' % (cls._dnsDistListeningAddr, cls._dnsDistPort) ] for acl in cls._acl: dnsdistcmd.extend(['--acl', acl]) @@ -90,14 +89,13 @@ class DNSDistTest(unittest.TestCase): output = subprocess.check_output(testcmd, stderr=subprocess.STDOUT, close_fds=True) except subprocess.CalledProcessError as exc: raise AssertionError('dnsdist --check-config failed (%d): %s' % (exc.returncode, exc.output)) - if output != b'Configuration \'dnsdist_test.conf\' OK!\n': + expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode() + if output != expectedOutput: raise AssertionError('dnsdist --check-config failed: %s' % output) - if shutUp: - with open(os.devnull, 'w') as fdDevNull: - cls._dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull) - else: - cls._dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True) + logFile = os.path.join('configs', 'dnsdist_%s.log' % (cls.__name__)) + with open(logFile, 'w') as fdLog: + cls._dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdLog, stderr=fdLog) if 'DNSDIST_FAST_TESTS' in os.environ: delay = 0.5 @@ -121,7 +119,7 @@ class DNSDistTest(unittest.TestCase): def setUpClass(cls): cls.startResponders() - cls.startDNSDist(cls._shutUp) + cls.startDNSDist() cls.setUpSockets() print("Launching tests..") diff --git a/regression-tests.dnsdist/runtests b/regression-tests.dnsdist/runtests index 8802191cc3..45e34dfbe7 100755 --- a/regression-tests.dnsdist/runtests +++ b/regression-tests.dnsdist/runtests @@ -20,6 +20,8 @@ pip install -r requirements.txt protoc -I=../pdns/ --python_out=. ../pdns/dnsmessage.proto protoc -I=../pdns/ --python_out=. ../pdns/dnstap.proto +mkdir -p configs + if [ -z "${DNSDISTBIN}" ]; then DNSDISTBIN=$(ls ../pdns/dnsdistdist/dnsdist-*/dnsdist) fi @@ -39,6 +41,12 @@ openssl x509 -req -days 1 -CA ca.pem -CAkey ca.key -CAcreateserial -in server.cs # Generate a chain cat server.pem ca.pem >> server.chain -nosetests --with-xunit $@ +if ! nosetests --with-xunit $@; then + for log in configs/*.log; do + echo "=== ${log} ===" + cat "${log}" + done + false +fi rm ca.key ca.pem ca.srl server.csr server.key server.pem server.chain