dev_1.0.0_yuyr 完成 log和bind模块开发部署测试 (#8)
- [x] 完成log模块镜像构建、本地端到端写日志——收集——查询流程; - [x] 完成bind模块构建; - [x] 内置域名IP自动更新脚本,使用 /private/argus/etc目录下文件进行同步,容器启动时自动写IP,定时任务刷新更新DNS服务器IP和DNS规则; Co-authored-by: root <root@curious.host.com> Reviewed-on: #8 Reviewed-by: sundapeng <sundp@mail.zgclab.edu.cn>
This commit was merged in pull request #8.
This commit is contained in:
2
src/bind/.gitignore
vendored
Normal file
2
src/bind/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
images/
|
||||
66
src/bind/build/Dockerfile
Normal file
66
src/bind/build/Dockerfile
Normal file
@@ -0,0 +1,66 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
# Set timezone and avoid interactive prompts
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# 设置构建参数
|
||||
ARG USE_INTRANET=false
|
||||
|
||||
# 配置内网 apt 源 (如果指定了内网选项)
|
||||
RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||
echo "Configuring intranet apt sources..." && \
|
||||
cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
|
||||
echo "deb [trusted=yes] http://10.68.64.1/ubuntu2204/ jammy main" > /etc/apt/sources.list && \
|
||||
echo 'Acquire::https::Verify-Peer "false";' > /etc/apt/apt.conf.d/99disable-ssl-check && \
|
||||
echo 'Acquire::https::Verify-Host "false";' >> /etc/apt/apt.conf.d/99disable-ssl-check; \
|
||||
fi
|
||||
|
||||
# Update package list and install required packages
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
bind9 \
|
||||
bind9utils \
|
||||
bind9-doc \
|
||||
supervisor \
|
||||
net-tools \
|
||||
inetutils-ping \
|
||||
vim \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 配置部署时使用的apt源
|
||||
RUN if [ "$USE_INTRANET" = "true" ]; then \
|
||||
echo "deb [trusted=yes] https://10.92.132.52/mirrors/ubuntu2204/ jammy main" > /etc/apt/sources.list; \
|
||||
fi
|
||||
|
||||
# Create supervisor configuration directory
|
||||
RUN mkdir -p /etc/supervisor/conf.d
|
||||
|
||||
# Copy supervisor configuration
|
||||
COPY src/bind/build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Copy BIND9 configuration files
|
||||
COPY src/bind/build/named.conf.local /etc/bind/named.conf.local
|
||||
COPY src/bind/build/db.argus.com /etc/bind/db.argus.com
|
||||
|
||||
# Copy startup and reload scripts
|
||||
COPY src/bind/build/startup.sh /usr/local/bin/startup.sh
|
||||
COPY src/bind/build/reload-bind9.sh /usr/local/bin/reload-bind9.sh
|
||||
COPY src/bind/build/argus_dns_sync.sh /usr/local/bin/argus_dns_sync.sh
|
||||
COPY src/bind/build/update-dns.sh /usr/local/bin/update-dns.sh
|
||||
|
||||
# Make scripts executable
|
||||
RUN chmod +x /usr/local/bin/startup.sh /usr/local/bin/reload-bind9.sh /usr/local/bin/argus_dns_sync.sh /usr/local/bin/update-dns.sh
|
||||
|
||||
# Set proper ownership for BIND9 files
|
||||
RUN chown bind:bind /etc/bind/named.conf.local /etc/bind/db.argus.com
|
||||
|
||||
# Expose DNS port
|
||||
EXPOSE 53/tcp 53/udp
|
||||
|
||||
# Use root user as requested
|
||||
USER root
|
||||
|
||||
# Start with startup script
|
||||
CMD ["/usr/local/bin/startup.sh"]
|
||||
100
src/bind/build/argus_dns_sync.sh
Normal file
100
src/bind/build/argus_dns_sync.sh
Normal file
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
WATCH_DIR="/private/argus/etc"
|
||||
ZONE_DB="/private/argus/bind/db.argus.com"
|
||||
LOCKFILE="/var/lock/argus_dns_sync.lock"
|
||||
BACKUP_DIR="/private/argus/bind/.backup"
|
||||
SLEEP_SECONDS=10
|
||||
RELOAD_SCRIPT="/usr/local/bin/reload-bind9.sh" # 这里放你已有脚本的路径
|
||||
|
||||
mkdir -p "$(dirname "$LOCKFILE")" "$BACKUP_DIR"
|
||||
|
||||
is_ipv4() {
|
||||
local ip="$1"
|
||||
[[ "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] || return 1
|
||||
IFS='.' read -r a b c d <<<"$ip"
|
||||
for n in "$a" "$b" "$c" "$d"; do
|
||||
(( n >= 0 && n <= 255 )) || return 1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
get_current_ip() {
|
||||
local name="$1"
|
||||
sed -n -E "s/^${name}[[:space:]]+IN[[:space:]]+A[[:space:]]+([0-9.]+)[[:space:]]*$/\1/p" "$ZONE_DB" | head -n1
|
||||
}
|
||||
|
||||
upsert_record() {
|
||||
local name="$1"
|
||||
local new_ip="$2"
|
||||
local ts
|
||||
ts="$(date +%Y%m%d-%H%M%S)"
|
||||
local changed=0
|
||||
|
||||
cp -a "$ZONE_DB" "$BACKUP_DIR/db.argus.com.$ts.bak"
|
||||
|
||||
local cur_ip
|
||||
cur_ip="$(get_current_ip "$name" || true)"
|
||||
|
||||
if [[ -z "$cur_ip" ]]; then
|
||||
# Ensure the file ends with a newline before adding new record
|
||||
if [[ -s "$ZONE_DB" ]] && [[ $(tail -c1 "$ZONE_DB" | wc -l) -eq 0 ]]; then
|
||||
echo "" >> "$ZONE_DB"
|
||||
fi
|
||||
printf "%-20s IN A %s\n" "$name" "$new_ip" >> "$ZONE_DB"
|
||||
echo "[ADD] ${name} -> ${new_ip}"
|
||||
changed=1
|
||||
elif [[ "$cur_ip" != "$new_ip" ]]; then
|
||||
awk -v n="$name" -v ip="$new_ip" '
|
||||
{
|
||||
if ($1==n && $2=="IN" && $3=="A") {
|
||||
printf "%-20s IN A %s\n", n, ip
|
||||
} else {
|
||||
print
|
||||
}
|
||||
}
|
||||
' "$ZONE_DB" > "${ZONE_DB}.tmp" && mv "${ZONE_DB}.tmp" "$ZONE_DB"
|
||||
echo "[UPDATE] ${name}: ${cur_ip} -> ${new_ip}"
|
||||
changed=1
|
||||
else
|
||||
echo "[SKIP] ${name} unchanged (${new_ip})"
|
||||
fi
|
||||
|
||||
return $changed
|
||||
}
|
||||
|
||||
while true; do
|
||||
exec 9>"$LOCKFILE"
|
||||
if flock -n 9; then
|
||||
shopt -s nullglob
|
||||
NEED_RELOAD=0
|
||||
|
||||
for f in "$WATCH_DIR"/*.argus.com; do
|
||||
base="$(basename "$f")"
|
||||
name="${base%.argus.com}"
|
||||
ip="$(grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' "$f" | tail -n1 || true)"
|
||||
|
||||
if [[ -z "$ip" ]] || ! is_ipv4 "$ip"; then
|
||||
echo "[WARN] $f 未找到有效 IPv4,跳过"
|
||||
continue
|
||||
fi
|
||||
|
||||
if upsert_record "$name" "$ip"; then
|
||||
NEED_RELOAD=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $NEED_RELOAD -eq 1 ]]; then
|
||||
echo "[INFO] 检测到 db.argus.com 变更,执行 reload-bind9.sh"
|
||||
bash "$RELOAD_SCRIPT"
|
||||
fi
|
||||
|
||||
flock -u 9
|
||||
else
|
||||
echo "[INFO] 已有同步任务在运行,跳过本轮"
|
||||
fi
|
||||
|
||||
sleep "$SLEEP_SECONDS"
|
||||
done
|
||||
|
||||
16
src/bind/build/db.argus.com
Normal file
16
src/bind/build/db.argus.com
Normal file
@@ -0,0 +1,16 @@
|
||||
$TTL 604800
|
||||
@ IN SOA ns1.argus.com. admin.argus.com. (
|
||||
2 ; Serial
|
||||
604800 ; Refresh
|
||||
86400 ; Retry
|
||||
2419200 ; Expire
|
||||
604800 ) ; Negative Cache TTL
|
||||
|
||||
; 定义 DNS 服务器
|
||||
@ IN NS ns1.argus.com.
|
||||
|
||||
; 定义 ns1 主机
|
||||
ns1 IN A 127.0.0.1
|
||||
|
||||
; 定义 web 指向 12.4.5.6
|
||||
web IN A 12.4.5.6
|
||||
68
src/bind/build/dns-monitor.sh
Normal file
68
src/bind/build/dns-monitor.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# DNS监控脚本 - 每10秒检查dns.conf是否有变化
|
||||
# 如果有变化则执行update-dns.sh脚本
|
||||
|
||||
DNS_CONF="/private/argus/etc/dns.conf"
|
||||
DNS_BACKUP="/tmp/dns.conf.backup"
|
||||
UPDATE_SCRIPT="/private/argus/etc/update-dns.sh"
|
||||
LOG_FILE="/var/log/supervisor/dns-monitor.log"
|
||||
|
||||
# 确保日志文件存在
|
||||
touch "$LOG_FILE"
|
||||
|
||||
log_message() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') [DNS-Monitor] $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
log_message "DNS监控脚本启动"
|
||||
|
||||
while true; do
|
||||
if [ -f "$DNS_CONF" ]; then
|
||||
if [ -f "$DNS_BACKUP" ]; then
|
||||
# 比较文件内容
|
||||
if ! cmp -s "$DNS_CONF" "$DNS_BACKUP"; then
|
||||
log_message "检测到DNS配置变化"
|
||||
|
||||
# 更新备份文件
|
||||
cp "$DNS_CONF" "$DNS_BACKUP"
|
||||
|
||||
# 执行更新脚本
|
||||
if [ -x "$UPDATE_SCRIPT" ]; then
|
||||
log_message "执行DNS更新脚本: $UPDATE_SCRIPT"
|
||||
"$UPDATE_SCRIPT" >> "$LOG_FILE" 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log_message "DNS更新脚本执行成功"
|
||||
else
|
||||
log_message "DNS更新脚本执行失败"
|
||||
fi
|
||||
else
|
||||
log_message "警告: 更新脚本不存在或不可执行: $UPDATE_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
|
||||
# 第一次检测到配置文件,执行更新脚本
|
||||
if [ -x "$UPDATE_SCRIPT" ]; then
|
||||
log_message "执行DNS更新脚本: $UPDATE_SCRIPT"
|
||||
"$UPDATE_SCRIPT" >> "$LOG_FILE" 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log_message "DNS更新脚本执行成功"
|
||||
|
||||
# 第一次运行,创建备份并执行更新
|
||||
cp "$DNS_CONF" "$DNS_BACKUP"
|
||||
log_message "创建DNS配置备份文件"
|
||||
|
||||
else
|
||||
log_message "DNS更新脚本执行失败"
|
||||
fi
|
||||
else
|
||||
log_message "警告: 更新脚本不存在或不可执行: $UPDATE_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_message "警告: DNS配置文件不存在: $DNS_CONF"
|
||||
fi
|
||||
|
||||
sleep 10
|
||||
done
|
||||
4
src/bind/build/named.conf.local
Normal file
4
src/bind/build/named.conf.local
Normal file
@@ -0,0 +1,4 @@
|
||||
zone "argus.com" {
|
||||
type master;
|
||||
file "/etc/bind/db.argus.com";
|
||||
};
|
||||
27
src/bind/build/reload-bind9.sh
Normal file
27
src/bind/build/reload-bind9.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Reloading BIND9 configuration..."
|
||||
|
||||
# Check if configuration files are valid
|
||||
echo "Checking named.conf.local syntax..."
|
||||
if ! named-checkconf /etc/bind/named.conf.local; then
|
||||
echo "ERROR: named.conf.local has syntax errors!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking zone file syntax..."
|
||||
if ! named-checkzone argus.com /etc/bind/db.argus.com; then
|
||||
echo "ERROR: db.argus.com has syntax errors!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Reload BIND9 via supervisor
|
||||
echo "Reloading BIND9 service..."
|
||||
supervisorctl restart bind9
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "BIND9 reloaded successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to reload BIND9!"
|
||||
exit 1
|
||||
fi
|
||||
40
src/bind/build/startup.sh
Normal file
40
src/bind/build/startup.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set /private permissions to 777 as requested
|
||||
chmod 777 /private 2>/dev/null || true
|
||||
|
||||
# Create persistent directories for BIND9 configs and DNS sync
|
||||
mkdir -p /private/argus/bind
|
||||
mkdir -p /private/argus/etc
|
||||
|
||||
# Copy configuration files to persistent storage if they don't exist
|
||||
if [ ! -f /private/argus/bind/named.conf.local ]; then
|
||||
cp /etc/bind/named.conf.local /private/argus/bind/named.conf.local
|
||||
fi
|
||||
|
||||
if [ ! -f /private/argus/bind/db.argus.com ]; then
|
||||
cp /etc/bind/db.argus.com /private/argus/bind/db.argus.com
|
||||
fi
|
||||
|
||||
# Copy update-dns.sh to /private/argus/etc/
|
||||
cp /usr/local/bin/update-dns.sh /private/argus/etc/update-dns.sh
|
||||
chown bind:bind /private/argus/etc/update-dns.sh
|
||||
chmod a+x /private/argus/etc/update-dns.sh
|
||||
|
||||
# Create symlinks to use persistent configs
|
||||
ln -sf /private/argus/bind/named.conf.local /etc/bind/named.conf.local
|
||||
ln -sf /private/argus/bind/db.argus.com /etc/bind/db.argus.com
|
||||
|
||||
# Set proper ownership
|
||||
chown bind:bind /private/argus/bind/named.conf.local /private/argus/bind/db.argus.com
|
||||
|
||||
# 记录容器ip地址更新到dns.conf
|
||||
IP=`ifconfig | grep -A 1 eth0 | grep inet | awk '{print $2}'`
|
||||
echo current IP: ${IP}
|
||||
echo ${IP} > /private/argus/etc/dns.conf
|
||||
|
||||
# Create supervisor log directory
|
||||
mkdir -p /var/log/supervisor
|
||||
|
||||
# Start supervisor
|
||||
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
37
src/bind/build/supervisord.conf
Normal file
37
src/bind/build/supervisord.conf
Normal file
@@ -0,0 +1,37 @@
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
logfile=/var/log/supervisor/supervisord.log
|
||||
pidfile=/var/run/supervisord.pid
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock
|
||||
|
||||
[program:bind9]
|
||||
command=/usr/sbin/named -g -c /etc/bind/named.conf -u bind
|
||||
user=bind
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/log/supervisor/bind9.err.log
|
||||
stdout_logfile=/var/log/supervisor/bind9.out.log
|
||||
priority=10
|
||||
|
||||
[program:argus-dns-sync]
|
||||
command=/usr/local/bin/argus_dns_sync.sh
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=3
|
||||
stopsignal=TERM
|
||||
user=root
|
||||
stdout_logfile=/var/log/argus_dns_sync.out.log
|
||||
stderr_logfile=/var/log/argus_dns_sync.err.log
|
||||
; 根据环境调整环境变量(可选)
|
||||
; environment=RNDC_RELOAD="yes"
|
||||
|
||||
31
src/bind/build/update-dns.sh
Executable file
31
src/bind/build/update-dns.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
# update-dns.sh
|
||||
# 从 /private/argus/etc/dns.conf 读取 IP,写入 /etc/resolv.conf
|
||||
|
||||
DNS_CONF="/private/argus/etc/dns.conf"
|
||||
RESOLV_CONF="/etc/resolv.conf"
|
||||
|
||||
# 检查配置文件是否存在
|
||||
if [ ! -f "$DNS_CONF" ]; then
|
||||
echo "配置文件不存在: $DNS_CONF" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 生成 resolv.conf 内容
|
||||
{
|
||||
while IFS= read -r ip; do
|
||||
# 跳过空行和注释
|
||||
case "$ip" in
|
||||
\#*) continue ;;
|
||||
"") continue ;;
|
||||
esac
|
||||
echo "nameserver $ip"
|
||||
done < "$DNS_CONF"
|
||||
} > "$RESOLV_CONF".tmp
|
||||
|
||||
# 替换写入 /etc/resolv.conf
|
||||
cat "$RESOLV_CONF".tmp > "$RESOLV_CONF"
|
||||
rm -f "$RESOLV_CONF".tmp
|
||||
|
||||
echo "已更新 $RESOLV_CONF"
|
||||
|
||||
16
src/bind/tests/docker-compose.yml
Normal file
16
src/bind/tests/docker-compose.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
services:
|
||||
bind9:
|
||||
image: argus-bind9:latest
|
||||
container_name: argus-bind9-test
|
||||
ports:
|
||||
- "53:53/tcp"
|
||||
- "53:53/udp"
|
||||
volumes:
|
||||
- ./private:/private
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- bind-test-network
|
||||
|
||||
networks:
|
||||
bind-test-network:
|
||||
driver: bridge
|
||||
115
src/bind/tests/scripts/00_e2e_test.sh
Executable file
115
src/bind/tests/scripts/00_e2e_test.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/bin/bash
|
||||
|
||||
# End-to-end test for BIND9 DNS server
|
||||
# This script runs all tests in sequence to validate the complete functionality
|
||||
# Usage: ./00_e2e_test.sh
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
echo "=========================================="
|
||||
echo "BIND9 DNS Server End-to-End Test Suite"
|
||||
echo "=========================================="
|
||||
|
||||
# Track test results
|
||||
total_tests=0
|
||||
passed_tests=0
|
||||
failed_tests=0
|
||||
|
||||
# Function to run a test step
|
||||
run_test_step() {
|
||||
local step_name="$1"
|
||||
local script_name="$2"
|
||||
local description="$3"
|
||||
|
||||
echo ""
|
||||
echo "[$step_name] $description"
|
||||
echo "$(printf '=%.0s' {1..50})"
|
||||
|
||||
((total_tests++))
|
||||
|
||||
if [ ! -f "$SCRIPT_DIR/$script_name" ]; then
|
||||
echo "✗ Test script not found: $script_name"
|
||||
((failed_tests++))
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Make sure script is executable
|
||||
chmod +x "$SCRIPT_DIR/$script_name"
|
||||
|
||||
# Run the test
|
||||
echo "Executing: $SCRIPT_DIR/$script_name"
|
||||
if "$SCRIPT_DIR/$script_name"; then
|
||||
echo "✓ $step_name completed successfully"
|
||||
((passed_tests++))
|
||||
return 0
|
||||
else
|
||||
echo "✗ $step_name failed"
|
||||
((failed_tests++))
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup any previous test environment (but preserve the Docker image)
|
||||
echo ""
|
||||
echo "[SETUP] Cleaning up any previous test environment..."
|
||||
if [ -f "$SCRIPT_DIR/05_cleanup.sh" ]; then
|
||||
chmod +x "$SCRIPT_DIR/05_cleanup.sh"
|
||||
"$SCRIPT_DIR/05_cleanup.sh" || true
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Starting BIND9 DNS server end-to-end test sequence..."
|
||||
|
||||
# Test sequence
|
||||
run_test_step "TEST-01" "01_start_container.sh" "Start BIND9 container" || true
|
||||
|
||||
run_test_step "TEST-02" "02_dig_test.sh" "Initial DNS resolution test" || true
|
||||
|
||||
run_test_step "TEST-03" "03_reload_test.sh" "Configuration reload with IP modification" || true
|
||||
|
||||
run_test_step "TEST-03.5" "03.5_dns_sync_test.sh" "DNS auto-sync functionality test" || true
|
||||
|
||||
run_test_step "TEST-04" "04_persistence_test.sh" "Configuration persistence after restart" || true
|
||||
|
||||
# Final cleanup (but preserve logs for review)
|
||||
echo ""
|
||||
echo "[CLEANUP] Cleaning up test environment..."
|
||||
run_test_step "CLEANUP" "05_cleanup.sh" "Clean up containers and networks" || true
|
||||
|
||||
# Test summary
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "TEST SUMMARY"
|
||||
echo "=========================================="
|
||||
echo "Total tests: $total_tests"
|
||||
echo "Passed: $passed_tests"
|
||||
echo "Failed: $failed_tests"
|
||||
|
||||
if [ $failed_tests -eq 0 ]; then
|
||||
echo ""
|
||||
echo "✅ ALL TESTS PASSED!"
|
||||
echo ""
|
||||
echo "BIND9 DNS server functionality validated:"
|
||||
echo " ✓ Container startup and basic functionality"
|
||||
echo " ✓ DNS resolution for configured domains"
|
||||
echo " ✓ Configuration modification and reload"
|
||||
echo " ✓ DNS auto-sync from IP files"
|
||||
echo " ✓ Configuration persistence across restarts"
|
||||
echo " ✓ Cleanup and resource management"
|
||||
echo ""
|
||||
echo "The BIND9 DNS server is ready for production use."
|
||||
exit 0
|
||||
else
|
||||
echo ""
|
||||
echo "❌ SOME TESTS FAILED!"
|
||||
echo ""
|
||||
echo "Please review the test output above to identify and fix issues."
|
||||
echo "You may need to:"
|
||||
echo " - Check Docker installation and permissions"
|
||||
echo " - Verify network connectivity"
|
||||
echo " - Review BIND9 configuration files"
|
||||
echo " - Check system resources and port availability"
|
||||
exit 1
|
||||
fi
|
||||
38
src/bind/tests/scripts/01_start_container.sh
Executable file
38
src/bind/tests/scripts/01_start_container.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Start BIND9 test container
|
||||
# Usage: ./01_start_container.sh
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
cd "$TEST_DIR"
|
||||
|
||||
echo "Starting BIND9 test container..."
|
||||
|
||||
# Ensure private directory exists with proper permissions
|
||||
mkdir -p private
|
||||
chmod 777 private
|
||||
|
||||
# Start the container
|
||||
docker compose up -d
|
||||
|
||||
echo "Waiting for container to be ready..."
|
||||
sleep 5
|
||||
|
||||
# Check if container is running
|
||||
if docker compose ps | grep -q "Up"; then
|
||||
echo "✓ Container started successfully"
|
||||
echo "Container status:"
|
||||
docker compose ps
|
||||
else
|
||||
echo "✗ Failed to start container"
|
||||
docker compose logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "BIND9 test environment is ready!"
|
||||
echo "DNS server listening on localhost:53"
|
||||
72
src/bind/tests/scripts/02_dig_test.sh
Executable file
72
src/bind/tests/scripts/02_dig_test.sh
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test DNS resolution using dig
|
||||
# Usage: ./02_dig_test.sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "Testing DNS resolution with dig..."
|
||||
|
||||
# Function to test DNS query
|
||||
test_dns_query() {
|
||||
local hostname="$1"
|
||||
local expected_ip="$2"
|
||||
local description="$3"
|
||||
|
||||
echo ""
|
||||
echo "Testing: $description"
|
||||
echo "Query: $hostname.argus.com"
|
||||
echo "Expected IP: $expected_ip"
|
||||
|
||||
# Perform dig query
|
||||
result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED")
|
||||
|
||||
if [ "$result" = "QUERY_FAILED" ]; then
|
||||
echo "✗ DNS query failed"
|
||||
return 1
|
||||
elif [ "$result" = "$expected_ip" ]; then
|
||||
echo "✓ DNS query successful: $result"
|
||||
return 0
|
||||
else
|
||||
echo "✗ DNS query returned unexpected result: $result"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if dig is available
|
||||
if ! command -v dig &> /dev/null; then
|
||||
echo "Installing dig (dnsutils)..."
|
||||
apt-get update && apt-get install -y dnsutils
|
||||
fi
|
||||
|
||||
# Check if container is running
|
||||
if ! docker compose ps | grep -q "Up"; then
|
||||
echo "Error: BIND9 container is not running"
|
||||
echo "Please start the container first with: ./01_start_container.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== DNS Resolution Tests ==="
|
||||
|
||||
# Test cases based on current configuration
|
||||
failed_tests=0
|
||||
|
||||
# Test ns1.argus.com -> 127.0.0.1
|
||||
if ! test_dns_query "ns1" "127.0.0.1" "Name server resolution"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
# Test web.argus.com -> 12.4.5.6
|
||||
if ! test_dns_query "web" "12.4.5.6" "Web server resolution"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Test Summary ==="
|
||||
if [ $failed_tests -eq 0 ]; then
|
||||
echo "✓ All DNS tests passed!"
|
||||
exit 0
|
||||
else
|
||||
echo "✗ $failed_tests test(s) failed"
|
||||
exit 1
|
||||
fi
|
||||
256
src/bind/tests/scripts/03.5_dns_sync_test.sh
Executable file
256
src/bind/tests/scripts/03.5_dns_sync_test.sh
Executable file
@@ -0,0 +1,256 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test DNS auto-sync functionality using argus_dns_sync.sh
|
||||
# This test validates the automatic DNS record updates from IP files
|
||||
# Usage: ./03.5_dns_sync_test.sh
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
echo "=== DNS Auto-Sync Functionality Test ==="
|
||||
|
||||
# Check if container is running
|
||||
if ! docker compose ps | grep -q "Up"; then
|
||||
echo "Error: BIND9 container is not running"
|
||||
echo "Please start the container first with: ./01_start_container.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if dig is available
|
||||
if ! command -v dig &> /dev/null; then
|
||||
echo "Installing dig (dnsutils)..."
|
||||
apt-get update && apt-get install -y dnsutils
|
||||
fi
|
||||
|
||||
# Function to test DNS query
|
||||
test_dns_query() {
|
||||
local hostname="$1"
|
||||
local expected_ip="$2"
|
||||
local description="$3"
|
||||
|
||||
echo "Testing: $description"
|
||||
echo "Query: $hostname.argus.com -> Expected: $expected_ip"
|
||||
|
||||
# Wait a moment for DNS cache
|
||||
sleep 2
|
||||
|
||||
result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED")
|
||||
|
||||
if [ "$result" = "$expected_ip" ]; then
|
||||
echo "✓ $result"
|
||||
return 0
|
||||
else
|
||||
echo "✗ Got: $result, Expected: $expected_ip"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to wait for sync to complete
|
||||
wait_for_sync() {
|
||||
local timeout=15
|
||||
local elapsed=0
|
||||
echo "Waiting for DNS sync to complete (max ${timeout}s)..."
|
||||
|
||||
while [ $elapsed -lt $timeout ]; do
|
||||
if docker compose exec bind9 test -f /var/lock/argus_dns_sync.lock; then
|
||||
echo "Sync process is running..."
|
||||
else
|
||||
echo "Sync completed"
|
||||
sleep 2 # Extra wait for DNS propagation
|
||||
return 0
|
||||
fi
|
||||
sleep 2
|
||||
elapsed=$((elapsed + 2))
|
||||
done
|
||||
|
||||
echo "Warning: Sync may still be running after ${timeout}s"
|
||||
return 0
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "Step 1: Preparing test environment..."
|
||||
|
||||
# Ensure required directories exist
|
||||
docker compose exec bind9 mkdir -p /private/argus/etc
|
||||
docker compose exec bind9 mkdir -p /private/argus/bind/.backup
|
||||
|
||||
# Backup original configuration if it exists
|
||||
docker compose exec bind9 test -f /private/argus/bind/db.argus.com && \
|
||||
docker compose exec bind9 cp /private/argus/bind/db.argus.com /private/argus/bind/db.argus.com.backup.test || true
|
||||
|
||||
# Ensure initial configuration is available (may already be symlinked)
|
||||
docker compose exec bind9 test -f /private/argus/bind/db.argus.com || \
|
||||
docker compose exec bind9 cp /etc/bind/db.argus.com /private/argus/bind/db.argus.com
|
||||
|
||||
echo "✓ Test environment prepared"
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Testing initial DNS configuration..."
|
||||
|
||||
# Get current IP for web.argus.com (may have been changed by previous tests)
|
||||
current_web_ip=$(dig @localhost web.argus.com A +short 2>/dev/null || echo "UNKNOWN")
|
||||
echo "Current web.argus.com IP: $current_web_ip"
|
||||
|
||||
# Test that DNS is working (regardless of specific IP)
|
||||
if [ "$current_web_ip" = "UNKNOWN" ] || [ -z "$current_web_ip" ]; then
|
||||
echo "DNS resolution not working for web.argus.com"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ DNS resolution is working"
|
||||
|
||||
echo ""
|
||||
echo "Step 3: Creating IP files for auto-sync..."
|
||||
|
||||
# Create test IP files in the watch directory
|
||||
echo "Creating test1.argus.com with IP 10.0.0.100"
|
||||
docker compose exec bind9 bash -c 'echo "10.0.0.100" > /private/argus/etc/test1.argus.com'
|
||||
|
||||
echo "Creating test2.argus.com with IP 10.0.0.200"
|
||||
docker compose exec bind9 bash -c 'echo "test2 service running on 10.0.0.200" > /private/argus/etc/test2.argus.com'
|
||||
|
||||
echo "Creating api.argus.com with IP 192.168.1.50"
|
||||
docker compose exec bind9 bash -c 'echo "API server: 192.168.1.50 port 8080" > /private/argus/etc/api.argus.com'
|
||||
|
||||
echo "✓ IP files created"
|
||||
|
||||
echo ""
|
||||
echo "Step 4: Checking DNS sync process..."
|
||||
|
||||
# Check if DNS sync process is already running (via supervisord)
|
||||
if docker compose exec bind9 pgrep -f argus_dns_sync.sh > /dev/null; then
|
||||
echo "✓ DNS sync process already running (via supervisord)"
|
||||
else
|
||||
echo "Starting DNS sync process manually..."
|
||||
# Start the DNS sync process in background if not running
|
||||
docker compose exec -d bind9 /usr/local/bin/argus_dns_sync.sh
|
||||
echo "✓ DNS sync process started manually"
|
||||
fi
|
||||
|
||||
# Wait for first sync cycle
|
||||
wait_for_sync
|
||||
|
||||
echo ""
|
||||
echo "Step 5: Testing auto-synced DNS records..."
|
||||
|
||||
failed_tests=0
|
||||
|
||||
# Test new DNS records created by auto-sync
|
||||
if ! test_dns_query "test1" "10.0.0.100" "Auto-synced test1.argus.com"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
if ! test_dns_query "test2" "10.0.0.200" "Auto-synced test2.argus.com"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
if ! test_dns_query "api" "192.168.1.50" "Auto-synced api.argus.com"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
# Verify original records still work (use current IP from earlier)
|
||||
if ! test_dns_query "web" "$current_web_ip" "Original web.argus.com still working"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
if ! test_dns_query "ns1" "127.0.0.1" "Original ns1.argus.com still working"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 6: Testing IP update functionality..."
|
||||
|
||||
# Update an existing IP file
|
||||
echo "Updating test1.argus.com IP from 10.0.0.100 to 10.0.0.150"
|
||||
docker compose exec bind9 bash -c 'echo "10.0.0.150" > /private/argus/etc/test1.argus.com'
|
||||
|
||||
# Wait for sync
|
||||
wait_for_sync
|
||||
|
||||
# Test updated record
|
||||
if ! test_dns_query "test1" "10.0.0.150" "Updated test1.argus.com IP"; then
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 7: Testing invalid IP handling..."
|
||||
|
||||
# Create file with invalid IP
|
||||
echo "Creating invalid.argus.com with invalid IP"
|
||||
docker compose exec bind9 bash -c 'echo "this is not an IP address" > /private/argus/etc/invalid.argus.com'
|
||||
|
||||
# Wait for sync (should skip invalid IP)
|
||||
wait_for_sync
|
||||
|
||||
# Verify invalid record was not added (should fail to resolve)
|
||||
result=$(dig @localhost invalid.argus.com A +short 2>/dev/null || echo "NO_RESULT")
|
||||
if [ "$result" = "NO_RESULT" ] || [ -z "$result" ]; then
|
||||
echo "✓ Invalid IP correctly ignored"
|
||||
else
|
||||
echo "✗ Invalid IP was processed: $result"
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 8: Verifying backup functionality..."
|
||||
|
||||
# Check if backups were created
|
||||
backup_count=$(docker compose exec bind9 ls -1 /private/argus/bind/.backup/ | wc -l || echo "0")
|
||||
if [ "$backup_count" -gt 0 ]; then
|
||||
echo "✓ Configuration backups created ($backup_count files)"
|
||||
# Show latest backup
|
||||
docker compose exec bind9 ls -la /private/argus/bind/.backup/ | tail -1
|
||||
else
|
||||
echo "✗ No backup files found"
|
||||
((failed_tests++))
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 9: Cleanup..."
|
||||
|
||||
# Note: We don't stop the DNS sync process since it's managed by supervisord
|
||||
echo "Note: DNS sync process will continue running (managed by supervisord)"
|
||||
|
||||
# Clean up test files
|
||||
docker compose exec bind9 rm -f /private/argus/etc/test1.argus.com
|
||||
docker compose exec bind9 rm -f /private/argus/etc/test2.argus.com
|
||||
docker compose exec bind9 rm -f /private/argus/etc/api.argus.com
|
||||
docker compose exec bind9 rm -f /private/argus/etc/invalid.argus.com
|
||||
|
||||
# Restore original configuration if backup exists
|
||||
docker compose exec bind9 test -f /private/argus/bind/db.argus.com.backup.test && \
|
||||
docker compose exec bind9 cp /private/argus/bind/db.argus.com.backup.test /private/argus/bind/db.argus.com && \
|
||||
docker compose exec bind9 rm /private/argus/bind/db.argus.com.backup.test || true
|
||||
|
||||
# Reload original configuration
|
||||
docker compose exec bind9 /usr/local/bin/reload-bind9.sh
|
||||
|
||||
echo "✓ Cleanup completed"
|
||||
|
||||
echo ""
|
||||
echo "=== DNS Auto-Sync Test Summary ==="
|
||||
if [ $failed_tests -eq 0 ]; then
|
||||
echo "✅ All DNS auto-sync tests passed!"
|
||||
echo ""
|
||||
echo "Validated functionality:"
|
||||
echo " ✓ Automatic DNS record creation from IP files"
|
||||
echo " ✓ IP address extraction from various file formats"
|
||||
echo " ✓ Dynamic DNS record updates"
|
||||
echo " ✓ Invalid IP address handling"
|
||||
echo " ✓ Configuration backup mechanism"
|
||||
echo " ✓ Preservation of existing DNS records"
|
||||
echo ""
|
||||
echo "The DNS auto-sync functionality is working correctly!"
|
||||
exit 0
|
||||
else
|
||||
echo "❌ $failed_tests DNS auto-sync test(s) failed!"
|
||||
echo ""
|
||||
echo "Please check:"
|
||||
echo " - argus_dns_sync.sh script configuration"
|
||||
echo " - File permissions in /private/argus/etc/"
|
||||
echo " - BIND9 reload functionality"
|
||||
echo " - Network connectivity and DNS resolution"
|
||||
exit 1
|
||||
fi
|
||||
112
src/bind/tests/scripts/03_reload_test.sh
Executable file
112
src/bind/tests/scripts/03_reload_test.sh
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test DNS configuration reload with IP modification
|
||||
# Usage: ./03_reload_test.sh
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
echo "=== DNS Configuration Reload Test ==="
|
||||
|
||||
# Check if container is running
|
||||
if ! docker compose ps | grep -q "Up"; then
|
||||
echo "Error: BIND9 container is not running"
|
||||
echo "Please start the container first with: ./01_start_container.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if dig is available
|
||||
if ! command -v dig &> /dev/null; then
|
||||
echo "Installing dig (dnsutils)..."
|
||||
apt-get update && apt-get install -y dnsutils
|
||||
fi
|
||||
|
||||
# Function to test DNS query
|
||||
test_dns_query() {
|
||||
local hostname="$1"
|
||||
local expected_ip="$2"
|
||||
local description="$3"
|
||||
|
||||
echo "Testing: $description"
|
||||
echo "Query: $hostname.argus.com -> Expected: $expected_ip"
|
||||
|
||||
result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED")
|
||||
|
||||
if [ "$result" = "$expected_ip" ]; then
|
||||
echo "✓ $result"
|
||||
return 0
|
||||
else
|
||||
echo "✗ Got: $result, Expected: $expected_ip"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "Step 1: Testing initial DNS configuration..."
|
||||
|
||||
# Test initial configuration
|
||||
if ! test_dns_query "web" "12.4.5.6" "Initial web.argus.com resolution"; then
|
||||
echo "Initial DNS test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Modifying DNS configuration..."
|
||||
|
||||
# Backup original configuration
|
||||
cp "$TEST_DIR/private/argus/bind/db.argus.com" "$TEST_DIR/private/argus/bind/db.argus.com.backup" 2>/dev/null || true
|
||||
|
||||
# Create new configuration with modified IP
|
||||
DB_FILE="$TEST_DIR/private/argus/bind/db.argus.com"
|
||||
|
||||
# Check if persistent config exists, if not use from container
|
||||
if [ ! -f "$DB_FILE" ]; then
|
||||
echo "Persistent config not found, copying from container..."
|
||||
docker compose exec bind9 cp /etc/bind/db.argus.com /private/argus/bind/db.argus.com
|
||||
docker compose exec bind9 chown bind:bind /private/argus/bind/db.argus.com
|
||||
fi
|
||||
|
||||
# Modify the IP address (12.4.5.6 -> 192.168.1.100)
|
||||
sed -i 's/12\.4\.5\.6/192.168.1.100/g' "$DB_FILE"
|
||||
|
||||
# Increment serial number for DNS cache invalidation
|
||||
current_serial=$(grep -o "2[[:space:]]*;" "$DB_FILE" | grep -o "2")
|
||||
new_serial=$((current_serial + 1))
|
||||
sed -i "s/2[[:space:]]*;/${new_serial} ;/" "$DB_FILE"
|
||||
|
||||
echo "Modified configuration:"
|
||||
echo "- Changed web.argus.com IP: 12.4.5.6 -> 192.168.1.100"
|
||||
echo "- Updated serial number: $current_serial -> $new_serial"
|
||||
|
||||
echo ""
|
||||
echo "Step 3: Reloading BIND9 configuration..."
|
||||
|
||||
# Reload BIND9 configuration
|
||||
docker compose exec bind9 /usr/local/bin/reload-bind9.sh
|
||||
|
||||
echo "Configuration reloaded"
|
||||
|
||||
# Wait a moment for changes to take effect
|
||||
sleep 3
|
||||
|
||||
echo ""
|
||||
echo "Step 4: Testing modified DNS configuration..."
|
||||
|
||||
# Test modified configuration
|
||||
if ! test_dns_query "web" "192.168.1.100" "Modified web.argus.com resolution"; then
|
||||
echo "Modified DNS test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Also verify ns1 still works
|
||||
if ! test_dns_query "ns1" "127.0.0.1" "ns1.argus.com still working"; then
|
||||
echo "ns1 DNS test failed after reload"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✓ DNS configuration reload test completed successfully!"
|
||||
echo "✓ IP address changed from 12.4.5.6 to 192.168.1.100"
|
||||
echo "✓ Configuration persisted and reloaded correctly"
|
||||
115
src/bind/tests/scripts/04_persistence_test.sh
Executable file
115
src/bind/tests/scripts/04_persistence_test.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test configuration persistence after container restart
|
||||
# Usage: ./04_persistence_test.sh
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
echo "=== Configuration Persistence Test ==="
|
||||
|
||||
# Check if dig is available
|
||||
if ! command -v dig &> /dev/null; then
|
||||
echo "Installing dig (dnsutils)..."
|
||||
apt-get update && apt-get install -y dnsutils
|
||||
fi
|
||||
|
||||
# Function to test DNS query
|
||||
test_dns_query() {
|
||||
local hostname="$1"
|
||||
local expected_ip="$2"
|
||||
local description="$3"
|
||||
|
||||
echo "Testing: $description"
|
||||
echo "Query: $hostname.argus.com -> Expected: $expected_ip"
|
||||
|
||||
result=$(dig @localhost $hostname.argus.com A +short 2>/dev/null || echo "QUERY_FAILED")
|
||||
|
||||
if [ "$result" = "$expected_ip" ]; then
|
||||
echo "✓ $result"
|
||||
return 0
|
||||
else
|
||||
echo "✗ Got: $result, Expected: $expected_ip"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "Step 1: Stopping current container..."
|
||||
|
||||
# Stop the container
|
||||
docker compose down
|
||||
|
||||
echo "Container stopped"
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Verifying persistent configuration exists..."
|
||||
|
||||
# Check if modified configuration exists
|
||||
DB_FILE="$TEST_DIR/private/argus/bind/db.argus.com"
|
||||
|
||||
if [ ! -f "$DB_FILE" ]; then
|
||||
echo "✗ Persistent configuration file not found: $DB_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the modified IP is in the configuration
|
||||
if grep -q "192.168.1.100" "$DB_FILE"; then
|
||||
echo "✓ Modified IP (192.168.1.100) found in persistent configuration"
|
||||
else
|
||||
echo "✗ Modified IP not found in persistent configuration"
|
||||
echo "Configuration content:"
|
||||
cat "$DB_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 3: Restarting container with persistent configuration..."
|
||||
|
||||
# Start the container again
|
||||
docker compose up -d
|
||||
|
||||
echo "Waiting for container to be ready..."
|
||||
sleep 5
|
||||
|
||||
# Check if container is running
|
||||
if ! docker compose ps | grep -q "Up"; then
|
||||
echo "✗ Failed to restart container"
|
||||
docker compose logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Container restarted successfully"
|
||||
|
||||
echo ""
|
||||
echo "Step 4: Testing DNS resolution after restart..."
|
||||
|
||||
# Wait a bit more for DNS to be fully ready
|
||||
sleep 5
|
||||
|
||||
# Test that the modified configuration is still active
|
||||
if ! test_dns_query "web" "192.168.1.100" "Persistent web.argus.com resolution"; then
|
||||
echo "✗ Persistent configuration test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Also verify ns1 still works
|
||||
if ! test_dns_query "ns1" "127.0.0.1" "ns1.argus.com still working"; then
|
||||
echo "✗ ns1 DNS test failed after restart"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 5: Verifying configuration files are linked correctly..."
|
||||
|
||||
# Check that the persistent files are properly linked
|
||||
echo "Checking file links in container:"
|
||||
docker compose exec bind9 ls -la /etc/bind/named.conf.local /etc/bind/db.argus.com
|
||||
|
||||
echo ""
|
||||
echo "✓ Configuration persistence test completed successfully!"
|
||||
echo "✓ Modified IP (192.168.1.100) persisted after container restart"
|
||||
echo "✓ Configuration files properly linked to persistent storage"
|
||||
echo "✓ DNS resolution working correctly with persisted configuration"
|
||||
87
src/bind/tests/scripts/05_cleanup.sh
Executable file
87
src/bind/tests/scripts/05_cleanup.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Clean up test environment and containers
|
||||
# Usage: ./05_cleanup.sh [--full]
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TEST_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
# Parse command line arguments
|
||||
FULL_CLEANUP=true
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--full)
|
||||
FULL_CLEANUP=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Usage: $0 [--full]"
|
||||
echo " --full: Also remove persistent data "
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
cd "$TEST_DIR"
|
||||
|
||||
echo "=== Cleaning up BIND9 test environment ==="
|
||||
|
||||
echo ""
|
||||
echo "Step 1: Stopping and removing containers..."
|
||||
|
||||
# Stop and remove containers
|
||||
docker compose down -v
|
||||
|
||||
echo "✓ Containers stopped and removed"
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Removing Docker networks..."
|
||||
|
||||
# Clean up networks
|
||||
docker network prune -f > /dev/null 2>&1 || true
|
||||
|
||||
echo "✓ Docker networks cleaned"
|
||||
|
||||
if [ "$FULL_CLEANUP" = true ]; then
|
||||
echo ""
|
||||
echo "Step 3: Removing persistent data..."
|
||||
|
||||
# Remove persistent data directory
|
||||
if [ -d "private" ]; then
|
||||
rm -rf private
|
||||
echo "✓ Persistent data directory removed"
|
||||
else
|
||||
echo "✓ No persistent data directory found"
|
||||
fi
|
||||
|
||||
else
|
||||
echo ""
|
||||
echo "Step 3: Preserving persistent data and Docker image..."
|
||||
echo "✓ Persistent data preserved in: private/"
|
||||
echo "✓ Docker image 'argus-bind9:latest' preserved"
|
||||
echo ""
|
||||
echo "To perform full cleanup including persistent data and image, run:"
|
||||
echo " $0 --full"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Cleanup Summary ==="
|
||||
echo "✓ Containers stopped and removed"
|
||||
echo "✓ Docker networks cleaned"
|
||||
|
||||
if [ "$FULL_CLEANUP" = true ]; then
|
||||
echo "✓ Persistent data removed"
|
||||
echo ""
|
||||
echo "Full cleanup completed! Test environment completely removed."
|
||||
else
|
||||
echo "✓ Persistent data preserved"
|
||||
echo "✓ Docker image preserved"
|
||||
echo ""
|
||||
echo "Basic cleanup completed! Run './01_start_container.sh' to restart testing."
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Test environment cleanup finished."
|
||||
Reference in New Issue
Block a user