]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Cleanup start and stop code 11070/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 3 Dec 2021 14:29:09 +0000 (15:29 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 6 Dec 2021 08:21:40 +0000 (09:21 +0100)
- more clearly print startup logs in case of exec error
- do not try to kill a process that's already dead
- do not call exit, but throw an AssertionError on startup issues

Also print logs on no exception

regression-tests.recursor-dnssec/recursortests.py
regression-tests.recursor-dnssec/test_API.py

index 4b11850691d643a55f496ae15addf7f4c965f3d9..9a565395b64712e45feb2c2d5de6b5a9ce85ca8c 100644 (file)
@@ -556,14 +556,11 @@ distributor-threads={threads}""".format(confdir=confdir,
         cls.waitForTCPSocket(ipaddress, 53)
 
         if cls._auths[ipaddress].poll() is not None:
-            try:
-                cls._auths[ipaddress].kill()
-            except OSError as e:
-                if e.errno != errno.ESRCH:
-                    raise
-                with open(logFile, 'r') as fdLog:
-                    print(fdLog.read())
-            sys.exit(cls._auths[ipaddress].returncode)
+            print(f"\n*** startAuth log for {logFile} ***")
+            with open(logFile, 'r') as fdLog:
+                print(fdLog.read())
+            print(f"*** End startAuth log for {logFile} ***")
+            raise AssertionError('%s failed (%d)' % (authcmd, cls._auths[ipaddress].returncode))
 
     @classmethod
     def generateRecursorConfig(cls, confdir):
@@ -619,14 +616,11 @@ distributor-threads={threads}""".format(confdir=confdir,
         cls.waitForTCPSocket("127.0.0.1", port)
 
         if cls._recursor.poll() is not None:
-            try:
-                cls._recursor.kill()
-            except OSError as e:
-                if e.errno != errno.ESRCH:
-                    raise
-                with open(logFile, 'r') as fdLog:
-                    print(fdLog.read())
-            sys.exit(cls._recursor.returncode)
+            print(f"\n*** startRecursor log for {logFile} ***")
+            with open(logFile, 'r') as fdLog:
+                print(fdLog.read())
+            print(f"*** End startRecursor log for {logFile} ***")
+            raise AssertionError('%s failed (%d)' % (recursorcmd, _recursor.returncode))
 
     @classmethod
     def wipeRecursorCache(cls, confdir):
@@ -674,6 +668,9 @@ distributor-threads={threads}""".format(confdir=confdir,
 
     @classmethod
     def killProcess(cls, p):
+        # Don't try to kill it if it's already dead
+        if p.poll() is not None:
+            return
         try:
             p.terminate()
             for count in range(10):
index 29ec49718b59770ad1ad0095144ade05fc9c2eff..07fc05aa154aa6827d47654f4312b0d2fcaf670d 100644 (file)
@@ -39,6 +39,7 @@ api-key=%s
 """ % (_wsPort, _wsPassword, _apiKey)
 
     def testAPI(self):
+        self.waitForTCPSocket("127.0.0.1", self._wsPort)
         headers = {'x-api-key': self._apiKey}
         url = 'http://127.0.0.1:' + str(self._wsPort) + '/api/v1/servers/localhost/statistics'
         r = requests.get(url, headers=headers, timeout=self._wsTimeout)
@@ -63,6 +64,7 @@ api-key=%s
 """ % (_wsPort, _wsPassword, _apiKey)
 
     def testAPI(self):
+        self.waitForTCPSocket("127.0.0.1", self._wsPort)
         headers = {'x-api-key': self._apiKey}
         url = 'http://127.0.0.1:' + str(self._wsPort) + '/api/v1/servers/localhost/statistics'
         try: