tests.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 Init/components b10-auth
  89. config set Init/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 Init/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 Init/components b10-auth
  122. config set Init/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. sleep 2
  128. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  129. # perform a simple check on the output (digcomp would be too much for this)
  130. grep 192.0.2.1 dig.out.$n > /dev/null || status=1
  131. if [ $status != 0 ]; then echo "I:failed"; fi
  132. n=`expr $n + 1`
  133. echo "I:Rechecking BIND 10 statistics after a pause ($n)"
  134. sleep 2
  135. echo 'Stats show
  136. ' | $RUN_BINDCTL \
  137. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  138. # The statistics counters can not be reset even after auth
  139. # restarts. Because stats preserves the query counts which the dying
  140. # auth sent. Then it cumulates them and new counts which the living
  141. # auth sends. This note assumes that the issue would have been
  142. # resolved : "#1941 stats lossage (multiple auth servers)".
  143. expected_count=`expr $expected_count + 1`
  144. test_counters $expected_count
  145. if [ $? != 0 ]; then echo "I:failed"; fi
  146. n=`expr $n + 1`
  147. echo "I:Changing the data source from sqlite3 to in-memory ($n)"
  148. DATASRC_SPEC='{"type": "MasterFiles", "cache-enable": true, "params": {"com":'
  149. DATASRC_SPEC="${DATASRC_SPEC} \"${TEST_TOP}/bindctl/nsx1/example-normalized.db\"}}"
  150. echo "config set data_sources/classes/IN[0] ${DATASRC_SPEC}
  151. config commit
  152. quit
  153. " | $RUN_BINDCTL \
  154. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  155. sleep 2
  156. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  157. grep 192.0.2.2 dig.out.$n > /dev/null || status=1
  158. if [ $status != 0 ]; then echo "I:failed"; fi
  159. n=`expr $n + 1`
  160. echo "I:Rechecking BIND 10 statistics after changing the datasource ($n)"
  161. sleep 2
  162. echo 'Stats show
  163. ' | $RUN_BINDCTL \
  164. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  165. # The statistics counters shouldn't be reset due to hot-swapping datasource.
  166. expected_count=`expr $expected_count + 1`
  167. test_counters $expected_count
  168. if [ $? != 0 ]; then echo "I:failed"; fi
  169. n=`expr $n + 1`
  170. echo "I:Starting more b10-auths and checking that ($n)"
  171. for i in 2 3
  172. do
  173. echo 'config add Init/components b10-auth-'$i'
  174. config set Init/components/b10-auth-'$i' { "special": "auth", "kind": "needed" }
  175. config commit
  176. quit
  177. ' | $RUN_BINDCTL \
  178. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  179. done
  180. sleep 2
  181. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  182. grep 192.0.2.2 dig.out.$n > /dev/null || status=1
  183. if [ $status != 0 ]; then echo "I:failed"; fi
  184. n=`expr $n + 1`
  185. echo "I:Rechecking BIND 10 statistics consistency after a pause ($n)"
  186. sleep 2
  187. expected_count=`expr $expected_count + 1`
  188. # Rechecking some times
  189. for i in 1 2 3 4
  190. do
  191. echo 'Stats show
  192. ' | $RUN_BINDCTL \
  193. --csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
  194. # The statistics counters should keep being consistent even while
  195. # multiple b10-auths are running.
  196. test_counters $expected_count
  197. if [ $? != 0 ]; then echo "I:failed "; break ; fi
  198. done
  199. n=`expr $n + 1`
  200. echo "I:Stopping extra b10-auths and checking that ($n)"
  201. for i in 3 2
  202. do
  203. echo 'config remove Init/components b10-auth-'$i'
  204. config commit
  205. quit
  206. ' | $RUN_BINDCTL \
  207. --csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
  208. done
  209. sleep 2
  210. $DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
  211. grep 192.0.2.2 dig.out.$n > /dev/null || status=1
  212. if [ $status != 0 ]; then echo "I:failed"; fi
  213. n=`expr $n + 1`
  214. # The statistics counters can not be rechecked here because the auth
  215. # instance seems to hang up after one of the multiple auth instances
  216. # was removed via bindctl. This reason seems to be the same reason as
  217. # #1703.
  218. echo "I:exit status: $status"
  219. exit $status