From 32a176376fc2a0df1201d96adb5f88f0f7e4b0fe Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 3 Dec 2021 15:29:09 +0100 Subject: [PATCH] Cleanup start and stop code - 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 --- .../recursortests.py | 29 +++++++++---------- regression-tests.recursor-dnssec/test_API.py | 2 ++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/regression-tests.recursor-dnssec/recursortests.py b/regression-tests.recursor-dnssec/recursortests.py index 4b11850691..9a565395b6 100644 --- a/regression-tests.recursor-dnssec/recursortests.py +++ b/regression-tests.recursor-dnssec/recursortests.py @@ -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): diff --git a/regression-tests.recursor-dnssec/test_API.py b/regression-tests.recursor-dnssec/test_API.py index 29ec49718b..07fc05aa15 100644 --- a/regression-tests.recursor-dnssec/test_API.py +++ b/regression-tests.recursor-dnssec/test_API.py @@ -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: -- 2.39.2