Fix unit tests on Windows

Relatively small fix enabling tests to pass on Windows. Connecting
to the ANY address on Windows is not allowed. Also, paths in Windows,
most times contain a colon. Doing a split() on a string such as
80:C:\test will yield 3 elements, not 2.

Change-Id: Icbf466940d4f1ac2a1d48c63839cd31e2ec62581
This commit is contained in:
Gabriel Adrian Samfira 2016-07-13 19:00:52 +03:00
parent a9f31a0b9d
commit 0c00db8604
2 changed files with 8 additions and 3 deletions
oslo_middleware

@ -52,7 +52,9 @@ class DisableByFilesPortsHealthcheck(pluginbase.HealthcheckBaseExtension):
for port_path in paths.split(","):
port_path = port_path.strip()
if port_path:
port, path = port_path.split(":")
# On windows, drive letters are followed by colons,
# which makes split() return 3 elements in this case
port, path = port_path.split(":", 1)
port = int(port)
yield (port, path)

@ -35,8 +35,11 @@ class HealthcheckMainTests(test_base.BaseTestCase):
self.addCleanup(server.shutdown)
while True:
try:
r = requests.get("http://%s:%s" % (server.server_address[0],
server.server_address[1]))
# Connecting on 0.0.0.0 is not allowed on windows
# The operating system will return WSAEADDRNOTAVAIL which
# in turn will throw a requests.ConnectionError
r = requests.get("http://127.0.0.1:%s" % (
server.server_address[1]))
except requests.ConnectionError:
# Server hasn't started up yet, try again in a few.
time.sleep(1)