Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 6 additions & 1 deletion tests/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,8 @@ def capture_and_check_packet_on_dut(
interface='any',
pkts_filter='',
pkts_validator=lambda pkts: pytest_assert(len(pkts) > 0, "No packets captured"),
pkts_validator_args=[],
pkts_validator_kwargs={},
wait_time=1
):
"""
Expand All @@ -1090,6 +1092,9 @@ def capture_and_check_packet_on_dut(
interface: the interface to capture packets on, default is 'any'
pkts_filter: the PCAP-FILTER to apply to the captured packets, default is '' means no filter
pkts_validator: the function to validate the captured packets, default is to check if any packet is captured
pkts_validator_args: ther args to pass to the pkts_validator function
pkts_validator_kwargs: the kwargs to pass to the pkts_validator function
wait_time: the time to wait before stopping the packet capture, default is 1 second
"""
pcap_save_path = "/tmp/func_capture_and_check_packet_on_dut_%s.pcap" % (str(uuid.uuid4()))
cmd_capture_pkts = "sudo nohup tcpdump --immediate-mode -U -i %s -w %s >/dev/null 2>&1 %s & echo $!" \
Expand All @@ -1106,6 +1111,6 @@ def capture_and_check_packet_on_dut(
duthost.shell("kill -s 2 %s" % tcpdump_pid)
with tempfile.NamedTemporaryFile() as temp_pcap:
duthost.fetch(src=pcap_save_path, dest=temp_pcap.name, flat=True)
pkts_validator(scapy_sniff(offline=temp_pcap.name))
pkts_validator(scapy_sniff(offline=temp_pcap.name), *pkts_validator_args, **pkts_validator_kwargs)
finally:
duthost.file(path=pcap_save_path, state="absent")
45 changes: 45 additions & 0 deletions tests/dhcp_server/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from tests.common.utilities import wait_until
from tests.common.helpers.assertions import pytest_assert as py_assert
from tests.common.helpers.assertions import pytest_require as py_require

DHCP_RELAY_CONTAINER_NAME = "dhcp_relay"
DHCP_SERVER_CONTAINER_NAME = "dhcp_server"
DHCP_SERVER_FEATRUE_NAME = "dhcp_server"


@pytest.fixture(scope="module", autouse=True)
def dhcp_server_setup_teardown(duthost):
features_state, _ = duthost.get_feature_status()
py_require(DHCP_SERVER_FEATRUE_NAME in features_state, "Skip on vs testbed without dhcp server feature")
restore_state_flag = False
if "enabled" not in features_state.get(DHCP_SERVER_FEATRUE_NAME, ""):
Comment thread
w1nda marked this conversation as resolved.
restore_state_flag = True
duthost.shell("config feature state dhcp_server enabled")
duthost.shell("sudo systemctl restart dhcp_relay.service")

def is_supervisor_subprocess_running(duthost, container_name, app_name):
return "RUNNING" in duthost.shell(f"docker exec {container_name} supervisorctl status {app_name}")["stdout"]
py_assert(
wait_until(20, 1, 1,
is_supervisor_subprocess_running,
duthost,
DHCP_SERVER_CONTAINER_NAME,
"dhcp-server-ipv4:kea-dhcp4"),
'feature dhcp_server is enabled but container is not running'
)
py_assert(
wait_until(30, 1, 1,
is_supervisor_subprocess_running,
duthost,
DHCP_RELAY_CONTAINER_NAME,
"dhcp-relay:dhcprelayd"),
'dhcprelayd in container dhcp_relay is not running'
)

yield

if restore_state_flag:
duthost.shell("config feature state dhcp_server disabled", module_ignore_errors=True)
Comment thread
w1nda marked this conversation as resolved.
Outdated
duthost.shell("sudo systemctl restart dhcp_relay.service")
duthost.shell("docker rm dhcp_server", module_ignore_errors=True)
Loading