dhcp6_process_tests.sh.in 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. }"
  39. # Invalid configuration (negative preferred-lifetime) to check that Kea
  40. # gracefully handles reconfiguration errors.
  41. CONFIG_INVALID="{
  42. \"Dhcp6\":
  43. {
  44. \"interfaces\": [ ],
  45. \"preferred-lifetime\": -3,
  46. \"valid-lifetime\": 4000,
  47. \"renew-timer\": 1000,
  48. \"rebind-timer\": 2000,
  49. \"lease-database\":
  50. {
  51. \"type\": \"memfile\",
  52. \"persist\": false
  53. },
  54. \"subnet6\": [
  55. {
  56. \"subnet\": \"2001:db8:1::/64\",
  57. \"pool\": [ \"2001:db8:1::10-2001:db8:1::100\" ]
  58. } ]
  59. }
  60. }"
  61. # Set the location of the executable.
  62. bin="kea-dhcp6"
  63. bin_path=@abs_top_builddir@/src/bin/dhcp6
  64. # Import common test library.
  65. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
  66. # This test verifies that DHCPv6 can be reconfigured with a SIGHUP signal.
  67. dynamic_reconfiguration_test() {
  68. # Log the start of the test and print test name.
  69. test_start "dhcpv6_srv.dynamic_reconfiguration"
  70. # Remove dangling Kea instances and remove log files.
  71. cleanup
  72. # Create new configuration file.
  73. create_config "${CONFIG}"
  74. # Instruct Kea to log to the specific file.
  75. set_logger
  76. # Start Kea.
  77. start_kea ${bin_path}/${bin}
  78. # Wait up to 20s for Kea to start.
  79. wait_for_kea 20
  80. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  81. printf "ERROR: timeout waiting for Kea to start.\n"
  82. clean_exit 1
  83. fi
  84. # Check if it is still running. It could have terminated (e.g. as a result
  85. # of configuration failure).
  86. get_pids ${bin}
  87. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  88. printf "ERROR: expected one Kea process to be started. Found %d processes\
  89. started.\n" ${_GET_PIDS_NUM}
  90. clean_exit 1
  91. fi
  92. # Check in the log file, how many times server has been configured. It should
  93. # be just once on startup.
  94. get_reconfigs
  95. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  96. printf "ERROR: server hasn't been configured.\n"
  97. clean_exit 1
  98. else
  99. printf "Server successfully configured.\n"
  100. fi
  101. # Now use invalid configuration.
  102. create_config "${CONFIG_INVALID}"
  103. # Try to reconfigure by sending SIGHUP
  104. send_signal 1 ${bin}
  105. # The configuration should fail and the error message should be there.
  106. wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
  107. # After receiving SIGHUP the server should try to reconfigure itself.
  108. # The configuration provided is invalid so it should result in
  109. # reconfiguration failure but the server should still be running.
  110. get_reconfigs
  111. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  112. printf "ERROR: server has been reconfigured despite bogus configuration.\n"
  113. clean_exit 1
  114. elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
  115. printf "ERROR: server did not report reconfiguration error despite attempt\
  116. to configure it with invalid configuration.\n"
  117. clean_exit 1
  118. fi
  119. # Make sure the server is still operational.
  120. get_pids ${bin}
  121. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  122. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  123. clean_exit 1
  124. fi
  125. # Restore the good configuration.
  126. create_config "${CONFIG}"
  127. # Reconfigure the server with SIGHUP.
  128. send_signal 1 ${bin}
  129. # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
  130. # Wait for it up to 10s.
  131. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  132. # After receiving SIGHUP the server should get reconfigured and the
  133. # reconfiguration should be noted in the log file. We should now
  134. # have two configurations logged in the log file.
  135. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  136. printf "ERROR: server hasn't been reconfigured.\n"
  137. clean_exit 1
  138. else
  139. printf "Server successfully reconfigured.\n"
  140. fi
  141. # Make sure the server is still operational.
  142. get_pids ${bin}
  143. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  144. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  145. clean_exit 1
  146. fi
  147. # All ok. Shut down Kea and exit.
  148. test_finish 0
  149. }
  150. # This test verifies that DHCPv6 server is shut down gracefully when it
  151. # receives a SIGINT or SIGTERM signal.
  152. shutdown_test() {
  153. test_name=${1} # Test name
  154. signum=${2} # Signal number
  155. # Log the start of the test and print test name.
  156. test_start ${test_name}
  157. # Remove dangling Kea instances and remove log files.
  158. cleanup
  159. # Create new configuration file.
  160. create_config "${CONFIG}"
  161. # Instruct Kea to log to the specific file.
  162. set_logger
  163. # Start Kea.
  164. start_kea ${bin_path}/${bin}
  165. # Wait up to 20s for Kea to start.
  166. wait_for_kea 20
  167. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  168. printf "ERROR: timeout waiting for Kea to start.\n"
  169. clean_exit 1
  170. fi
  171. # Check if it is still running. It could have terminated (e.g. as a result
  172. # of configuration failure).
  173. get_pids ${bin}
  174. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  175. printf "ERROR: expected one Kea process to be started. Found %d processes\
  176. started.\n" ${_GET_PIDS_NUM}
  177. clean_exit 1
  178. fi
  179. # Check in the log file, how many times server has been configured. It should
  180. # be just once on startup.
  181. get_reconfigs
  182. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  183. printf "ERROR: server hasn't been configured.\n"
  184. clean_exit 1
  185. else
  186. printf "Server successfully configured.\n"
  187. fi
  188. # Send signal to Kea (SIGTERM, SIGINT etc.)
  189. send_signal ${signum} ${bin}
  190. # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  191. # should be recorded in the log file with the appropriate message.
  192. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  193. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  194. printf "ERROR: Server did not record shutdown in the log.\n"
  195. clean_exit 1
  196. fi
  197. # Make sure the server is down.
  198. wait_for_server_down 5 ${bin}
  199. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  200. "Expected wait_for_server_down return %d, returned %d"
  201. test_finish 0
  202. }
  203. dynamic_reconfiguration_test
  204. shutdown_test "dhcpv4.sigterm_test" 15
  205. shutdown_test "dhcpv4.sigint_test" 2