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

Break connection loop on certain exceptions. #262

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Changes from all 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
13 changes: 13 additions & 0 deletions img_proof/ipa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from contextlib import contextmanager
from string import ascii_lowercase
from tempfile import NamedTemporaryFile
from paramiko.ssh_exception import AuthenticationException

from img_proof.ipa_constants import SYNC_POINTS
from img_proof.ipa_exceptions import IpaSSHException, IpaUtilsException
Expand Down Expand Up @@ -81,6 +82,8 @@ def establish_ssh_connection(ip,
key_filename=ssh_private_key_file,
timeout=timeout
)
except (FileNotFoundError, AuthenticationException):
raise
except: # noqa: E722
attempts -= 1
time.sleep(10)
Expand Down Expand Up @@ -281,6 +284,16 @@ def get_ssh_client(ip,
timeout=wait_period
)
execute_ssh_command(client, 'ls')
except FileNotFoundError:
raise IpaSSHException(
'SSH private key file {key_file} not found.'.format(
key_file=ssh_private_key_file
)
)
except AuthenticationException:
raise IpaSSHException(
'Authentication failed while establishing SSH connection.'
)
except: # noqa: E722
if client:
client.close()
Expand Down