]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Implement a convenience function for "rndc dumpdb"
authorMichał Kępień <michal@isc.org>
Thu, 8 Aug 2019 12:27:55 +0000 (14:27 +0200)
committerMichał Kępień <michal@isc.org>
Thu, 8 Aug 2019 13:12:12 +0000 (15:12 +0200)
Add a helper shell function, rndc_dumpdb(), which provides a convenient
way to call "rndc dumpdb" for a given server with optional additional
arguments.  Since database dumping is an asynchronous process, the
function waits until the dump is complete before returning, which
prevents false positives in system tests caused by inspecting the dump
before its preparation is finished.  The function also renames the dump
file before returning so that it does not get overwritten by subsequent
calls; this retains forensic data in case of an unexpected test failure.

(cherry picked from commit ab78e350ddfcd7e88c529f3be393245fc709be2d)

bin/tests/system/conf.sh.in
bin/tests/system/conf.sh.win32

index 65c0c5a19b05fcb1682ce056d9003ea2b547d2aa..cedabbee8c1d13f7e28c54eb768076b48aa6be86 100644 (file)
@@ -346,6 +346,48 @@ nextpart () {
         END          { print NR > "/dev/stderr" }' $1 2> $1.prev
 }
 
+# rndc_dumpdb: call "rndc dumpdb [...]" and wait until it completes
+#
+# The first argument is the name server instance to send the command to, in the
+# form of "nsX" (where "X" is the instance number), e.g. "ns5".  The remaining
+# arguments, if any, are appended to the rndc command line after "dumpdb".
+#
+# Control channel configuration for the name server instance to send the
+# command to must match the contents of bin/tests/system/common/rndc.conf.
+#
+# rndc output is stored in a file called rndc.out.test${n}; the "n" variable is
+# required to be set by the calling tests.sh script.
+#
+# Return 0 if the dump completes successfully; return 1 if rndc returns an exit
+# code other than 0 or if the "; Dump complete" string does not appear in the
+# dump within 10 seconds.
+rndc_dumpdb() {
+       __ret=0
+       __dump_complete=0
+       __server="${1}"
+       __ip="10.53.0.`echo "${__server}" | tr -c -d "0-9"`"
+
+       shift
+       ${RNDC} -c ../common/rndc.conf -p "${CONTROLPORT}" -s "${__ip}" dumpdb "$@" > "rndc.out.test${n}" 2>&1 || __ret=1
+
+       for _ in 0 1 2 3 4 5 6 7 8 9
+       do
+               if grep '^; Dump complete$' "${__server}/named_dump.db" > /dev/null; then
+                       mv "${__server}/named_dump.db" "${__server}/named_dump.db.test${n}"
+                       __dump_complete=1
+                       break
+               fi
+               sleep 1
+       done
+
+       if [ ${__dump_complete} -eq 0 ]; then
+               echo_i "timed out waiting for 'rndc dumpdb' to finish"
+               __ret=1
+       fi
+
+       return ${__ret}
+}
+
 # copy_setports - Copy Configuration File and Replace Ports
 #
 # Convenience function to copy a configuration file, replacing the tokens
index 99c6634cfa47017c64a868f9f4824eab028a3359..6e062ea92643a04e0237c071609d1ac212ed99e7 100644 (file)
@@ -318,6 +318,48 @@ nextpart () {
         END          { print NR > "/dev/stderr" }' $1 2> $1.prev
 }
 
+# rndc_dumpdb: call "rndc dumpdb [...]" and wait until it completes
+#
+# The first argument is the name server instance to send the command to, in the
+# form of "nsX" (where "X" is the instance number), e.g. "ns5".  The remaining
+# arguments, if any, are appended to the rndc command line after "dumpdb".
+#
+# Control channel configuration for the name server instance to send the
+# command to must match the contents of bin/tests/system/common/rndc.conf.
+#
+# rndc output is stored in a file called rndc.out.test${n}; the "n" variable is
+# required to be set by the calling tests.sh script.
+#
+# Return 0 if the dump completes successfully; return 1 if rndc returns an exit
+# code other than 0 or if the "; Dump complete" string does not appear in the
+# dump within 10 seconds.
+rndc_dumpdb() {
+       __ret=0
+       __dump_complete=0
+       __server="${1}"
+       __ip="10.53.0.`echo "${__server}" | tr -c -d "0-9"`"
+
+       shift
+       ${RNDC} -c ../common/rndc.conf -p "${CONTROLPORT}" -s "${__ip}" dumpdb "$@" > "rndc.out.test${n}" 2>&1 || __ret=1
+
+       for _ in 0 1 2 3 4 5 6 7 8 9
+       do
+               if grep '^; Dump complete$' "${__server}/named_dump.db" > /dev/null; then
+                       mv "${__server}/named_dump.db" "${__server}/named_dump.db.test${n}"
+                       __dump_complete=1
+                       break
+               fi
+               sleep 1
+       done
+
+       if [ ${__dump_complete} -eq 0 ]; then
+               echo_i "timed out waiting for 'rndc dumpdb' to finish"
+               __ret=1
+       fi
+
+       return ${__ret}
+}
+
 # copy_setports - Copy Configuration File and Replace Ports
 #
 # Convenience function to copy a configuration file, replacing the tokens