dhcp6_process_tests.sh.in 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. # Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
  2. #
  3. # This Source Code Form is subject to the terms of the Mozilla Public
  4. # License, v. 2.0. If a copy of the MPL was not distributed with this
  5. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. # Path to the temporary configuration file.
  7. CFG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test_config.json
  8. # Path to the Kea log file.
  9. LOG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test.log
  10. # Path to the Kea lease file.
  11. LEASE_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test_leases.csv
  12. # Expected version
  13. EXPECTED_VERSION="@PACKAGE_VERSION@"
  14. # Kea configuration to be stored in the configuration file.
  15. CONFIG="{
  16. \"Dhcp6\":
  17. { \"interfaces-config\": {
  18. \"interfaces\": [ ]
  19. },
  20. \"server-id\": {
  21. \"type\": \"LLT\",
  22. \"persist\": false
  23. },
  24. \"preferred-lifetime\": 3000,
  25. \"valid-lifetime\": 4000,
  26. \"renew-timer\": 1000,
  27. \"rebind-timer\": 2000,
  28. \"lease-database\":
  29. {
  30. \"type\": \"memfile\",
  31. \"name\": \"$LEASE_FILE\",
  32. \"persist\": false,
  33. \"lfc-interval\": 0
  34. },
  35. \"subnet6\": [
  36. {
  37. \"subnet\": \"2001:db8:1::/64\",
  38. \"pools\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
  39. } ],
  40. \"dhcp-ddns\": {
  41. \"enable-updates\": true,
  42. \"qualifying-suffix\": \"\"
  43. }
  44. },
  45. \"Logging\":
  46. {
  47. \"loggers\": [
  48. {
  49. \"name\": \"kea-dhcp6\",
  50. \"output_options\": [
  51. {
  52. \"output\": \"$LOG_FILE\"
  53. }
  54. ],
  55. \"severity\": \"INFO\"
  56. }
  57. ]
  58. }
  59. }"
  60. # Invalid configuration (negative preferred-lifetime) to check that Kea
  61. # gracefully handles reconfiguration errors.
  62. CONFIG_INVALID="{
  63. \"Dhcp6\":
  64. {
  65. \"interfaces\": [ ],
  66. \"preferred-lifetime\": -3,
  67. \"valid-lifetime\": 4000,
  68. \"renew-timer\": 1000,
  69. \"rebind-timer\": 2000,
  70. \"lease-database\":
  71. {
  72. \"type\": \"memfile\",
  73. \"persist\": false
  74. },
  75. \"subnet6\": [
  76. {
  77. \"subnet\": \"2001:db8:1::/64\",
  78. \"pool\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
  79. } ]
  80. },
  81. \"Logging\":
  82. {
  83. \"loggers\": [
  84. {
  85. \"name\": \"kea-dhcp6\",
  86. \"output_options\": [
  87. {
  88. \"output\": \"$LOG_FILE\"
  89. }
  90. ],
  91. \"severity\": \"INFO\"
  92. }
  93. ]
  94. }
  95. }"
  96. # Set the location of the executable.
  97. bin="kea-dhcp6"
  98. bin_path=@abs_top_builddir@/src/bin/dhcp6
  99. # Import common test library.
  100. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
  101. # This test verifies that DHCPv6 can be reconfigured with a SIGHUP signal.
  102. dynamic_reconfiguration_test() {
  103. # Log the start of the test and print test name.
  104. test_start "dhcpv6_srv.dynamic_reconfiguration"
  105. # Remove dangling Kea instances and remove log files.
  106. cleanup
  107. # Create new configuration file.
  108. create_config "${CONFIG}"
  109. # Instruct Kea to log to the specific file.
  110. set_logger
  111. # Start Kea.
  112. start_kea ${bin_path}/${bin}
  113. # Wait up to 20s for Kea to start.
  114. wait_for_kea 20
  115. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  116. printf "ERROR: timeout waiting for Kea to start.\n"
  117. clean_exit 1
  118. fi
  119. # Check if it is still running. It could have terminated (e.g. as a result
  120. # of configuration failure).
  121. get_pid ${bin}
  122. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  123. printf "ERROR: expected one Kea process to be started. Found %d processes\
  124. started.\n" ${_GET_PIDS_NUM}
  125. clean_exit 1
  126. fi
  127. # Check in the log file, how many times server has been configured. It should
  128. # be just once on startup.
  129. get_reconfigs
  130. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  131. printf "ERROR: server hasn't been configured.\n"
  132. clean_exit 1
  133. else
  134. printf "Server successfully configured.\n"
  135. fi
  136. # Now use invalid configuration.
  137. create_config "${CONFIG_INVALID}"
  138. # Try to reconfigure by sending SIGHUP
  139. send_signal 1 ${bin}
  140. # The configuration should fail and the error message should be there.
  141. wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
  142. # After receiving SIGHUP the server should try to reconfigure itself.
  143. # The configuration provided is invalid so it should result in
  144. # reconfiguration failure but the server should still be running.
  145. get_reconfigs
  146. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  147. printf "ERROR: server has been reconfigured despite bogus configuration.\n"
  148. clean_exit 1
  149. elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
  150. printf "ERROR: server did not report reconfiguration error despite attempt\
  151. to configure it with invalid configuration.\n"
  152. clean_exit 1
  153. fi
  154. # Make sure the server is still operational.
  155. get_pid ${bin}
  156. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  157. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  158. clean_exit 1
  159. fi
  160. # Restore the good configuration.
  161. create_config "${CONFIG}"
  162. # Reconfigure the server with SIGHUP.
  163. send_signal 1 ${bin}
  164. # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
  165. # Wait for it up to 10s.
  166. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  167. # After receiving SIGHUP the server should get reconfigured and the
  168. # reconfiguration should be noted in the log file. We should now
  169. # have two configurations logged in the log file.
  170. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  171. printf "ERROR: server hasn't been reconfigured.\n"
  172. clean_exit 1
  173. else
  174. printf "Server successfully reconfigured.\n"
  175. fi
  176. # Make sure the server is still operational.
  177. get_pid ${bin}
  178. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  179. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  180. clean_exit 1
  181. fi
  182. # When the server receives a signal the call to select() function is
  183. # interrupted. This should not be logged as an error.
  184. get_log_messages "DHCP6_PACKET_RECEIVE_FAIL"
  185. assert_eq 0 ${_GET_LOG_MESSAGES} \
  186. "Expected get_log_messages DHCP6_PACKET_RECEIVE_FAIL return %d, \
  187. returned %d."
  188. # All ok. Shut down Kea and exit.
  189. test_finish 0
  190. }
  191. # This test verifies that DHCPv6 server is shut down gracefully when it
  192. # receives a SIGINT or SIGTERM signal.
  193. shutdown_test() {
  194. test_name=${1} # Test name
  195. signum=${2} # Signal number
  196. # Log the start of the test and print test name.
  197. test_start ${test_name}
  198. # Remove dangling Kea instances and remove log files.
  199. cleanup
  200. # Create new configuration file.
  201. create_config "${CONFIG}"
  202. # Instruct Kea to log to the specific file.
  203. set_logger
  204. # Start Kea.
  205. start_kea ${bin_path}/${bin}
  206. # Wait up to 20s for Kea to start.
  207. wait_for_kea 20
  208. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  209. printf "ERROR: timeout waiting for Kea to start.\n"
  210. clean_exit 1
  211. fi
  212. # Check if it is still running. It could have terminated (e.g. as a result
  213. # of configuration failure).
  214. get_pid ${bin}
  215. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  216. printf "ERROR: expected one Kea process to be started. Found %d processes\
  217. started.\n" ${_GET_PIDS_NUM}
  218. clean_exit 1
  219. fi
  220. # Check in the log file, how many times server has been configured. It should
  221. # be just once on startup.
  222. get_reconfigs
  223. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  224. printf "ERROR: server hasn't been configured.\n"
  225. clean_exit 1
  226. else
  227. printf "Server successfully configured.\n"
  228. fi
  229. # Send signal to Kea (SIGTERM, SIGINT etc.)
  230. send_signal ${signum} ${bin}
  231. # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  232. # should be recorded in the log file with the appropriate message.
  233. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  234. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  235. printf "ERROR: Server did not record shutdown in the log.\n"
  236. clean_exit 1
  237. fi
  238. # Make sure the server is down.
  239. wait_for_server_down 5 ${bin}
  240. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  241. "Expected wait_for_server_down return %d, returned %d"
  242. # When the server receives a signal the call to select() function is
  243. # interrupted. This should not be logged as an error.
  244. get_log_messages "DHCP6_PACKET_RECEIVE_FAIL"
  245. assert_eq 0 ${_GET_LOG_MESSAGES} \
  246. "Expected get_log_messages DHCP6_PACKET_RECEIVE_FAIL return %d, \
  247. returned %d."
  248. test_finish 0
  249. }
  250. # This test verifies that DHCPv6 can be configured to run lease file cleanup
  251. # periodially.
  252. lfc_timer_test() {
  253. # Log the start of the test and print test name.
  254. test_start "dhcpv6_srv.lfc_timer_test"
  255. # Remove dangling Kea instances and remove log files.
  256. cleanup
  257. # Create a configuration with the LFC enabled, by replacing the section
  258. # with the lfc-interval and persist parameters.
  259. LFC_CONFIG=$(printf "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 1/g' \
  260. | sed -e 's/\"persist\": false,/\"persist\": true,/g')
  261. # Create new configuration file.
  262. create_config "${LFC_CONFIG}"
  263. # Instruct Kea to log to the specific file.
  264. set_logger
  265. # Start Kea.
  266. start_kea ${bin_path}/${bin}
  267. # Wait up to 20s for Kea to start.
  268. wait_for_kea 20
  269. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  270. printf "ERROR: timeout waiting for Kea to start.\n"
  271. clean_exit 1
  272. fi
  273. # Check if it is still running. It could have terminated (e.g. as a result
  274. # of configuration failure).
  275. get_pid ${bin}
  276. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  277. printf "ERROR: expected one Kea process to be started. Found %d processes\
  278. started.\n" ${_GET_PIDS_NUM}
  279. clean_exit 1
  280. fi
  281. # Check if Kea emits the log message indicating that LFC is started.
  282. wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 1
  283. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  284. printf "ERROR: Server did not execute LFC.\n"
  285. clean_exit 1
  286. fi
  287. # Give it a short time to run.
  288. sleep 1
  289. # Modify the interval.
  290. LFC_CONFIG=$(printf "${CONFIG}" | sed -e 's/\"lfc-interval\": 1/\"lfc-interval\": 2/g')
  291. # Create new configuration file.
  292. create_config "${LFC_CONFIG}"
  293. # Reconfigure the server with SIGHUP.
  294. send_signal 1 ${bin}
  295. # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
  296. # Wait for it up to 10s.
  297. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  298. # After receiving SIGHUP the server should get reconfigured and the
  299. # reconfiguration should be noted in the log file. We should now
  300. # have two configurations logged in the log file.
  301. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  302. printf "ERROR: server hasn't been reconfigured.\n"
  303. clean_exit 1
  304. else
  305. printf "Server successfully reconfigured.\n"
  306. fi
  307. # Make sure the server is still operational.
  308. get_pid ${bin}
  309. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  310. printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  311. clean_exit 1
  312. fi
  313. # Wait for the LFC to run the second time.
  314. wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 2
  315. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  316. printf "ERROR: Server did not execute LFC.\n"
  317. clean_exit 1
  318. fi
  319. # Send signal to Kea SIGTERM
  320. send_signal 15 ${bin}
  321. # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  322. # should be recorded in the log file with the appropriate message.
  323. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  324. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  325. printf "ERROR: Server did not record shutdown in the log.\n"
  326. clean_exit 1
  327. fi
  328. # Make sure the server is down.
  329. wait_for_server_down 5 ${bin}
  330. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  331. "Expected wait_for_server_down return %d, returned %d"
  332. # All ok. Shut down Kea and exit.
  333. test_finish 0
  334. }
  335. server_pid_file_test "${CONFIG}" DHCP6_ALREADY_RUNNING
  336. dynamic_reconfiguration_test
  337. shutdown_test "dhcpv6.sigterm_test" 15
  338. shutdown_test "dhcpv6.sigint_test" 2
  339. version_test "dhcpv6.version"
  340. logger_vars_test "dhcpv6.variables"
  341. lfc_timer_test