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
37 changes: 32 additions & 5 deletions tests/common/dualtor/data_plane_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest
import json
import os.path
import re
import time
import random
import shutil

from tests.common.dualtor.dual_tor_common import active_active_ports # noqa F401
from tests.common.dualtor.dual_tor_common import active_standby_ports # noqa F401
Expand Down Expand Up @@ -209,7 +212,31 @@ def cleanup(ptfadapter, duthosts_list):


@pytest.fixture
def send_t1_to_server_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost): # noqa F811
def save_pcap(request, pytestconfig):
"""Save pcap file to the log directory."""

yield

pcap_file = "/tmp/capture.pcap"
local_pcap_file_template = "%s_dump.pcap"
if os.path.isfile(pcap_file):
test_log_file = pytestconfig.getoption("log_file", None)
if test_log_file:
log_dir = os.path.dirname(os.path.abspath(test_log_file))
# Remove any illegal characters from the test name
local_pcap_filename = local_pcap_file_template % re.sub(r"[^\w\s-]", "_", request.node.name)
local_pcap_filename = re.sub(r'[_\s]+', '_', local_pcap_filename)
pcap_file_dst = os.path.join(log_dir, local_pcap_filename)
logging.debug("Save dualtor-io pcap file to %s", pcap_file_dst)
shutil.copyfile(src=pcap_file, dst=pcap_file_dst)
else:
logging.info("Skip saving pcap file to log directory as log directory not set.")
else:
logging.warn("No pcap file found at {}".format(pcap_file))


@pytest.fixture
def send_t1_to_server_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost, save_pcap): # noqa F811
"""
Starts IO test from T1 router to server.
As part of IO test the background thread sends and sniffs packets.
Expand Down Expand Up @@ -274,7 +301,7 @@ def t1_to_server_io_test(activehost, tor_vlan_port=None,


@pytest.fixture
def send_server_to_t1_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost): # noqa F811
def send_server_to_t1_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost, save_pcap): # noqa F811
"""
Starts IO test from server to T1 router.
As part of IO test the background thread sends and sniffs packets.
Expand Down Expand Up @@ -339,7 +366,7 @@ def server_to_t1_io_test(activehost, tor_vlan_port=None,


@pytest.fixture
def send_soc_to_t1_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost): # noqa F811
def send_soc_to_t1_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost, save_pcap): # noqa F811

arp_setup(ptfhost)

Expand All @@ -363,7 +390,7 @@ def soc_to_t1_io_test(activehost, tor_vlan_port=None,


@pytest.fixture
def send_t1_to_soc_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost): # noqa F811
def send_t1_to_soc_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost, save_pcap): # noqa F811

arp_setup(ptfhost)

Expand Down Expand Up @@ -405,7 +432,7 @@ def _select_test_mux_ports(cable_type, count):


@pytest.fixture
def send_server_to_server_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost): # noqa F811
def send_server_to_server_with_action(duthosts, ptfhost, ptfadapter, tbinfo, cable_type, vmhost, save_pcap): # noqa F811

arp_setup(ptfhost)

Expand Down
5 changes: 5 additions & 0 deletions tests/common/dualtor/dual_tor_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ def start_sniffer(self):
self.capture_pcap = '/tmp/capture.pcap'
self.capture_log = '/tmp/capture.log'

# Do some cleanup first
self.ptfhost.file(path=self.capture_pcap, state="absent")
if os.path.exists(self.capture_pcap):
os.unlink(self.capture_pcap)

self.setup_ptf_sniffer()
self.start_ptf_sniffer()

Expand Down
2 changes: 2 additions & 0 deletions tests/dualtor_io/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from tests.common.dualtor.data_plane_utils import save_pcap # noqa F401


def pytest_configure(config):

Expand Down