Skip to content
Merged
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
31 changes: 24 additions & 7 deletions tests/dns/static_dns/test_static_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import random
import re
import os

from tests.common.reboot import reboot
from tests.common.config_reload import config_reload
Expand Down Expand Up @@ -40,6 +41,22 @@
EXCEED_MAX_ERR = r"Error: The maximum number \(3\) of nameservers exceeded"
DUPLICATED_IP_ERR = r"Error: .* nameserver is already configured"

MGMT_PORT = "eth0"
DHCLIENT_PID_FILE = "/tmp/dhclient-dns-test.pid"


def start_dhclient(duthost):
duthost.shell(f"sudo dhclient -pf {DHCLIENT_PID_FILE} {MGMT_PORT}")


@pytest.fixture()
def stop_dhclient(duthost):
yield

if os.path.exists(DHCLIENT_PID_FILE):
Copy link
Contributor

@byu343 byu343 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yxieca It is found by @Staphylo that this check runs on the test server, but should be on the DUT, which will make the cleanup of dhclient still not happen. This PR lets dhclient only started for MGMT_PORT which was also including many front panel ports before this PR; it can fix the original issue. @nhe-NV Still, can you please further fix the cleanup of the dhclient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed it in #11765

duthost.shell(f"sudo kill $(cat {DHCLIENT_PID_FILE})")
duthost.shell(f"rm -rf {DHCLIENT_PID_FILE}")


@pytest.mark.disable_loganalyzer
def test_static_dns_basic(request, duthost, localhost, mgmt_interfaces):
Expand Down Expand Up @@ -97,13 +114,13 @@ def test_static_dns_basic(request, duthost, localhost, mgmt_interfaces):
if mgmt_interfaces:
verify_nameserver_in_conf_file(duthost, [])
else:
origin_dynamic_nameservers = get_nameserver_from_resolvconf(duthost, file_name=RESOLV_CONF_FILE+".bk")
origin_dynamic_nameservers = get_nameserver_from_resolvconf(duthost, file_name=RESOLV_CONF_FILE + ".bk")
verify_nameserver_in_conf_file(duthost, origin_dynamic_nameservers)


@pytest.mark.usefixtures('static_mgmt_ip_configured')
class TestStaticMgmtPortIP():
def test_dynamic_dns_not_working_when_static_ip_configured(self, duthost):
def test_dynamic_dns_not_working_when_static_ip_configured(self, duthost, stop_dhclient):
"""
Test to verify Dynamic DNS not work when static ip address is configured on the mgmt port
:param duthost: DUT host object
Expand All @@ -120,13 +137,13 @@ def test_dynamic_dns_not_working_when_static_ip_configured(self, duthost):
verify_nameserver_in_conf_file(duthost, [])

with allure.step("Renew dhcp to restore the dns configuration."):
duthost.shell("sudo dhclient")
start_dhclient(duthost)
verify_nameserver_in_conf_file(duthost, [])


@pytest.mark.usefixtures('static_mgmt_ip_not_configured')
class TestDynamicMgmtPortIP():
def test_static_dns_is_not_changing_when_do_dhcp_renew(self, duthost):
def test_static_dns_is_not_changing_when_do_dhcp_renew(self, duthost, stop_dhclient):
"""
Test case to verify Static DNS will not change when do dhcp renew for the mgmt port
:param duthost: DUT host object
Expand All @@ -143,7 +160,7 @@ def test_static_dns_is_not_changing_when_do_dhcp_renew(self, duthost):
verify_nameserver_in_conf_file(duthost, expected_nameservers)

with allure.step("Renew dhcp to restore the dns configuration."):
duthost.shell("sudo dhclient")
start_dhclient(duthost)

with allure.step(f"Verify that {RESOLV_CONF_FILE} is not modified"):
verify_nameserver_in_conf_file(duthost, expected_nameservers)
Expand All @@ -153,7 +170,7 @@ def test_static_dns_is_not_changing_when_do_dhcp_renew(self, duthost):
del_dns_nameserver(duthost, nameserver)

@pytest.mark.usefixtures('static_mgmt_ip_not_configured')
def test_dynamic_dns_working_when_no_static_ip_and_static_dns(self, duthost):
def test_dynamic_dns_working_when_no_static_ip_and_static_dns(self, duthost, stop_dhclient):
"""
The test is to verify Dynamic DNS work as expected when no static ip configured on mgmt port and
static DNS is configured.
Expand Down Expand Up @@ -182,7 +199,7 @@ def test_dynamic_dns_working_when_no_static_ip_and_static_dns(self, duthost):
config_mgmt_ip(duthost, mgmt_interfaces, "remove")

with allure.step("Renew dhcp to restore the dns configuration."):
duthost.shell("sudo dhclient")
start_dhclient(duthost)
verify_nameserver_in_conf_file(duthost, origin_dynamic_nameservers)


Expand Down