dhcp6_shutdown_test.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if [ $# -ne 2 ]; then
  15. printf "USAGE: dhcp6_shutdown_test.sh <test_name> <signal_num>\n"
  16. exit 1
  17. fi
  18. # Test name
  19. test_name=${1}
  20. # Signal number to be used for this test.
  21. SIG_NUM=$2
  22. # Path to the temporary configuration file.
  23. CFG_FILE="test_config.json"
  24. # Path to the Kea log file.
  25. LOG_FILE="test.log"
  26. # Kea configuration to be stored in the configuration file.
  27. CONFIG="{
  28. \"Dhcp6\":
  29. {
  30. \"interfaces\": [ ],
  31. \"preferred-lifetime\": 3000,
  32. \"valid-lifetime\": 4000,
  33. \"renew-timer\": 1000,
  34. \"rebind-timer\": 2000,
  35. \"lease-database\":
  36. {
  37. \"type\": \"memfile\",
  38. \"persist\": false
  39. },
  40. \"subnet6\": [
  41. {
  42. \"subnet\": \"2001:db8:1::/64\",
  43. \"pool\": [ \"2001:db8:1::10-2001:db8:1::100\" ]
  44. } ]
  45. }
  46. }"
  47. # Set the location of the executable.
  48. bin="b10-dhcp6"
  49. bin_path=".."
  50. # Import common test library.
  51. . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
  52. # Log the start of the test and print test name.
  53. test_start ${test_name}
  54. # Remove dangling Kea instances and remove log files.
  55. cleanup
  56. # Create new configuration file.
  57. create_config "${CONFIG}"
  58. # Instruct Kea to log to the specific file.
  59. set_logger
  60. # Start Kea.
  61. start_kea ${bin_path}/${bin}
  62. # Wait up to 20s for Kea to start.
  63. wait_for_kea 20
  64. if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  65. printf "ERROR: timeout waiting for Kea to start.\n"
  66. clean_exit 1
  67. fi
  68. # Check if it is still running. It could have terminated (e.g. as a result
  69. # of configuration failure).
  70. get_pids ${bin}
  71. if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  72. printf "ERROR: expected one Kea process to be started. Found %d processes\
  73. started.\n" ${_GET_PIDS_NUM}
  74. clean_exit 1
  75. fi
  76. # Check in the log file, how many times server has been configured. It should
  77. # be just once on startup.
  78. get_reconfigs
  79. if [ ${_GET_RECONFIGS} -ne 1 ]; then
  80. printf "ERROR: server hasn't been configured.\n"
  81. clean_exit 1
  82. else
  83. printf "Server successfully configured.\n"
  84. fi
  85. # Send signal to Kea (SIGTERM, SIGINT etc.)
  86. send_signal ${SIG_NUM} ${bin}
  87. # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  88. # should be recorded in the log file with the appropriate message.
  89. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  90. if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  91. printf "ERROR: Server did not record shutdown in the log.\n"
  92. clean_exit 1
  93. fi
  94. # Server should have shut down.
  95. get_pids ${bin}
  96. if [ ${_GET_PIDS_NUM} -ne 0 ]; then
  97. printf "ERROR: Kea did not shut down after receiving signal.\n"\
  98. ${_GET_PIDS_NUM}
  99. clean_exit 1
  100. fi
  101. clean_exit 0