Skip to content

Commit

Permalink
[FIX] cetmix_tower_server: Connection test
Browse files Browse the repository at this point in the history
Ensure all attempts are used if the connection fails.
  • Loading branch information
ivs-cetmix committed Jan 17, 2025
1 parent 4a49208 commit 2a5d80b
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions cetmix_tower_server/models/cetmix_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,32 @@ def server_check_ssh_connection(

# Try connecting multiple times
for attempt in range(1, attempts + 1):
result = server.test_ssh_connection(
raise_on_error=False,
return_notification=False,
try_command=try_command,
try_file=try_file,
)
if result.get("status") == 0:
return {
"exit_code": 0,
"message": _("Connection successful."),
}
if attempt == attempts:
return {
"exit_code": SSH_CONNECTION_ERROR,
"message": _(
"Failed to connect after %(attempts)s attempts. "
"Error: %(err)s",
attempts=attempts,
err=result.get("error", ""),
),
}
try:
result = server.test_ssh_connection(
raise_on_error=True,
return_notification=False,
try_command=try_command,
try_file=try_file,
)
if result.get("status") == 0:
return {
"exit_code": 0,
"message": _("Connection successful."),
}
if attempt == attempts:
return {
"exit_code": SSH_CONNECTION_ERROR,
"message": _(
"Failed to connect after %(attempts)s attempts. "
"Error: %(err)s",
attempts=attempts,
err=result.get("error", ""),
),
}
except Exception as e:
if attempt == attempts:
return {
"exit_code": SSH_CONNECTION_ERROR,
"message": _(f"Failed to connect. Error: {e}"),
}
time.sleep(wait_time)

0 comments on commit 2a5d80b

Please sign in to comment.