Skip to content

Commit 357950b

Browse files
committed
test: imfamy: Allow broken images
If ping succeed but fail to check if netconf port is open, the testsystem will hang forever. This will allow totally broken images to be loaded at the device.
1 parent 20673c3 commit 357950b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

test/infamy/netutil.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import socket
22

3-
def tcp_port_is_open(host, port):
3+
def tcp_port_is_open(host, port, timeout=3):
44
try:
5-
ai = socket.getaddrinfo(host, port, 0, 0, socket.SOL_TCP)
6-
sock = socket.socket(ai[0][0], ai[0][1], 0)
7-
sock.connect(ai[0][4])
8-
sock.close()
9-
return True
10-
except Exception:
5+
with socket.create_connection((host, port), timeout=timeout):
6+
return True
7+
except (socket.timeout, OSError):
118
return False

0 commit comments

Comments
 (0)