From eb37fd2f136afdf0937261aaf4e6066b95ef564d Mon Sep 17 00:00:00 2001 From: Matthijs Mekking Date: Thu, 6 Apr 2023 09:21:09 +0200 Subject: [PATCH] Add more log/tap rotation tests Add more tests to the dnstap system test to roll with different values. Touch some files to make sure the number of existing files exceed the number that we want to keep. Add a test to the logfileconfig system test for the increment suffix. (cherry picked from commit 9fb9670ebcc9d234c95c1c9512211ad6d50feea5) --- bin/tests/system/dnstap/tests.sh | 40 +++++++++----- bin/tests/system/logfileconfig/clean.sh | 2 + .../system/logfileconfig/ns1/named.incconf.in | 52 +++++++++++++++++++ bin/tests/system/logfileconfig/tests.sh | 28 ++++++++++ 4 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 bin/tests/system/logfileconfig/ns1/named.incconf.in diff --git a/bin/tests/system/dnstap/tests.sh b/bin/tests/system/dnstap/tests.sh index 5ed1d94c3c..9e28c95689 100644 --- a/bin/tests/system/dnstap/tests.sh +++ b/bin/tests/system/dnstap/tests.sh @@ -787,28 +787,42 @@ lines=`$DNSTAPREAD -y large-answer.fstrm | grep -c "opcode: QUERY"` if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` -test_dnstap_roll() ( +_test_dnstap_roll() ( ip="$1" ns="$2" n="$3" + $RNDCCMD -s "${ip}" dnstap -roll "${n}" | sed "s/^/${ns} /" | cat_i && files=$(find "$ns" -name "dnstap.out.[0-9]" | wc -l) && - test "$files" -le "${n}" && test "$files" -ge "1" + test "$files" -eq "${n}" && test "$files" -ge "1" ) -echo_i "checking 'rndc -roll ' (no versions)" -ret=0 -start_server --noclean --restart --port "${PORT}" ns3 -_repeat 5 test_dnstap_roll 10.53.0.3 ns3 3 || ret=1 -if [ $ret != 0 ]; then echo_i "failed"; fi -status=$((status+ret)) -echo_i "checking 'rndc -roll ' (versions)" -ret=0 +test_dnstap_roll() { + echo_i "checking 'rndc -roll $4' ($1)" + ret=0 + + try=0 + while test $try -lt 12 + do + touch "$3/dnstap.out.$try" + try=`expr $try + 1` + done + + _repeat 10 _test_dnstap_roll $2 $3 $4 || ret=1 + if [ $ret != 0 ]; then echo_i "failed"; fi + status=$((status+ret)) +} + +start_server --noclean --restart --port "${PORT}" ns3 +test_dnstap_roll "no versions" 10.53.0.3 ns3 6 +test_dnstap_roll "no versions" 10.53.0.3 ns3 3 +test_dnstap_roll "no versions" 10.53.0.3 ns3 1 + start_server --noclean --restart --port "${PORT}" ns2 -_repeat 5 test_dnstap_roll 10.53.0.2 ns2 3 || ret=1 -if [ $ret != 0 ]; then echo_i "failed"; fi -status=$((status+ret)) +test_dnstap_roll "versions" 10.53.0.2 ns2 6 +test_dnstap_roll "versions" 10.53.0.2 ns2 3 +test_dnstap_roll "versions" 10.53.0.2 ns2 1 echo_i "exit status: $status" [ "$status" -eq 0 ] || exit 1 diff --git a/bin/tests/system/logfileconfig/clean.sh b/bin/tests/system/logfileconfig/clean.sh index 18aa5de2dd..befbcfe84e 100644 --- a/bin/tests/system/logfileconfig/clean.sh +++ b/bin/tests/system/logfileconfig/clean.sh @@ -31,6 +31,8 @@ rm -f ns1/named_vers rm -f ns1/named_vers.* rm -f ns1/named_ts rm -f ns1/named_ts.* +rm -f ns1/named_inc +rm -f ns1/named_inc.* rm -f ns1/named_unlimited rm -f ns1/named_unlimited.* rm -f ns*/managed-keys.bind* diff --git a/bin/tests/system/logfileconfig/ns1/named.incconf.in b/bin/tests/system/logfileconfig/ns1/named.incconf.in new file mode 100644 index 0000000000..d398c330eb --- /dev/null +++ b/bin/tests/system/logfileconfig/ns1/named.incconf.in @@ -0,0 +1,52 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + query-source address 10.53.0.1; + notify-source 10.53.0.1; + transfer-source 10.53.0.1; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + listen-on-v6 { none; }; + dnssec-validation no; + recursion no; + notify yes; +}; + +logging { + channel default_log { + buffered no; + file "named_inc" versions 1 size 1k suffix increment; # small size + severity debug 100; + print-time yes; + }; + category default { default_log; default_debug; }; + category lame-servers { null; }; + + channel query_log { + file "query_log"; + print-time yes; + buffered yes; + }; + category queries { query_log; }; +}; + +controls { + inet 10.53.0.1 port @CONTROLPORT@ allow { any; } keys { "rndc-key"; }; +}; + +key rndc-key { + secret "1234abcd8765"; + algorithm hmac-sha256; +}; diff --git a/bin/tests/system/logfileconfig/tests.sh b/bin/tests/system/logfileconfig/tests.sh index 397f9aa443..8c433b07f7 100644 --- a/bin/tests/system/logfileconfig/tests.sh +++ b/bin/tests/system/logfileconfig/tests.sh @@ -208,6 +208,34 @@ retry_quiet 5 _found2 || ret=1 if [ "$ret" -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) +n=$((n+1)) +echo_i "testing incremented versions ($n)" +ret=0 +copy_setports ns1/named.incconf.in ns1/named.conf +try=0 +while test $try -lt 12 +do + touch ns1/named_inc.$try + try=`expr $try + 1` +done +rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n +_found2() ( + $DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n + grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1 + + try=1 + while test $try -lt 12 + do + [ -f ns1/named_inc.$try ] && return 1 + try=`expr $try + 1` + done + set -- ns1/named_inc.* + [ "$#" -eq 1 ] || return 1 +) +retry_quiet 5 _found2 || ret=1 +if [ "$ret" -ne 0 ]; then echo_i "failed"; fi +status=$((status+ret)) + n=$((n+1)) echo_i "testing unlimited versions ($n)" ret=0