diff --git a/CHANGES b/CHANGES index 9a0c10c10c..b86af344cb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4161. [test] Test for consistency between "rndc stats" and the + XML and JSON statistics channel contents. [RT #38700] + 4159. [cleanup] Alphabetize dig's help output. [RT #39966] 4157. [protocol] Update experimental SIT code to use the EDNS COOKIE diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in index 5d945bf432..c31bde244f 100644 --- a/bin/tests/system/conf.sh.in +++ b/bin/tests/system/conf.sh.in @@ -74,8 +74,9 @@ SUBDIRS="acl additional allow_query addzone autosign builtin legacy limits logfileconfig lwresd masterfile masterformat metadata notify nslookup nsupdate pending @PKCS11_TEST@ reclimit redirect resolver rndc rpz rpzrecurse - rrl rrchecker rrsetorder rsabigexponent sit smartsign - sortlist spf staticstub statistics stub tkey tsig tsiggss + rrl rrchecker rrsetorder rsabigexponent + sit smartsign sortlist spf staticstub statistics statschannel stub + tkey tsig tsiggss unknown upforwd verify views wildcard xfer xferquota zero zonechecks" diff --git a/bin/tests/system/statschannel/clean.sh b/bin/tests/system/statschannel/clean.sh new file mode 100644 index 0000000000..c36776f7a3 --- /dev/null +++ b/bin/tests/system/statschannel/clean.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +rm -f traffic traffic.out.* +rm -f dig.out* +rm -f */named.memstats +rm -f */named.run +rm -f ns*/named.lock +rm -f ns*/named.stats +rm -f xml.*stats json.*stats diff --git a/bin/tests/system/statschannel/fetch.pl b/bin/tests/system/statschannel/fetch.pl new file mode 100644 index 0000000000..db420b1c45 --- /dev/null +++ b/bin/tests/system/statschannel/fetch.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +# +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +# fetch.pl: +# Simple script to fetch HTTP content from the statistics channel +# of a BIND server. Fetches the full XML stats from 10.53.0.2 port +# 8853 by default; these can be overridden by command line arguments. + +use File::Fetch; +use Getopt::Std; + +sub usage { + print ("Usage: fetch.pl [-s address] [-p port] [path]\n"); + exit 1; +} + +my %options={}; +getopts("s:p:", \%options); + +my $addr = "10.53.0.2"; +$addr = $options{a} if defined $options{a}; + +my $path = 'xml/v3'; +if (@ARGV >= 1) { + $path = shift @ARGV; +} + +my $port = 8853; +$port = $options{p} if defined $options{p}; + +my $ff = File::Fetch->new(uri => "http://$addr:$port/$path"); +my $file = $ff->fetch() or die $ff->error; +print ("$file\n"); diff --git a/bin/tests/system/statschannel/ns2/example.db b/bin/tests/system/statschannel/ns2/example.db new file mode 100644 index 0000000000..0d2c052abb --- /dev/null +++ b/bin/tests/system/statschannel/ns2/example.db @@ -0,0 +1,52 @@ +; Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +; +; Permission to use, copy, modify, and/or distribute this software for any +; purpose with or without fee is hereby granted, provided that the above +; copyright notice and this permission notice appear in all copies. +; +; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +; AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +; PERFORMANCE OF THIS SOFTWARE. + +$ORIGIN . +$TTL 300 ; 5 minutes +example IN SOA mname1. . ( + 1 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) +example. NS ns2.example. +ns2.example. A 10.53.0.2 + +$ORIGIN example. +a A 10.0.0.1 + MX 10 mail.example. +short TXT "short text" +long TXT ( + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + ) + +mail A 10.0.0.2 diff --git a/bin/tests/system/statschannel/ns2/named.conf b/bin/tests/system/statschannel/ns2/named.conf new file mode 100644 index 0000000000..60912738de --- /dev/null +++ b/bin/tests/system/statschannel/ns2/named.conf @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +controls { /* empty */ }; + +options { + query-source address 10.53.0.2; + notify-source 10.53.0.2; + transfer-source 10.53.0.2; + port 5300; + pid-file "named.pid"; + listen-on { 10.53.0.2; }; + listen-on-v6 { none; }; + recursion no; + notify yes; +}; + +statistics-channels { inet 10.53.0.2 port 8853 allow { localhost; }; }; + +include "../../common/controls.conf"; + +zone "example" { + type master; + file "example.db"; + allow-transfer { any; }; +}; diff --git a/bin/tests/system/statschannel/prereq.sh b/bin/tests/system/statschannel/prereq.sh new file mode 100644 index 0000000000..ef6efe476d --- /dev/null +++ b/bin/tests/system/statschannel/prereq.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +fail=0 + +if $PERL -e 'use File::Fetch;' 2>/dev/null +then + : +else + echo "I:This test requires the File::Fetch library." >&2 + fail=1 +fi + +exit $fail diff --git a/bin/tests/system/statschannel/server-json.pl b/bin/tests/system/statschannel/server-json.pl new file mode 100644 index 0000000000..4c81edea1a --- /dev/null +++ b/bin/tests/system/statschannel/server-json.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +# +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +# server-json.pl: +# Parses the JSON version of the server stats into a normalized format. + +use JSON; + +open(INPUT, "}; +close(INPUT); + +my $ref = decode_json($text); +foreach $key (keys $ref->{opcodes}) { + print "opcode " . $key . ": " . $ref->{opcodes}->{$key} . "\n"; +} +foreach $key (keys $ref->{qtypes}) { + print "qtype " . $key . ": " . $ref->{qtypes}->{$key} . "\n"; +} +foreach $key (keys $ref->{nsstats}) { + print "nsstat " . $key . ": " . $ref->{nsstats}->{$key} . "\n"; +} diff --git a/bin/tests/system/statschannel/server-xml.pl b/bin/tests/system/statschannel/server-xml.pl new file mode 100644 index 0000000000..4887fc6611 --- /dev/null +++ b/bin/tests/system/statschannel/server-xml.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl +# +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +# server-xml.pl: +# Parses the XML version of the server stats into a normalized format. + +use XML::Simple; + +my $ref = XMLin("xml.stats"); +my $counters = $ref->{server}->{counters}; +foreach $group (@$counters) { + foreach $key (keys $group->{counter}) { + print $group->{type} . " " . $key . ": ". $group->{counter}->{$key}->{content} . "\n"; + } +} diff --git a/bin/tests/system/statschannel/tests.sh b/bin/tests/system/statschannel/tests.sh new file mode 100644 index 0000000000..b4eaed074b --- /dev/null +++ b/bin/tests/system/statschannel/tests.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +SYSTEMTESTTOP=.. +. $SYSTEMTESTTOP/conf.sh + +DIGCMD="$DIG @10.53.0.2 -p 5300" + +if $PERL -e 'use JSON;' 2>/dev/null +then + PERL_JSON=1 +else + unset PERL_JSON + echo "I:JSON tests require JSON library; skipping" >&2 +fi + +if $PERL -e 'XML::Simple;' 2>/dev/null +then + PERL_XML=1 +else + unset PERL_XML + echo "I:XML tests require XML::Simple; skipping" >&2 +fi + +if [ ! $PERL_JSON -a ! $PERL_XML ]; then + echo "I:skipping all tests" + exit 0 +fi + +status=0 +n=1 + +ret=0 +echo "I:checking consistency between named.stats and xml/json ($n)" +rm -f ns2/named.stats +$DIGCMD +tcp example ns > dig.out.$n || ret=1 +$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 stats 2>&1 | sed 's/^/I:ns1 /' +query_count=`awk '/QUERY/ {print $1}' ns2/named.stats` +txt_count=`awk '/TXT/ {print $1}' ns2/named.stats` +if [ $PERL_XML ]; then + file=`$PERL fetch.pl xml/v3/server` + mv $file xml.stats + $PERL server-xml.pl > xml.fmtstats 2> /dev/null + xml_query_count=`awk '/opcode QUERY/ { print $NF }' xml.fmtstats` + [ "$query_count" -eq "$xml_query_count" ] || ret=1 + xml_txt_count=`awk '/qtype TXT/ { print $NF }' xml.fmtstats` + [ "$txt_count" -eq "$xml_txt_count" ] || ret=1 +fi +if [ $PERL_JSON ]; then + file=`$PERL fetch.pl json/v1/server` + mv $file json.stats + $PERL server-xml.pl > json.fmtstats 2> /dev/null + json_query_count=`awk '/opcode QUERY/ { print $NF }' json.fmtstats` + [ "$query_count" -eq "$json_query_count" ] || ret=1 + json_txt_count=`awk '/qtype TXT/ { print $NF }' json.fmtstats` + [ "$txt_count" -eq "$json_txt_count" ] || ret=1 +fi +if [ $ret != 0 ]; then echo "I: failed"; fi +status=`expr $status + $ret` +n=`expr $n + 1` + +echo "I:exit status: $status" +exit $status