d2_process_tests.sh.in 7.3 KB

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