]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix transfer statistics extraction
authorMichał Kępień <michal@isc.org>
Tue, 18 Jun 2019 06:51:50 +0000 (08:51 +0200)
committerMichał Kępień <michal@isc.org>
Tue, 18 Jun 2019 06:53:35 +0000 (08:53 +0200)
Make the get_named_xfer_stats() helper shell function more precise in
order to prevent it from matching the wrong lines as that may trigger
false positives for the "ixfr" and "xfer" system tests.  As an example,
the regular expression responsible for extracting the number of bytes
transmitted throughout an entire zone transfer could also match a line
containing the following string:

    transfer of '<zone-name>/IN': sending TCP message of <integer> bytes

However, such a line is not one summarizing a zone transfer.

Also simplify both get_dig_xfer_stats() and get_named_xfer_stats() by
eliminating the need for "echo" statements in them.

(cherry picked from commit fab67c074a8df8c0996c858629e9b23dff35417c)

bin/tests/system/conf.sh.common

index c18d5272e29a7998db998add11ae9734c9f75ac8..460a831bcb7bb373c2fcf4d6c4ea883dd5f52ca1 100644 (file)
@@ -337,21 +337,26 @@ rndc_reconfig() {
 # in $1, converting them to a format used by some system tests.
 get_dig_xfer_stats() {
        LOGFILE="$1"
-       echo "messages=`sed -n "s/^;; XFR size: .*messages \([0-9][0-9]*\).*/\1/p" "${LOGFILE}"`"
-       echo "records=`sed -n "s/^;; XFR size: \([0-9][0-9]*\) records.*/\1/p" "${LOGFILE}"`"
-       echo "bytes=`sed -n "s/^;; XFR size: .*bytes \([0-9][0-9]*\).*/\1/p" "${LOGFILE}"`"
+       sed -n "s/^;; XFR size: .*messages \([0-9][0-9]*\).*/messages=\1/p" "${LOGFILE}"
+       sed -n "s/^;; XFR size: \([0-9][0-9]*\) records.*/records=\1/p" "${LOGFILE}"
+       sed -n "s/^;; XFR size: .*bytes \([0-9][0-9]*\).*/bytes=\1/p" "${LOGFILE}"
 }
 
 # get_named_xfer_stats: from named log file $1, extract transfer
-# statistics for the last transfer for peer $2 and zone $3, converting
+# statistics for the last transfer for peer $2 and zone $3 (from a log
+# message which has to contain the string provided in $4), converting
 # them to a format used by some system tests.
 get_named_xfer_stats() {
        LOGFILE="$1"
-       PEER="$2"
-       ZONE="$3"
-       echo "messages=`grep "${PEER}" "${LOGFILE}" | sed -n "s/.*${ZONE}.* \([0-9][0-9]*\) messages.*/\1/p" | tail -1`"
-       echo "records=`grep "${PEER}" "${LOGFILE}" | sed -n "s/.*${ZONE}.* \([0-9][0-9]*\) records.*/\1/p" | tail -1`"
-       echo "bytes=`grep "${PEER}" "${LOGFILE}" | sed -n "s/.*${ZONE}.* \([0-9][0-9]*\) bytes.*/\1/p" | tail -1`"
+       PEER="`echo $2 | sed 's/\./\\\\./g'`"
+       ZONE="`echo $3 | sed 's/\./\\\\./g'`"
+       MESSAGE="$4"
+       grep " ${PEER}#.*${MESSAGE}:" "${LOGFILE}" | \
+               sed -n "s/.* '${ZONE}\/.* \([0-9][0-9]*\) messages.*/messages=\1/p" | tail -1
+       grep " ${PEER}#.*${MESSAGE}:" "${LOGFILE}" | \
+               sed -n "s/.* '${ZONE}\/.* \([0-9][0-9]*\) records.*/records=\1/p" | tail -1
+       grep " ${PEER}#.*${MESSAGE}:" "${LOGFILE}" | \
+               sed -n "s/.* '${ZONE}\/.* \([0-9][0-9]*\) bytes.*/bytes=\1/p" | tail -1
 }
 
 # copy_setports - Copy Configuration File and Replace Ports