Skip to content

Commit 68b4180

Browse files
saiarcot895wangxin
authored andcommitted
Add a test case to check /etc/resolv.conf (#7828)
* Add a test case to check /etc/resolv.conf Add a test case to verify that the expected nameservers are present (or not present) in /etc/resolv.conf. Signed-off-by: Saikrishna Arcot <[email protected]> * Fix pre-commit check Signed-off-by: Saikrishna Arcot <[email protected]> * Add dns test to t0 kvmtest and PR test pipeline Signed-off-by: Saikrishna Arcot <[email protected]> --------- Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent 2c4abd7 commit 68b4180

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

.azure-pipelines/pr_test_scripts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ t0:
1212
- container_checker/test_container_checker.py
1313
- dhcp_relay/test_dhcp_relay.py
1414
- dhcp_relay/test_dhcpv6_relay.py
15+
- dns/test_dns_resolv_conf.py
1516
- generic_config_updater/test_aaa.py
1617
- generic_config_updater/test_bgp_prefix.py
1718
- generic_config_updater/test_bgp_speaker.py

tests/common/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@
77
IS_BACKEND_TOPOLOGY_KEY = "is_backend_topology"
88
# a topology whos name contains the indicator 'backend' will be considered as a backend topology
99
BACKEND_TOPOLOGY_IND = "backend"
10+
# ssh connect default username and password
11+
DEFAULT_SSH_CONNECT_PARAMS = {
12+
"public": {"username": "admin",
13+
"password": "YourPaSsWoRd"}
14+
}
15+
# resolv.conf expected nameservers
16+
RESOLV_CONF_NAMESERVERS = {
17+
"public": []
18+
}

tests/dns/test_dns_resolv_conf.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
import logging
3+
from tests.common.constants import RESOLV_CONF_NAMESERVERS
4+
from tests.common.helpers.assertions import pytest_assert
5+
from tests.common.utilities import get_image_type
6+
7+
pytestmark = [
8+
pytest.mark.topology("any")
9+
]
10+
11+
logger = logging.getLogger(__name__)
12+
13+
14+
def test_dns_resolv_conf(duthost):
15+
"""verify that /etc/resolv.conf contains the expected nameservers
16+
17+
Args:
18+
duthost: AnsibleHost instance for DUT
19+
"""
20+
# Check SONiC image type and get expected nameservers in /etc/resolv.conf
21+
expected_nameservers = set(RESOLV_CONF_NAMESERVERS[get_image_type(duthost=duthost)])
22+
23+
logger.info("expected nameservers: [{}]".format(" ".join(expected_nameservers)))
24+
25+
resolv_conf = duthost.shell("cat /etc/resolv.conf", module_ignore_errors=True)
26+
pytest_assert(resolv_conf["rc"] == 0, "Failed to read /etc/resolf.conf!")
27+
current_nameservers = []
28+
for resolver_line in resolv_conf["stdout_lines"]:
29+
if not resolver_line.startswith("nameserver"):
30+
continue
31+
current_nameservers.append(resolver_line.split()[1])
32+
33+
current_nameservers = set(current_nameservers)
34+
35+
logger.info("current nameservers: [{}]".format(" ".join(current_nameservers)))
36+
37+
pytest_assert(not(current_nameservers ^ expected_nameservers),
38+
"Mismatch between expected and current nameservers! Expected: [{}]. Current: [{}].".format(
39+
" ".join(expected_nameservers), " ".join(current_nameservers)))

tests/kvmtest.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ test_t0() {
154154
popd
155155
else
156156
tests="\
157+
dns/test_dns_resolv_conf.py \
157158
generic_config_updater/test_aaa.py \
158159
generic_config_updater/test_bgpl.py \
159160
generic_config_updater/test_bgp_prefix.py \

0 commit comments

Comments
 (0)