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
29 changes: 11 additions & 18 deletions tests/fdb/test_fdb_mac_expire.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import time

from tests.common.helpers.assertions import pytest_assert
from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm [py/unused-import]
from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # noqa F401 # lgtm [py/unused-import]
from tests.ptf_runner import ptf_runner

pytestmark = [
pytest.mark.topology('t0', 'm0', 'mx')
Expand All @@ -13,6 +14,8 @@

DISABLE_REFRESH = "disable_refresh"
REFRESH_DEST_MAC = "refresh_with_dest_mac"


class TestFdbMacExpire:
"""
TestFdbMacExpire Verifies FDb aging timer is respected
Expand Down Expand Up @@ -90,24 +93,14 @@ def __runPtfTest(self, ptfhost, testCase='', testParams={}):
RunAnsibleModuleFail if ptf test fails
"""
logger.info("Running PTF test case '{0}' on '{1}'".format(testCase, ptfhost.hostname))
ptfhost.shell(argv=[
"/root/env-python3/bin/ptf",
"--test-dir",
"ptftests/py3",
testCase,
"--platform-dir",
ptf_runner(
ptfhost,
"ptftests",
"--platform",
"remote",
"-t",
";".join(["{0}={1}".format(k, repr(v)) for k, v in testParams.items()]),
"--relax",
"--debug",
"info",
"--log-file",
"/tmp/{0}".format(testCase)
],
chdir = "/root",
testCase,
platform_dir="ptftests",
params=testParams,
log_file="/tmp/{0}".format(testCase),
is_python3=True
)

@pytest.fixture(scope="class", autouse=True)
Expand Down
15 changes: 9 additions & 6 deletions tests/ptf_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def ptf_collect(host, log_file):
host.fetch(src=pcap_file, dest=filename_pcap, flat=True, fail_on_missing=False)
allure.attach.file(filename_pcap, 'ptf_pcap: ' + filename_pcap, allure.attachment_type.PCAP)


def ptf_runner(host, testdir, testname, platform_dir=None, params={},
platform="remote", qlen=0, relax=True, debug_level="info",
socket_recv_size=None, log_file=None, device_sockets=[], timeout=0,
socket_recv_size=None, log_file=None, device_sockets=[], timeout=0, custom_options="",
module_ignore_errors=False, is_python3=False):
# Call virtual env ptf for migrated py3 scripts.
# ptf will load all scripts under ptftests, it will throw error for py2 scripts.
Expand All @@ -37,9 +38,9 @@ def ptf_runner(host, testdir, testname, platform_dir=None, params={},
if path_exists["stat"]["exists"]:
cmd = "/root/env-python3/bin/ptf --test-dir {} {}".format(testdir+'/py3', testname)
else:
error_msg = "Virtual environment for Python3 /root/env-python3/bin/ptf doesn't exist.\nPlease check and update docker-ptf image, make sure to use the correct one."
logger.error("Exception caught while executing case: {}. Error message: {}"\
.format(testname, error_msg))
error_msg = "Virtual environment for Python3 /root/env-python3/bin/ptf doesn't exist.\n" \
"Please check and update docker-ptf image, make sure to use the correct one."
logger.error("Exception caught while executing case: {}. Error message: {}".format(testname, error_msg))
raise Exception(error_msg)
else:
cmd = "ptf --test-dir {} {}".format(testdir, testname)
Expand Down Expand Up @@ -75,6 +76,9 @@ def ptf_runner(host, testdir, testname, platform_dir=None, params={},
if timeout:
cmd += " --test-case-timeout {}".format(int(timeout))

if custom_options:
cmd += " " + custom_options

if hasattr(host, "macsec_enabled") and host.macsec_enabled:
if not is_python3:
logger.error("MACsec is only available in Python3")
Expand All @@ -95,7 +99,6 @@ def ptf_runner(host, testdir, testname, platform_dir=None, params={},
ptf_collect(host, log_file)
traceback_msg = traceback.format_exc()
allure.attach(traceback_msg, 'ptf_runner_exception_traceback', allure.attachment_type.TEXT)
logger.error("Exception caught while executing case: {}. Error message: {}"\
.format(testname, traceback_msg))
logger.error("Exception caught while executing case: {}. Error message: {}".format(testname, traceback_msg))
raise Exception
return True
Loading