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