Skip to content

Commit

Permalink
minor modifications to gcp_auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarsh2001 committed Oct 6, 2023
1 parent bd59d21 commit 250afa1
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions .github/auth/vm_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@ def _start_ssh_session(response, creds, username, passphrase):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
ssh.connect(
external_ip,
username=username,
key_filename=creds,
passphrase=passphrase,
)
print("SSH session successful !")
except Exception as e:
print(e)
max_retries = 3
retry_delay = 10 # seconds

for _ in range(max_retries):
# ssh connection fails non-deterministically
try:
ssh.connect(
external_ip,
username=username,
key_filename=creds,
passphrase=passphrase,
)
print("SSH session successful !")
except paramiko.ssh_exception.NoValidConnectionsError as e:
print(f"SSH Exception(NoValidConnectionsError): {e}")
time.sleep(retry_delay)
except paramiko.ssh_exception.SSHException as e:
print(f"SSH Exception(General): {e}")
except paramiko.ssh_exception.AuthenticationException as e:
print(f"Authentication failed: {e}")
return

# Open an SSH session
transport = ssh.get_transport()
Expand Down

0 comments on commit 250afa1

Please sign in to comment.