1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
# -*- shell-script -*-
FUNCTIONS_DIR="debian/tests/functions.d"
match_or_exit () {
file_to_match="$1"
pattern_file="$2"
while read line_to_match <&3 && read pattern_line <&4 ; do
if [ "${line_to_match##$pattern_line}" ]; then
echo '!!! MISMATCH !!!' >&2
echo "Line: ${line_to_match}" >&2
echo "Pattern: ${pattern_line}" >&2
exit 1
fi;
done 3<"${file_to_match}" 4<"${pattern_file}"
}
linecount () {
wc -l $1 | cut -d' ' -f1
}
error_exit () {
echo "ERROR: $1"
exit 1
}
possibly_purge_resolved () {
# Uninstall systemd-resolved, to free port 53/UDP and restart dnsmasq
if [ "$(systemctl is-active systemd-resolved.service)" = 'active' ]; then
echo "Purging systemd-resolved..."
apt-get -yq purge systemd-resolved
if [ "$1" = 'and_restart_dnsmasq' ]; then
echo "Restarting dnsmasq.service..."
systemctl restart dnsmasq.service
fi
fi
}
stop_dnsmasq_bind_networking () {
systemctl stop dnsmasq.service
systemctl stop named.service
systemctl stop networking.service
}
configure_and_start_networking () {
# Add interfaces needed for the test
cat ${FUNCTIONS_DIR}/add-to.interfaces >> /etc/network/interfaces
# Extend dhcpcd configuration, Ubuntu runs dhcpcd in place of
# isc-dhcp-client and Debian might also use it in future.
# See bug #1089585 for details.
cat ${FUNCTIONS_DIR}/add-to.dhcpcd.conf >> /etc/dhcpcd.conf
systemctl start networking.service
}
configure_and_start_bind () {
cp ${FUNCTIONS_DIR}/db.autopkg.test /etc/bind/
cat ${FUNCTIONS_DIR}/add-to.named.conf.local >> /etc/bind/named.conf.local
cp ${FUNCTIONS_DIR}/named.conf.options /etc/bind/named.conf.options
systemctl start named.service
}
configure_and_start_dnsmasq () {
alt_mode=0
lua_mode=0
sysv_mode=0
service='dnsmasq.service'
sysv_param2=''
conf_dir='/etc/dnsmasq.d'
while [ -n "$1" ]; do
case "$1" in
alt|lua|sysv) eval ${1}_mode=1 ;;
*) error_exit "configure_and_start_dnsmasq(): invalid flag '$1'"
esac
shift
done
if [ ${alt_mode} -eq 1 ]; then
cp ${FUNCTIONS_DIR}/dnsmasq.alt-autopkgtest.default /etc/default/dnsmasq.alt
cp /etc/dnsmasq.conf /etc/dnsmasq.alt.conf
mkdir /etc/dnsmasq.alt.d
service='dnsmasq@alt.service'
sysv_param2='alt'
conf_dir='/etc/dnsmasq.alt.d'
fi
cp ${FUNCTIONS_DIR}/dnsmasq-autopkgtest.conf "${conf_dir}"
if [ ${lua_mode} -eq 1 ]; then
mkdir -p /usr/local/share/dnsmasq
cp ${FUNCTIONS_DIR}/log.lua /usr/local/share/dnsmasq/
echo "dhcp-luascript=/usr/local/share/dnsmasq/log.lua\n" \
>>"${conf_dir}"/dnsmasq-autopkgtest.conf
fi
if [ ${sysv_mode} -eq 1 ]; then
SYSTEMCTL_SKIP_REDIRECT=1 /etc/init.d/dnsmasq start "${sysv_param2}"
else
systemctl enable "${service}"
systemctl start "${service}"
fi
}
check_compile_time_options () {
journalctl -b -u dnsmasq
echo ~~~ Check compile time options...
journalctl -b -u dnsmasq -g 'options: ' --output cat >options.msg
cat options.msg
match_or_exit options.msg ${FUNCTIONS_DIR}/options${1}.patterns
}
get_address_on_veth1_and_check_the_result () {
echo ~~~ Get an address on veth1 and check the result...
ip netns exec clientnet ifup veth1
ip netns exec clientnet ip addr show dev veth1 >ip-addr.out 2>&1
cat ip-addr.out
match_or_exit ip-addr.out ${FUNCTIONS_DIR}/ip-addr.patterns
}
query_test_zone_records_and_check_the_result () {
echo ~~~ Query some test zone records and check the result...
ip netns exec clientnet dig +short SOA autopkg.test >dig.out 2>&1
ip netns exec clientnet dig +short NS autopkg.test >>dig.out 2>&1
ip netns exec clientnet dig +short A ns.autopkg.test >>dig.out 2>&1
ip netns exec clientnet dig +short A dhcp3.autopkg.test >>dig.out 2>&1
cat dig.out
if [ `linecount dig.out` -ne `linecount ${FUNCTIONS_DIR}/dig.patterns` ] ; then
error_exit 'empty or unexpected output'
fi
match_or_exit dig.out ${FUNCTIONS_DIR}/dig.patterns
}
check_utils () {
#Test dhcp_lease_time and dhcp_release
leases_file='/var/lib/misc/dnsmasq.leases'
client_ip_address=`cut -d' ' -f3 $leases_file`
client_mac_address=`cut -d' ' -f2 $leases_file`
echo ~~~ Test dhcp_lease_time...
if ! dhcp_lease_time $client_ip_address; then
error_exit "'dhcp_lease_time $client_ip_address' failed with return code $?"
else
#Add \n to dhcp_lease_time's output
echo ''
fi
echo ~~~ Test dhcp_release...
cat $leases_file
if ! dhcp_release veth0 $client_ip_address 1-$client_mac_address; then
error_exit "'dhcp_release veth0 $client_ip_address 1-$client_mac_address' failed with return code $?"
fi
sleep 1
if [ -n "`cat $leases_file`" ]; then
cat $leases_file
error_exit "$leases_file is not empty"
fi
}
check_lua_log () {
log_file='/var/log/dnsmasq-lua.log'
echo ~~~ Check log file generated by lua script
ls -l ${log_file}
if [ -s ${log_file} ]; then
cat ${log_file}
match_or_exit ${log_file} ${FUNCTIONS_DIR}/log.patterns
else
error_exit "${log_file} is empty"
fi
}
check_dnsmasq_status () {
echo ~~ Check whether dnsmasq has been started up successfully
systemctl status dnsmasq.service
}
|