Skip to content

Commit

Permalink
[FIX] cetmix_tower_server: Connection test
Browse files Browse the repository at this point in the history
Fix connection test

Task: 4256
  • Loading branch information
GabbasovDinar committed Jan 14, 2025
1 parent b1e01f1 commit 55e350c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cetmix_tower_server/models/cetmix_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,18 @@ def server_check_ssh_connection(self, server_reference, attempts=5, timeout=15):

# Initialize SSH connection instance
ssh_connection = SSH(**ssh_params)

# Try connecting multiple times
for attempt in range(1, attempts + 1):
try:
ssh_connection.connection()
ssh_connection._connect()
return {
"code": 0,
"exit_code": 0,
"message": _("Connection successful."),
}
except TimeoutError as e:
if attempt == attempts:
return {
"code": SSH_CONNECTION_TIMEOUT,
"exit_code": SSH_CONNECTION_TIMEOUT,
"message": _(
"Connection timed out after %(attempts)s attempts. "
"Error: %(err)s",
Expand All @@ -170,7 +169,7 @@ def server_check_ssh_connection(self, server_reference, attempts=5, timeout=15):
except Exception as e:
if attempt == attempts:
return {
"code": SSH_CONNECTION_ERROR,
"exit_code": SSH_CONNECTION_ERROR,
"message": _(
"Failed to connect after %(attempts)s attempts. "
"Error: %(err)s",
Expand All @@ -183,6 +182,6 @@ def server_check_ssh_connection(self, server_reference, attempts=5, timeout=15):

# If all attempts fail
return {
"code": SSH_CONNECTION_ERROR,
"exit_code": SSH_CONNECTION_ERROR,
"message": _("All connection connection attempts have failed."),
}

0 comments on commit 55e350c

Please sign in to comment.