diff --git a/ansible/roles/test/files/ptftests/advanced-reboot.py b/ansible/roles/test/files/ptftests/advanced-reboot.py index ed09edb6175..75aa5fe2bb3 100644 --- a/ansible/roles/test/files/ptftests/advanced-reboot.py +++ b/ansible/roles/test/files/ptftests/advanced-reboot.py @@ -225,7 +225,8 @@ def __init__(self): self.dut_connection = DeviceConnection( self.test_params['dut_hostname'], self.test_params['dut_username'], - password=self.test_params['dut_password'] + password=self.test_params['dut_password'], + alt_password=self.test_params.get('alt_password') ) # Check if platform type is kvm diff --git a/ansible/roles/test/files/ptftests/device_connection.py b/ansible/roles/test/files/ptftests/device_connection.py index 5a475eba671..0539941e886 100644 --- a/ansible/roles/test/files/ptftests/device_connection.py +++ b/ansible/roles/test/files/ptftests/device_connection.py @@ -1,8 +1,9 @@ import paramiko import logging import socket +import sys from paramiko.ssh_exception import BadHostKeyException, AuthenticationException, SSHException - +from pip._vendor.retrying import retry logger = logging.getLogger(__name__) DEFAULT_CMD_EXECUTION_TIMEOUT_SEC = 10 @@ -14,7 +15,7 @@ class DeviceConnection: Paramiko module uses fallback mechanism where it would first try to use ssh key and that fails, it will attempt username/password combination ''' - def __init__(self, hostname, username, password=None): + def __init__(self, hostname, username, password=None, alt_password=None): ''' Class constructor @@ -25,7 +26,13 @@ def __init__(self, hostname, username, password=None): self.hostname = hostname self.username = username self.password = password + self.alt_password = alt_password + + @retry( + stop_max_attempt_number=2, + retry_on_exception=lambda e: isinstance(e, AuthenticationException) + ) def execCommand(self, cmd, timeout=DEFAULT_CMD_EXECUTION_TIMEOUT_SEC): ''' Executes command on remote device @@ -52,12 +59,16 @@ def execCommand(self, cmd, timeout=DEFAULT_CMD_EXECUTION_TIMEOUT_SEC): stdOut = so.readlines() stdErr = se.readlines() retValue = 0 + except AuthenticationException as authenticationException: + logger.error('SSH Authentication failure with message: %s' % authenticationException) + if self.alt_password is not None: + # attempt retry with alt_password + self.password = self.alt_password + raise AuthenticationException except SSHException as sshException: logger.error('SSH Command failed with message: %s' % sshException) - except AuthenticationException as authenticationException: - logger.error('SSH Authentiaction failure with message: %s' % authenticationException) except BadHostKeyException as badHostKeyException: - logger.error('SSH Authentiaction failure with message: %s' % badHostKeyException) + logger.error('SSH Authentication failure with message: %s' % badHostKeyException) except socket.timeout as e: # The ssh session will timeout in case of a successful reboot logger.error('Caught exception socket.timeout: {}, {}, {}'.format(repr(e), str(e), type(e))) diff --git a/tests/upgrade_path/test_upgrade_path.py b/tests/upgrade_path/test_upgrade_path.py index fbed0a3f912..c8f1a60c075 100644 --- a/tests/upgrade_path/test_upgrade_path.py +++ b/tests/upgrade_path/test_upgrade_path.py @@ -99,10 +99,12 @@ def ptf_params(duthosts, rand_one_dut_hostname, nbrhosts, creds, tbinfo): #TODO:Update to vm_hosts.append(value['host'].host.mgmt_ip) vm_hosts.append(value['host'].host.options['inventory_manager'].get_host(value['host'].hostname).vars['ansible_host']) + sonicadmin_alt_password = duthost.host.options['variable_manager']._hostvars[duthost.hostname].get("ansible_altpassword") ptf_params = { "verbose": False, "dut_username": creds.get('sonicadmin_user'), "dut_password": creds.get('sonicadmin_password'), + "alt_password": sonicadmin_alt_password, "dut_hostname": duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'], "reboot_limit_in_seconds": 30, "reboot_type": "warm-reboot",