From abbf97bd42811b9156a6a37ee2235e81e90ec678 Mon Sep 17 00:00:00 2001 From: Nana He Date: Fri, 23 Feb 2024 16:40:09 +0800 Subject: [PATCH] fix static dns issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Need to check if the dhclient pid exist or not or the dut host. 2. Save the dhclient pid under the /run folder instead of the /tmp folder, When dhclient runs it drops the permissions to meet the required security level. With the dropped per in the Debian 12, it can’t create a PID file in a /tmp/ directory. Instead /run/ directory should be used. --- tests/dns/static_dns/test_static_dns.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/dns/static_dns/test_static_dns.py b/tests/dns/static_dns/test_static_dns.py index cd83fdad99b..c7ba00eb16b 100644 --- a/tests/dns/static_dns/test_static_dns.py +++ b/tests/dns/static_dns/test_static_dns.py @@ -2,7 +2,6 @@ import logging import random import re -import os from tests.common.reboot import reboot from tests.common.config_reload import config_reload @@ -42,7 +41,7 @@ DUPLICATED_IP_ERR = r"Error: .* nameserver is already configured" MGMT_PORT = "eth0" -DHCLIENT_PID_FILE = "/tmp/dhclient-dns-test.pid" +DHCLIENT_PID_FILE = "/run/dhclient-dns-test.pid" def start_dhclient(duthost): @@ -53,7 +52,7 @@ def start_dhclient(duthost): def stop_dhclient(duthost): yield - if os.path.exists(DHCLIENT_PID_FILE): + if duthost.shell(f'ls {DHCLIENT_PID_FILE}', module_ignore_errors=True)['rc'] == 0: duthost.shell(f"sudo kill $(cat {DHCLIENT_PID_FILE})") duthost.shell(f"rm -rf {DHCLIENT_PID_FILE}")