From 98e438df00111541958b54543b3056c06783fd73 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 15 Feb 2012 09:29:27 +1100 Subject: wintest: Cope with nc not timing out even when -w 1 is specified --- wintest/wintest.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'wintest') diff --git a/wintest/wintest.py b/wintest/wintest.py index b58cff597d..8b8df2ce43 100644 --- a/wintest/wintest.py +++ b/wintest/wintest.py @@ -491,8 +491,22 @@ options { def port_wait(self, hostname, port, retries=200, delay=3, wait_for_fail=False): '''wait for a host to come up on the network''' - self.retry_cmd("nc -v -z -w 1 %s %u" % (hostname, port), ['succeeded'], - retries=retries, delay=delay, wait_for_fail=wait_for_fail) + + while retries > 0: + child = self.pexpect_spawn("nc -v -z -w 1 %s %u" % (hostname, port), crlf=False, timeout=1) + i = child.expect(['succeeded', 'failed', pexpect.EOF, pexpect.TIMEOUT]) + if wait_for_fail: + if i > 0: + return + else: + if i == 0: + return + + time.sleep(delay) + retries -= 1 + self.info("retrying (retries=%u delay=%u)" % (retries, delay)) + + raise RuntimeError("gave up waiting for %s:%d" % (hostname, port)) def run_net_time(self, child): '''run net time on windows''' -- cgit