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
8 changes: 8 additions & 0 deletions ansible/roles/test/files/ptftests/device_connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import paramiko
import logging
import socket
from paramiko.ssh_exception import BadHostKeyException, AuthenticationException, SSHException

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -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()

Expand Down
24 changes: 12 additions & 12 deletions ansible/roles/test/files/ptftests/wr_arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime
import traceback
import sys
import socket
import threading
from collections import defaultdict
from pprint import pprint
Expand All @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
23 changes: 5 additions & 18 deletions tests/arp/test_wr_arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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,
},
Expand Down