Skip to content

Commit 3625139

Browse files
committed
qemu_guest_test: add test for sudo fqdn issue
If DNS is misconfigured in the deployment environment, sudo may hang while it times out on DNS requests, which is not desirable for the majority of our users. Add a test that identifies if sudo is using DNS. See: #193 There isn't an easy and obvious method of testing "did sudo use DNS" that (ideally) is independent of the DNS configuration in the test environment. This is hopefully unintrusive and reasonably flexible. The catch is that if we use sudo-rs in the future then it might stop working if Rust doesn't use libc. But this seems better than nothing. To make it easier to ensure that this test is correctly testing what we need, I've separated the test from the fix using xfail. This way, before the issue is fixed, the test suite passing means that the test is correctly detecting the issue. I'll then introduce the fix in the next change. Signed-off-by: Robie Basak <robie.basak@oss.qualcomm.com>
1 parent e3f7a3b commit 3625139

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

ci/qemu_guest_test.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# These tests are run inside the qemu guest as root using its own pytest runner
77
# invocation.
88

9+
import subprocess
10+
import tempfile
11+
912
import pytest
1013

1114
# Mark this module so that the main test runner can skip it when running from
@@ -20,3 +23,69 @@ def test_empty():
2023
# The empty test. This is nevertheless useful as its presence ensures that
2124
# the host is calling the guest test suite in this module correctly.
2225
pass
26+
27+
28+
# To keep tests fast for developer iteration, just install all the test
29+
# dependencies together once for all tests defined here. It is likely that our
30+
# tests here are not going to interact. If they do, then we can decide whether
31+
# to compromise on this at that time.
32+
@pytest.fixture(scope="module")
33+
def apt_dependencies():
34+
# To speed things up, we deliberately skip the apt-get update here on the
35+
# assumption that it was arranged by whatever is running the test. This is
36+
# arranged from qemu_test.py::test_using_guest_tests() instead.
37+
subprocess.run(
38+
["apt-get", "install", "-y", "--no-install-recommends", "sudo", "gdb"],
39+
check=True,
40+
)
41+
42+
43+
@pytest.mark.xfail(
44+
reason="https://github.com/qualcomm-linux/qcom-deb-images/issues/193",
45+
strict=True,
46+
)
47+
def test_sudo_no_fqdn(apt_dependencies):
48+
"""sudo should not call FQDN lookup functions
49+
50+
See: https://github.com/qualcomm-linux/qcom-deb-images/issues/193
51+
"""
52+
with tempfile.NamedTemporaryFile(
53+
mode="w", delete_on_close=False
54+
) as gdb_commands_file:
55+
print(
56+
"catch load",
57+
"run",
58+
"del 1",
59+
sep="\n",
60+
file=gdb_commands_file,
61+
)
62+
for fn_name in [
63+
"gethostbyaddr",
64+
"getnameinfo",
65+
"getaddrinfo",
66+
"gethostbyname",
67+
]:
68+
print(
69+
f"break {fn_name}",
70+
f"commands",
71+
f' print "{fn_name} called\\n"',
72+
f" quit 1",
73+
f"end",
74+
sep="\n",
75+
file=gdb_commands_file,
76+
)
77+
print("continue", file=gdb_commands_file)
78+
gdb_commands_file.close()
79+
80+
subprocess.run(
81+
[
82+
"gdb",
83+
"--batch",
84+
"-x",
85+
gdb_commands_file.name,
86+
"--args",
87+
"sudo",
88+
"true",
89+
],
90+
check=True,
91+
)

0 commit comments

Comments
 (0)