Module: check_mk
Branch: master
Commit: 84cbab1c0ce0bde95c9010ed5577393696861067
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=84cbab1c0ce0bd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 27 16:33:51 2018 +0200
Fixed unstable integration tests because of port conflicts
The previous "free port" detection was not sufficient because the
site is not always running and listenting on that port during tests.
This could lead to conflicts when different branch test jobs run.
Change-Id: Ic689330d17d18c2363774551d83bc0212ebc4ec6
---
tests/testlib/__init__.py | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 8e54bc7..96cfca3 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -2,6 +2,7 @@
# encoding: utf-8
import os
+import glob
import pwd
import time
import pytest
@@ -916,6 +917,8 @@ class Site(object):
if start_again:
self.start()
+ sys.stdout.write("After livestatus port lock\n")
+
def _gather_livestatus_port(self):
if self.reuse and self.exists():
@@ -927,21 +930,17 @@ class Site(object):
def get_free_port_from(self, port):
- while True:
- try:
- print "Trying port %d" % port
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- sock.bind(("127.0.0.1", port))
- sock.listen(1)
- sock.close()
-
- break # found a bindable port
- except socket.error, e:
- print "Failed to bind 127.0.0.1:%d: %s" % (port, e)
- port += 1
-
- print "Using port %d" % port
+ used_ports = set([])
+ for cfg_path in glob.glob("/omd/sites/*/etc/omd/site.conf"):
+ for line in cfg_path:
+ if line.startswith("CONFIG_LIVESTATUS_TCP_PORT="):
+ port = int(line.strip().split("=",
1)[1].strip("'"))
+ used_ports.add(port)
+
+ while port in used_ports:
+ port += 1
+
+ print "Livestatus ports already in use: %r, using port: %d" %
(used_ports, port)
return port
# Problem: The group change only affects new sessions of the test_user