Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion ansible/roles/test/files/ptftests/advanced-reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions ansible/roles/test/files/ptftests/device_connection.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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)))
Expand Down
2 changes: 2 additions & 0 deletions tests/upgrade_path/test_upgrade_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down