tests.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  4. #
  5. # Permission to use, copy, modify, and/or distribute this software for any
  6. # purpose with or without fee is hereby granted, provided that the above
  7. # copyright notice and this permission notice appear in all copies.
  8. #
  9. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. # PERFORMANCE OF THIS SOFTWARE.
  16. SYSTEMTESTTOP=..
  17. . $SYSTEMTESTTOP/conf.sh
  18. #
  19. # Do bindctl tests.
  20. #
  21. status=0
  22. n=0
  23. # TODO: consider consistency with statistics definition in auth.spec
  24. # flatten JSON
  25. awk_flatten_json='
  26. function join(ary, len) {
  27. ret = "";
  28. for (i = 1; i <= len; ++i) {
  29. ret = ret""ary[i];
  30. }
  31. return ret;
  32. }
  33. BEGIN {
  34. depth = 0;
  35. }
  36. /.+{$/ {
  37. label[++depth] = $1;
  38. next;
  39. }
  40. /},?/ {
  41. --depth;
  42. next;
  43. }
  44. /:/ {
  45. print join(label,depth)""$1" "$2;
  46. }
  47. '
  48. # Check the counters have expected values given with 1st argument.
  49. # This function tests only these counters will be incremented in every checks
  50. # since the content of datasource and requests are not changed in this test.
  51. test_counters () {
  52. status=0
  53. $AWK "$awk_flatten_json" bindctl.out.$n | \
  54. grep '"Auth":"zones":"_SERVER_":"request":"v4": '$1 > \
  55. /dev/null || status=1
  56. $AWK "$awk_flatten_json" bindctl.out.$n | \
  57. grep '"Auth":"zones":"_SERVER_":"request":"v6": '0 > \
  58. /dev/null || status=1
  59. $AWK "$awk_flatten_json" bindctl.out.$n | \
  60. grep '"Auth":"zones":"_SERVER_":"request":"udp": '$1 > \
  61. /dev/null || status=1
  62. $AWK "$awk_flatten_json" bindctl.out.$n | \
  63. grep '"Auth":"zones":"_SERVER_":"request":"tcp": '0 > \
  64. /dev/null || status=1
  65. $AWK "$awk_flatten_json" bindctl.out.$n | \
  66. grep '"Auth":"zones":"_SERVER_":"opcode":"query": '$1 > \
  67. /dev/null || status=1
  68. $AWK "$awk_flatten_json" bindctl.out.$n | \
  69. grep '"Auth":"zones":"_SERVER_":"responses": '$1 > \
  70. /dev/null || status=1
  71. $AWK "$awk_flatten_json" bindctl.out.$n | \
  72. grep '"Auth":"zones":"_SERVER_":"rcode":"noerror": '$1 > \
  73. /dev/null || status=1
  74. $AWK "$awk_flatten_json" bindctl.out.$n | \
  75. grep '"Auth":"zones":"_SERVER_":"qrysuccess": '$1 > \
  76. /dev/null || status=1
  77. $AWK "$awk_flatten_json" bindctl.out.$n | \
  78. grep '"Auth":"zones":"_SERVER_":"qryauthans": '$1 > \
  79. /dev/null || status=1
  80. return $status
  81. }
  82. expected_count=0
  83. echo "I:Checking b10-auth is disabled by default ($n)"
  84. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A > /dev/null && status=1
  85. if [ $status != 0 ]; then echo "I:failed"; fi
  86. n=`expr $n + 1`
  87. echo "I:Starting b10-auth and checking that it works ($n)"
  88. echo 'config add Boss/components b10-auth
  89. config set Boss/components/b10-auth { "special": "auth", "kind": "needed" }
  90. config commit
  91. quit
  92. ' | $RUN_BINDCTL \
  93. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  94. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  95. # perform a simple check on the output (digcomp would be too much for this)
  96. grep 192.0.2.1 dig.out.$n > /dev/null || status=1
  97. if [ $status != 0 ]; then echo "I:failed"; fi
  98. n=`expr $n + 1`
  99. echo "I:Checking BIND 10 statistics after a pause ($n)"
  100. # wait for 2sec to make sure b10-stats gets the latest statistics.
  101. sleep 2
  102. echo 'Stats show
  103. ' | $RUN_BINDCTL \
  104. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  105. # the server should have received 1 request
  106. expected_count=`expr $expected_count + 1`
  107. test_counters $expected_count
  108. if [ $? != 0 ]; then echo "I:failed"; fi
  109. n=`expr $n + 1`
  110. echo "I:Stopping b10-auth and checking that ($n)"
  111. echo 'config remove Boss/components b10-auth
  112. config commit
  113. quit
  114. ' | $RUN_BINDCTL \
  115. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  116. # dig should exit with a failure code.
  117. $DIG +tcp +norec @10.53.0.1 -p 53210 ns.example.com. A > /dev/null && status=1
  118. if [ $status != 0 ]; then echo "I:failed"; fi
  119. n=`expr $n + 1`
  120. echo "I:Restarting b10-auth and checking that ($n)"
  121. echo 'config add Boss/components b10-auth
  122. config set Boss/components/b10-auth { "special": "auth", "kind": "needed" }
  123. config commit
  124. quit
  125. ' | $RUN_BINDCTL \
  126. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  127. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  128. # perform a simple check on the output (digcomp would be too much for this)
  129. grep 192.0.2.1 dig.out.$n > /dev/null || status=1
  130. if [ $status != 0 ]; then echo "I:failed"; fi
  131. n=`expr $n + 1`
  132. echo "I:Rechecking BIND 10 statistics after a pause ($n)"
  133. sleep 2
  134. echo 'Stats show
  135. ' | $RUN_BINDCTL \
  136. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  137. # The statistics counters can not be reset even after auth
  138. # restarts. Because stats preserves the query counts which the dying
  139. # auth sent. Then it cumulates them and new counts which the living
  140. # auth sends. This note assumes that the issue would have been
  141. # resolved : "#1941 stats lossage (multiple auth servers)".
  142. expected_count=`expr $expected_count + 1`
  143. test_counters $expected_count
  144. if [ $? != 0 ]; then echo "I:failed"; fi
  145. n=`expr $n + 1`
  146. echo "I:Changing the data source from sqlite3 to in-memory ($n)"
  147. DATASRC_SPEC='{"type": "MasterFiles", "cache-enable": true, "params": {"com":'
  148. DATASRC_SPEC="${DATASRC_SPEC} \"${TEST_TOP}/bindctl/nsx1/example-normalized.db\"}}"
  149. echo "config set data_sources/classes/IN[0] ${DATASRC_SPEC}
  150. config commit
  151. quit
  152. " | $RUN_BINDCTL \
  153. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  154. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  155. grep 192.0.2.2 dig.out.$n > /dev/null || status=1
  156. if [ $status != 0 ]; then echo "I:failed"; fi
  157. n=`expr $n + 1`
  158. echo "I:Rechecking BIND 10 statistics after changing the datasource ($n)"
  159. sleep 2
  160. echo 'Stats show
  161. ' | $RUN_BINDCTL \
  162. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  163. # The statistics counters shouldn't be reset due to hot-swapping datasource.
  164. expected_count=`expr $expected_count + 1`
  165. test_counters $expected_count
  166. if [ $? != 0 ]; then echo "I:failed"; fi
  167. n=`expr $n + 1`
  168. echo "I:Starting more b10-auths and checking that ($n)"
  169. for i in 2 3
  170. do
  171. echo 'config add Boss/components b10-auth-'$i'
  172. config set Boss/components/b10-auth-'$i' { "special": "auth", "kind": "needed" }
  173. config commit
  174. quit
  175. ' | $RUN_BINDCTL \
  176. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  177. done
  178. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  179. grep 192.0.2.2 dig.out.$n > /dev/null || status=1
  180. if [ $status != 0 ]; then echo "I:failed"; fi
  181. n=`expr $n + 1`
  182. echo "I:Rechecking BIND 10 statistics consistency after a pause ($n)"
  183. sleep 2
  184. expected_count=`expr $expected_count + 1`
  185. # Rechecking some times
  186. for i in 1 2 3 4
  187. do
  188. echo 'Stats show
  189. ' | $RUN_BINDCTL \
  190. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  191. # The statistics counters should keep being consistent even while
  192. # multiple b10-auths are running.
  193. test_counters $expected_count
  194. if [ $? != 0 ]; then echo "I:failed "; break ; fi
  195. done
  196. n=`expr $n + 1`
  197. echo "I:Stopping extra b10-auths and checking that ($n)"
  198. for i in 3 2
  199. do
  200. echo 'config remove Boss/components b10-auth-'$i'
  201. config commit
  202. quit
  203. ' | $RUN_BINDCTL \
  204. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  205. done
  206. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  207. grep 192.0.2.2 dig.out.$n > /dev/null || status=1
  208. if [ $status != 0 ]; then echo "I:failed"; fi
  209. n=`expr $n + 1`
  210. # The statistics counters can not be rechecked here because the auth
  211. # instance seems to hang up after one of the multiple auth instances
  212. # was removed via bindctl. This reason seems to be the same reason as
  213. # #1703.
  214. echo "I:exit status: $status"
  215. exit $status