Skip to content

Commit

Permalink
fix: netcat socket closing for healthcheck
Browse files Browse the repository at this point in the history
Change-Id: I0e26f1435e7c6722f7d6dd7f73bb9012ee76e875
  • Loading branch information
grafuls committed Sep 4, 2020
1 parent 4c29197 commit 04398b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion quads/tools/move_and_rebuild_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ async def move_and_rebuild(host, new_cloud, semaphore, rebuild=False, loop=None)
return False

healthy = False
nc = Netcat(_host_obj.name)
for i in range(RETRIES):
nc = Netcat(_host_obj.name)
if nc.health_check():
healthy = True
nc.close()
break
nc.close()

if not healthy:
logger.error("Failed to recover host after changing boot order.")
Expand Down
11 changes: 8 additions & 3 deletions quads/tools/netcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ def health_check(self, timeout=15):
try:
self.socket.settimeout(timeout)
self.connect()
except (TimeoutError, socket.timeout):
except (
socket.timeout,
TimeoutError,
ConnectionResetError,
ConnectionRefusedError,
):
return False
return True

Expand All @@ -37,8 +42,8 @@ def read_until(self, data):
self.buff += self.socket.recv(1024)

pos = self.buff.find(data)
return_val = self.buff[:pos + len(data)]
self.buff = self.buff[pos + len(data):]
return_val = self.buff[: pos + len(data)]
self.buff = self.buff[pos + len(data) :]

return return_val

Expand Down
2 changes: 2 additions & 0 deletions quads/tools/validate_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def post_system_test(self):
"Potential provisioning in process. SKIPPING."
)
continue
nc.close()
badfish = None
try:
badfish = loop.run_until_complete(
Expand Down Expand Up @@ -182,6 +183,7 @@ def post_network_test(self):
nc = Netcat(host.name)
if not nc.health_check():
hosts_down.append(host.name)
nc.close()
if len(host.interfaces) > len(test_host.interfaces):
test_host = host

Expand Down

0 comments on commit 04398b9

Please sign in to comment.