diff --git a/ansible/roles/test/files/ptftests/device_connection.py b/ansible/roles/test/files/ptftests/device_connection.py index a29ea493b06..5a475eba671 100644 --- a/ansible/roles/test/files/ptftests/device_connection.py +++ b/ansible/roles/test/files/ptftests/device_connection.py @@ -1,5 +1,6 @@ import paramiko import logging +import socket from paramiko.ssh_exception import BadHostKeyException, AuthenticationException, SSHException logger = logging.getLogger(__name__) @@ -57,6 +58,13 @@ def execCommand(self, cmd, timeout=DEFAULT_CMD_EXECUTION_TIMEOUT_SEC): logger.error('SSH Authentiaction failure with message: %s' % authenticationException) except BadHostKeyException as badHostKeyException: logger.error('SSH Authentiaction 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))) + retValue = 255 + except Exception as e: + logger.error('Exception caught: {}, {}, type: {}'.format(repr(e), str(e), type(e))) + logger.error(sys.exc_info()) finally: client.close() diff --git a/ansible/roles/test/files/ptftests/wr_arp.py b/ansible/roles/test/files/ptftests/wr_arp.py index 39240138985..c05f89715f1 100644 --- a/ansible/roles/test/files/ptftests/wr_arp.py +++ b/ansible/roles/test/files/ptftests/wr_arp.py @@ -12,6 +12,7 @@ import datetime import traceback import sys +import socket import threading from collections import defaultdict from pprint import pprint @@ -22,6 +23,7 @@ from ptf import config import ptf.dataplane as dataplane import ptf.testutils as testutils +from device_connection import DeviceConnection class ArpTest(BaseTest): @@ -60,19 +62,14 @@ def cmd(self, cmds): return stdout, stderr, return_code - def ssh(self, cmds): - ssh_cmds = ["ssh", "-oStrictHostKeyChecking=no", "-oServerAliveInterval=2", "admin@" + self.dut_ssh] - ssh_cmds.extend(cmds) - stdout, stderr, return_code = self.cmd(ssh_cmds) - if stdout != []: - self.log("stdout from dut: '%s'" % str(stdout)) - if stderr != []: - self.log("stderr from dut '%s'" % str(stderr)) - self.log("return code from dut: '%s'" % str(return_code)) + def dut_exec_cmd(self, cmd): + self.log("Executing cmd='{}'".format(cmd)) + stdout, stderr, return_code = self.dut_connection.execCommand(cmd, timeout=30) + self.log("return_code={}, stdout={}, stderr={}".format(return_code, stdout, stderr)) if return_code == 0: return True, str(stdout) - elif return_code == 255 and 'Timeout, server' in stderr and 'not responding' in stderr: + elif return_code == 255: return True, str(stdout) else: return False, "return code: %d. stdout = '%s' stderr = '%s'" % (return_code, str(stdout), str(stderr)) @@ -82,14 +79,14 @@ def dut_thr(self, q_from, q_to): cmd = q_from.get() if cmd == 'WR': self.log("Rebooting remote side") - res, res_text = self.ssh(["sudo", "warm-reboot", "-c", self.ferret_ip]) + res, res_text = self.dut_exec_cmd("sudo warm-reboot -c {}".format(self.ferret_ip)) if res: q_to.put('ok: %s' % res_text) else: q_to.put('error: %s' % res_text) elif cmd == 'uptime': self.log("Check uptime remote side") - res, res_text = self.ssh(["uptime", "-s"]) + res, res_text = self.dut_exec_cmd("uptime -s") if res: q_to.put('ok: %s' % res_text) else: @@ -193,6 +190,9 @@ def setUp(self): config = self.get_param('config_file') self.ferret_ip = self.get_param('ferret_ip') self.dut_ssh = self.get_param('dut_ssh') + self.dut_username = self.get_param('dut_username') + self.dut_password = self.get_param('dut_password') + self.dut_connection = DeviceConnection(self.dut_ssh, username=self.dut_username, password=self.dut_password) self.how_long = int(self.get_param('how_long', required=False, default=300)) if not os.path.isfile(config): diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index 99472847882..6af49d18eb1 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -6,13 +6,13 @@ from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import remove_ip_addresses # lgtm[py/unused-import] -from tests.common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys from tests.ptf_runner import ptf_runner logger = logging.getLogger(__name__) pytestmark = [ - pytest.mark.topology('t0') + pytest.mark.topology('t0'), + pytest.mark.disable_loganalyzer ] # Globals @@ -159,22 +159,7 @@ def setupRouteToPtfhost(self, duthost, ptfhost): assert result["rc"] == 0 or "No such process" in result["stderr"], \ "Failed to delete route with error '{0}'".format(result["stderr"]) - @pytest.fixture(scope='class', autouse=True) - def prepareSshKeys(self, duthost, ptfhost, creds): - ''' - Prepares testbed ssh keys by generating ssh key on ptf host and adding this key to known_hosts on duthost - This class-scope fixture runs once before test start - - Args: - duthost (AnsibleHost): Device Under Test (DUT) - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - None - ''' - prepareTestbedSshKeys(duthost, ptfhost, creds['sonicadmin_user']) - - def testWrArp(self, request, duthost, ptfhost): + def testWrArp(self, request, duthost, ptfhost, creds): ''' Control Plane Assistant test for Warm-Reboot. @@ -206,6 +191,8 @@ def testWrArp(self, request, duthost, ptfhost): params={ 'ferret_ip' : ptfIp, 'dut_ssh' : dutIp, + 'dut_username': creds['sonicadmin_user'], + 'dut_password': creds['sonicadmin_password'], 'config_file' : VXLAN_CONFIG_FILE, 'how_long' : testDuration, },