d2_process_tests.sh.in 7.3 KB

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