Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions parts/linux/cloud-init/artifacts/localdns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ wait_for_localdns_removed_from_resolv_conf() {
current_dns=$(awk '/^nameserver/ {print $2}' "$RESOLV_CONF" 2>/dev/null | paste -sd' ')

# Use word boundary matching (-w) with fixed string (-F) to avoid partial IP matches.
if ! grep -qwF "$LOCALDNS_NODE_LISTENER_IP" <<< "$current_dns"; then
if [ -n "$current_dns" ] && ! grep -qwF "$LOCALDNS_NODE_LISTENER_IP" <<< "$current_dns"; then
Comment thread
saewoni marked this conversation as resolved.
echo "DNS configuration refreshed successfully. Current DNS: ${current_dns}"
return 0
fi
Expand Down Expand Up @@ -658,7 +658,7 @@ EOF
cleanup_iptables_and_dns() {
# Ensure network variables are initialized if not already set.
# This is needed here because this function can be called from cleanup traps or systemd restarts initiated by watchdog.
if [ -z "${NETWORK_DROPIN_FILE:-}" ] || [ -z "${NETWORK_DROPIN_DIR:-}" ]; then
if [ -z "${DEFAULT_ROUTE_INTERFACE:-}" ] || [ -z "${NETWORK_DROPIN_FILE:-}" ] || [ -z "${NETWORK_DROPIN_DIR:-}" ]; then
Comment thread
saewoni marked this conversation as resolved.
echo "Network variables not initialized, attempting to determine them..."
if ! initialize_network_variables; then
echo "Failed to initialize network variables during cleanup."
Expand Down
23 changes: 15 additions & 8 deletions spec/parts/linux/cloud-init/artifacts/localdns_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1338,11 +1338,18 @@ EOF
The stdout should include "Current DNS:"
End

It 'should return success if resolv.conf is empty'
It 'should keep waiting if resolv.conf has no nameservers'
Comment thread
saewoni marked this conversation as resolved.
> "$RESOLV_CONF"
When run wait_for_localdns_removed_from_resolv_conf 5
The status should be success
The stdout should include "DNS configuration refreshed successfully"
When run wait_for_localdns_removed_from_resolv_conf 1
The status should be failure
The stdout should include "Timed out waiting for localdns to be removed"
End

It 'should keep waiting if resolv.conf contains only comments'
printf '# nameserver 10.0.0.1\n' > "$RESOLV_CONF"
When run wait_for_localdns_removed_from_resolv_conf 1
The status should be failure
The stdout should include "Timed out waiting for localdns to be removed"
End

It 'should use default timeout of 5 seconds when not specified'
Expand All @@ -1354,11 +1361,11 @@ EOF
The stdout should include "DNS configuration refreshed successfully"
End

It 'should handle resolv.conf not existing gracefully'
It 'should fail when resolv.conf does not exist'
rm -f "$RESOLV_CONF"
When run wait_for_localdns_removed_from_resolv_conf 2
The status should be success
The stdout should include "DNS configuration refreshed successfully"
When run wait_for_localdns_removed_from_resolv_conf 1
The status should be failure
The stdout should include "Timed out waiting for localdns to be removed"
End

It 'should not match partial IP addresses'
Expand Down
Loading