test: add a test for resolved and wait-online interactions

Specifically, add a test case that ensures systemd-networkd-wait-online --dns
is robust against (a) systemd-resolved absence, and (b) systemd-resolved
restarts.
This commit is contained in:
Nick Rosbrook
2025-04-30 11:12:15 -04:00
parent 5e67cb3bed
commit 3ea04a9432
+60
View File
@@ -1241,6 +1241,66 @@ testcase_14_refuse_record_types() {
(! run varlinkctl call /run/systemd/resolve/io.systemd.Resolve io.systemd.Resolve.ResolveService '{"name":"","type":"_mysvc._tcp","domain":"signed.test"}')
}
# Test systemd-networkd-wait-online interactions with systemd-resolved
testcase_15_wait_online_dns() {
# Cleanup
# shellcheck disable=SC2317
cleanup() {
echo "===== journalctl -u $unit ====="
journalctl -b --no-pager --no-hostname --full -u "$unit"
echo "=========="
rm -f "$override"
restart_resolved
resolvectl revert dns0
}
trap cleanup RETURN ERR
local unit
local override
unit="wait-online-dns-$(systemd-id128 new -u).service"
override="/run/systemd/resolved.conf.d/90-global-dns.conf"
# Clear global and per-interface DNS before monitoring the configuration change.
mkdir -p "$(dirname "$override")"
{
echo "[Resolve]"
echo "DNS="
echo "FallbackDNS="
} > "$override"
systemctl reload systemd-resolved.service
resolvectl dns dns0 ""
resolvectl domain dns0 ""
# Stop systemd-resolved before calling systemd-networkd-wait-online. It should retry connections.
systemctl stop systemd-resolved.service
# Begin systemd-networkd-wait-online --dns
systemd-run -u "$unit" -p "Environment=SYSTEMD_LOG_LEVEL=debug" -p "Environment=SYSTEMD_LOG_TARGET=journal" --service-type=exec \
/usr/lib/systemd/systemd-networkd-wait-online --timeout=20 --dns --interface=dns0
# Wait until it blocks waiting for updated DNS config
timeout 10 bash -c "journalctl -b -u $unit -f | grep -q -m1 'dns0: No.*DNS server is accessible'"
# Update the global configuration. Restart rather than reload systemd-resolved so that
# systemd-networkd-wait-online has to re-connect to the varlink service.
{
echo "[Resolve]"
echo "DNS=10.0.0.1"
} > "$override"
systemctl restart systemd-resolved.service
# Wait for the monitor to exit gracefully.
timeout 10 bash -c "while systemctl --quiet is-active $unit; do sleep 0.5; done"
# Check that a disconnect happened, and was handled.
journalctl -b -u "$unit" --grep="DNS configuration monitor disconnected, reconnecting..." > /dev/null
# Check that dns0 was found to be online.
journalctl -b -u "$unit" --grep="dns0: link is configured by networkd and online." > /dev/null
}
# PRE-SETUP
systemctl unmask systemd-resolved.service
systemctl enable --now systemd-resolved.service