dhcp6_process_tests.sh.in 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. #
  3. # Permission to use, copy, modify, and/or distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. # PERFORMANCE OF THIS SOFTWARE.
  14. # Path to the temporary configuration file.
  15. CFG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test_config.json
  16. # Path to the Kea log file.
  17. LOG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test.log
  18. # Kea configuration to be stored in the configuration file.
  19. CONFIG="{
  20. \"Dhcp6\":
  21. {
  22. \"interfaces\": [ ],
  23. \"preferred-lifetime\": 3000,
  24. \"valid-lifetime\": 4000,
  25. \"renew-timer\": 1000,
  26. \"rebind-timer\": 2000,
  27. \"lease-database\":
  28. {
  29. \"type\": \"memfile\",
  30. \"persist\": false
  31. },
  32. \"subnet6\": [
  33. {
  34. \"subnet\": \"2001:db8:1::/64\",
  35. \"pool\": [ \"2001:db8:1::10-2001:db8:1::100\" ]
  36. } ]
  37. },
  38. \"Logging\":
  39. {
  40. \"loggers\": [
  41. {
  42. \"name\": \"kea-dhcp6\",
  43. \"output_options\": [
  44. {
  45. \"output\": \"$LOG_FILE\"
  46. }
  47. ],
  48. \"severity\": \"INFO\"
  49. }
  50. ]
  51. }
  52. }"
  53. # Invalid configuration (negative preferred-lifetime) to check that Kea
  54. # gracefully handles reconfiguration errors.
  55. CONFIG_INVALID="{
  56. \"Dhcp6\":
  57. {
  58. \"interfaces\": [ ],
  59. \"preferred-lifetime\": -3,
  60. \"valid-lifetime\": 4000,
  61. \"renew-timer\": 1000,
  62. \"rebind-timer\": 2000,
  63. \"lease-database\":
  64. {
  65. \"type\": \"memfile\",
  66. \"persist\": false
  67. },
  68. \"subnet6\": [
  69. {
  70. \"subnet\": \"2001:db8:1::/64\",
  71. \"pool\": [ \"2001:db8:1::10-2001:db8:1::100\" ]
  72. } ]
  73. },
  74. \"Logging\":
  75. {
  76. \"loggers\": [
  77. {
  78. \"name\": \"kea-dhcp6\",
  79. \"output_options\": [
  80. {
  81. \"output\": \"$LOG_FILE\"
  82. }
  83. ],
  84. \"severity\": \"INFO\"
  85. }
  86. ]
  87. }
  88. }"
  89. # Set the location of the executable.
  90. bin="kea-dhcp6"
  91. bin_path=@abs_top_builddir@/src/bin/dhcp6
  92. # Import common test library.
  93. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
  94. # This test verifies that DHCPv6 can be reconfigured with a SIGHUP signal.
  95. dynamic_reconfiguration_test() {
  96. # Log the start of the test and print test name.
  97. test_start "dhcpv6_srv.dynamic_reconfiguration"
  98. # Remove dangling Kea instances and remove log files.
  99. cleanup
  100. # Create new configuration file.
  101. create_config "${CONFIG}"
  102. # Instruct Kea to log to the specific file.
  103. set_logger
  104. # Start Kea.
  105. start_kea ${bin_path}/${bin}
  106. # Wait up to 20s for Kea to start.
  107. wait_for_kea 20
  108. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  109. printf "ERROR: timeout waiting for Kea to start.\n"
  110. clean_exit 1
  111. fi
  112. # Check if it is still running. It could have terminated (e.g. as a result
  113. # of configuration failure).
  114. get_pids ${bin}
  115. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  116. printf "ERROR: expected one Kea process to be started. Found %d processes\
  117. started.\n" ${_GET_PIDS_NUM}
  118. clean_exit 1
  119. fi
  120. # Check in the log file, how many times server has been configured. It should
  121. # be just once on startup.
  122. get_reconfigs
  123. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  124. printf "ERROR: server hasn't been configured.\n"
  125. clean_exit 1
  126. else
  127. printf "Server successfully configured.\n"
  128. fi
  129. # Now use invalid configuration.
  130. create_config "${CONFIG_INVALID}"
  131. # Try to reconfigure by sending SIGHUP
  132. send_signal 1 ${bin}
  133. # The configuration should fail and the error message should be there.
  134. wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
  135. # After receiving SIGHUP the server should try to reconfigure itself.
  136. # The configuration provided is invalid so it should result in
  137. # reconfiguration failure but the server should still be running.
  138. get_reconfigs
  139. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  140. printf "ERROR: server has been reconfigured despite bogus configuration.\n"
  141. clean_exit 1
  142. elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
  143. printf "ERROR: server did not report reconfiguration error despite attempt\
  144. to configure it with invalid configuration.\n"
  145. clean_exit 1
  146. fi
  147. # Make sure the server is still operational.
  148. get_pids ${bin}
  149. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  150. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  151. clean_exit 1
  152. fi
  153. # Restore the good configuration.
  154. create_config "${CONFIG}"
  155. # Reconfigure the server with SIGHUP.
  156. send_signal 1 ${bin}
  157. # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
  158. # Wait for it up to 10s.
  159. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  160. # After receiving SIGHUP the server should get reconfigured and the
  161. # reconfiguration should be noted in the log file. We should now
  162. # have two configurations logged in the log file.
  163. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  164. printf "ERROR: server hasn't been reconfigured.\n"
  165. clean_exit 1
  166. else
  167. printf "Server successfully reconfigured.\n"
  168. fi
  169. # Make sure the server is still operational.
  170. get_pids ${bin}
  171. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  172. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  173. clean_exit 1
  174. fi
  175. # All ok. Shut down Kea and exit.
  176. test_finish 0
  177. }
  178. # This test verifies that DHCPv6 server is shut down gracefully when it
  179. # receives a SIGINT or SIGTERM signal.
  180. shutdown_test() {
  181. test_name=${1} # Test name
  182. signum=${2} # Signal number
  183. # Log the start of the test and print test name.
  184. test_start ${test_name}
  185. # Remove dangling Kea instances and remove log files.
  186. cleanup
  187. # Create new configuration file.
  188. create_config "${CONFIG}"
  189. # Instruct Kea to log to the specific file.
  190. set_logger
  191. # Start Kea.
  192. start_kea ${bin_path}/${bin}
  193. # Wait up to 20s for Kea to start.
  194. wait_for_kea 20
  195. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  196. printf "ERROR: timeout waiting for Kea to start.\n"
  197. clean_exit 1
  198. fi
  199. # Check if it is still running. It could have terminated (e.g. as a result
  200. # of configuration failure).
  201. get_pids ${bin}
  202. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  203. printf "ERROR: expected one Kea process to be started. Found %d processes\
  204. started.\n" ${_GET_PIDS_NUM}
  205. clean_exit 1
  206. fi
  207. # Check in the log file, how many times server has been configured. It should
  208. # be just once on startup.
  209. get_reconfigs
  210. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  211. printf "ERROR: server hasn't been configured.\n"
  212. clean_exit 1
  213. else
  214. printf "Server successfully configured.\n"
  215. fi
  216. # Send signal to Kea (SIGTERM, SIGINT etc.)
  217. send_signal ${signum} ${bin}
  218. # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  219. # should be recorded in the log file with the appropriate message.
  220. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  221. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  222. printf "ERROR: Server did not record shutdown in the log.\n"
  223. clean_exit 1
  224. fi
  225. # Make sure the server is down.
  226. wait_for_server_down 5 ${bin}
  227. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  228. "Expected wait_for_server_down return %d, returned %d"
  229. test_finish 0
  230. }
  231. dynamic_reconfiguration_test
  232. shutdown_test "dhcpv4.sigterm_test" 15
  233. shutdown_test "dhcpv4.sigint_test" 2