dnsdist: Preserve configuration and log files in regression tests
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 14 Feb 2019 10:55:47 +0000 (11:55 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 14 Feb 2019 11:19:36 +0000 (12:19 +0100)
regression-tests.dnsdist/.gitignore
regression-tests.dnsdist/dnsdisttests.py
regression-tests.dnsdist/runtests

index 8502da2174c4eb02ad840e10549a5ef2ca7993a0..c970bcaf655aee4855dda45e103e84bcbaac611a 100644 (file)
@@ -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
index bda4b93212bb46f2ea448640aed1f3d98ba60581..e1df6cfa7df44a5631334af0776505a88560a587 100644 (file)
@@ -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..")
index 8802191cc3900eff312f16f9225218215ac2bf99..45e34dfbe7a8bcd9f860735e1b1f235657e4c708 100755 (executable)
@@ -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