Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to address paramiko connection errors #2811

Merged
merged 24 commits into from
Nov 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions tests/tests_deployment/test_jupyterhub_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,53 @@
TIMEOUT_SECS = 300


@pytest.fixture(scope="function")
@pytest.fixture(scope="session")
viniciusdc marked this conversation as resolved.
Show resolved Hide resolved
def paramiko_object(jupyterhub_access_token):
"""Connects to JupyterHub ssh cluster from outside the cluster."""
"""
Connects to JupyterHub SSH cluster from outside the cluster with retry on
authentication errors.
"""

# Define the sequence of auth_timeouts in seconds
retry_timeouts = [2 * 60, 3 * 60, 5 * 60] # 2min, 3min, 5min

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
params = {
"hostname": constants.NEBARI_HOSTNAME,
"port": 8022,
"username": constants.KEYCLOAK_USERNAME,
"password": jupyterhub_access_token,
"allow_agent": constants.PARAMIKO_SSH_ALLOW_AGENT,
"look_for_keys": constants.PARAMIKO_SSH_LOOK_FOR_KEYS,
"auth_timeout": 5 * 60,
}

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for timeout in retry_timeouts:
params["auth_timeout"] = timeout
viniciusdc marked this conversation as resolved.
Show resolved Hide resolved
params["banner_timeout"] = timeout
try:
ssh_client.connect(**params)
break
except paramiko.AuthenticationException as auth_err:
if "failed to start server on time!" in str(auth_err):
if timeout == retry_timeouts[-1]:
ssh_client.close()
raise
else:
ssh_client.close()
raise
except paramiko.SSHException:
ssh_client.close()
raise
except Exception:
ssh_client.close()
raise
else:
ssh_client.close()
raise paramiko.AuthenticationException(
"Failed to authenticate after multiple attempts."
)
try:
ssh_client.connect(**params)
yield ssh_client
finally:
ssh_client.close()
Expand Down
Loading