123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- # Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
- #
- # This Source Code Form is subject to the terms of the Mozilla Public
- # License, v. 2.0. If a copy of the MPL was not distributed with this
- # file, You can obtain one at http://mozilla.org/MPL/2.0/.
- # Path to the temporary configuration file.
- CFG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test_config.json
- # Path to the Kea log file.
- LOG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test.log
- # Path to the Kea lease file.
- LEASE_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test_leases.csv
- # Expected version
- EXPECTED_VERSION="@PACKAGE_VERSION@"
- # Kea configuration to be stored in the configuration file.
- CONFIG="{
- \"Dhcp6\":
- { \"interfaces-config\": {
- \"interfaces\": [ ]
- },
- \"server-id\": {
- \"type\": \"LLT\",
- \"persist\": false
- },
- \"preferred-lifetime\": 3000,
- \"valid-lifetime\": 4000,
- \"renew-timer\": 1000,
- \"rebind-timer\": 2000,
- \"lease-database\":
- {
- \"type\": \"memfile\",
- \"name\": \"$LEASE_FILE\",
- \"persist\": false,
- \"lfc-interval\": 0
- },
- \"subnet6\": [
- {
- \"subnet\": \"2001:db8:1::/64\",
- \"pools\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
- } ],
- \"dhcp-ddns\": {
- \"enable-updates\": true,
- \"qualifying-suffix\": \"\"
- }
- },
- \"Logging\":
- {
- \"loggers\": [
- {
- \"name\": \"kea-dhcp6\",
- \"output_options\": [
- {
- \"output\": \"$LOG_FILE\"
- }
- ],
- \"severity\": \"INFO\"
- }
- ]
- }
- }"
- # Invalid configuration (negative preferred-lifetime) to check that Kea
- # gracefully handles reconfiguration errors.
- CONFIG_INVALID="{
- \"Dhcp6\":
- {
- \"interfaces\": [ ],
- \"preferred-lifetime\": -3,
- \"valid-lifetime\": 4000,
- \"renew-timer\": 1000,
- \"rebind-timer\": 2000,
- \"lease-database\":
- {
- \"type\": \"memfile\",
- \"persist\": false
- },
- \"subnet6\": [
- {
- \"subnet\": \"2001:db8:1::/64\",
- \"pool\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
- } ]
- },
- \"Logging\":
- {
- \"loggers\": [
- {
- \"name\": \"kea-dhcp6\",
- \"output_options\": [
- {
- \"output\": \"$LOG_FILE\"
- }
- ],
- \"severity\": \"INFO\"
- }
- ]
- }
- }"
- # Set the location of the executable.
- bin="kea-dhcp6"
- bin_path=@abs_top_builddir@/src/bin/dhcp6
- # Import common test library.
- . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
- # This test verifies that DHCPv6 can be reconfigured with a SIGHUP signal.
- dynamic_reconfiguration_test() {
- # Log the start of the test and print test name.
- test_start "dhcpv6_srv.dynamic_reconfiguration"
- # Remove dangling Kea instances and remove log files.
- cleanup
- # Create new configuration file.
- create_config "${CONFIG}"
- # Instruct Kea to log to the specific file.
- set_logger
- # Start Kea.
- start_kea ${bin_path}/${bin}
- # Wait up to 20s for Kea to start.
- wait_for_kea 20
- if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
- printf "ERROR: timeout waiting for Kea to start.\n"
- clean_exit 1
- fi
- # Check if it is still running. It could have terminated (e.g. as a result
- # of configuration failure).
- get_pid ${bin}
- if [ ${_GET_PIDS_NUM} -ne 1 ]; then
- printf "ERROR: expected one Kea process to be started. Found %d processes\
- started.\n" ${_GET_PIDS_NUM}
- clean_exit 1
- fi
- # Check in the log file, how many times server has been configured. It should
- # be just once on startup.
- get_reconfigs
- if [ ${_GET_RECONFIGS} -ne 1 ]; then
- printf "ERROR: server hasn't been configured.\n"
- clean_exit 1
- else
- printf "Server successfully configured.\n"
- fi
- # Now use invalid configuration.
- create_config "${CONFIG_INVALID}"
- # Try to reconfigure by sending SIGHUP
- send_signal 1 ${bin}
- # The configuration should fail and the error message should be there.
- wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
- # After receiving SIGHUP the server should try to reconfigure itself.
- # The configuration provided is invalid so it should result in
- # reconfiguration failure but the server should still be running.
- get_reconfigs
- if [ ${_GET_RECONFIGS} -ne 1 ]; then
- printf "ERROR: server has been reconfigured despite bogus configuration.\n"
- clean_exit 1
- elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
- printf "ERROR: server did not report reconfiguration error despite attempt\
- to configure it with invalid configuration.\n"
- clean_exit 1
- fi
- # Make sure the server is still operational.
- get_pid ${bin}
- if [ ${_GET_PIDS_NUM} -ne 1 ]; then
- printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
- clean_exit 1
- fi
- # Restore the good configuration.
- create_config "${CONFIG}"
- # Reconfigure the server with SIGHUP.
- send_signal 1 ${bin}
- # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
- # Wait for it up to 10s.
- wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
- # After receiving SIGHUP the server should get reconfigured and the
- # reconfiguration should be noted in the log file. We should now
- # have two configurations logged in the log file.
- if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
- printf "ERROR: server hasn't been reconfigured.\n"
- clean_exit 1
- else
- printf "Server successfully reconfigured.\n"
- fi
- # Make sure the server is still operational.
- get_pid ${bin}
- if [ ${_GET_PIDS_NUM} -ne 1 ]; then
- printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
- clean_exit 1
- fi
- # When the server receives a signal the call to select() function is
- # interrupted. This should not be logged as an error.
- get_log_messages "DHCP6_PACKET_RECEIVE_FAIL"
- assert_eq 0 ${_GET_LOG_MESSAGES} \
- "Expected get_log_messages DHCP6_PACKET_RECEIVE_FAIL return %d, \
- returned %d."
- # All ok. Shut down Kea and exit.
- test_finish 0
- }
- # This test verifies that DHCPv6 server is shut down gracefully when it
- # receives a SIGINT or SIGTERM signal.
- shutdown_test() {
- test_name=${1} # Test name
- signum=${2} # Signal number
- # Log the start of the test and print test name.
- test_start ${test_name}
- # Remove dangling Kea instances and remove log files.
- cleanup
- # Create new configuration file.
- create_config "${CONFIG}"
- # Instruct Kea to log to the specific file.
- set_logger
- # Start Kea.
- start_kea ${bin_path}/${bin}
- # Wait up to 20s for Kea to start.
- wait_for_kea 20
- if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
- printf "ERROR: timeout waiting for Kea to start.\n"
- clean_exit 1
- fi
- # Check if it is still running. It could have terminated (e.g. as a result
- # of configuration failure).
- get_pid ${bin}
- if [ ${_GET_PIDS_NUM} -ne 1 ]; then
- printf "ERROR: expected one Kea process to be started. Found %d processes\
- started.\n" ${_GET_PIDS_NUM}
- clean_exit 1
- fi
- # Check in the log file, how many times server has been configured. It should
- # be just once on startup.
- get_reconfigs
- if [ ${_GET_RECONFIGS} -ne 1 ]; then
- printf "ERROR: server hasn't been configured.\n"
- clean_exit 1
- else
- printf "Server successfully configured.\n"
- fi
- # Send signal to Kea (SIGTERM, SIGINT etc.)
- send_signal ${signum} ${bin}
- # Wait up to 10s for the server's graceful shutdown. The graceful shut down
- # should be recorded in the log file with the appropriate message.
- wait_for_message 10 "DHCP6_SHUTDOWN" 1
- if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
- printf "ERROR: Server did not record shutdown in the log.\n"
- clean_exit 1
- fi
- # Make sure the server is down.
- wait_for_server_down 5 ${bin}
- assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
- "Expected wait_for_server_down return %d, returned %d"
- # When the server receives a signal the call to select() function is
- # interrupted. This should not be logged as an error.
- get_log_messages "DHCP6_PACKET_RECEIVE_FAIL"
- assert_eq 0 ${_GET_LOG_MESSAGES} \
- "Expected get_log_messages DHCP6_PACKET_RECEIVE_FAIL return %d, \
- returned %d."
- test_finish 0
- }
- # This test verifies that DHCPv6 can be configured to run lease file cleanup
- # periodially.
- lfc_timer_test() {
- # Log the start of the test and print test name.
- test_start "dhcpv6_srv.lfc_timer_test"
- # Remove dangling Kea instances and remove log files.
- cleanup
- # Create a configuration with the LFC enabled, by replacing the section
- # with the lfc-interval and persist parameters.
- LFC_CONFIG=$(printf "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 1/g' \
- | sed -e 's/\"persist\": false,/\"persist\": true,/g')
- # Create new configuration file.
- create_config "${LFC_CONFIG}"
- # Instruct Kea to log to the specific file.
- set_logger
- # Start Kea.
- start_kea ${bin_path}/${bin}
- # Wait up to 20s for Kea to start.
- wait_for_kea 20
- if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
- printf "ERROR: timeout waiting for Kea to start.\n"
- clean_exit 1
- fi
- # Check if it is still running. It could have terminated (e.g. as a result
- # of configuration failure).
- get_pid ${bin}
- if [ ${_GET_PIDS_NUM} -ne 1 ]; then
- printf "ERROR: expected one Kea process to be started. Found %d processes\
- started.\n" ${_GET_PIDS_NUM}
- clean_exit 1
- fi
- # Check if Kea emits the log message indicating that LFC is started.
- wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 1
- if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
- printf "ERROR: Server did not execute LFC.\n"
- clean_exit 1
- fi
- # Give it a short time to run.
- sleep 1
- # Modify the interval.
- LFC_CONFIG=$(printf "${CONFIG}" | sed -e 's/\"lfc-interval\": 1/\"lfc-interval\": 2/g')
- # Create new configuration file.
- create_config "${LFC_CONFIG}"
- # Reconfigure the server with SIGHUP.
- send_signal 1 ${bin}
- # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
- # Wait for it up to 10s.
- wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
- # After receiving SIGHUP the server should get reconfigured and the
- # reconfiguration should be noted in the log file. We should now
- # have two configurations logged in the log file.
- if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
- printf "ERROR: server hasn't been reconfigured.\n"
- clean_exit 1
- else
- printf "Server successfully reconfigured.\n"
- fi
- # Make sure the server is still operational.
- get_pid ${bin}
- if [ ${_GET_PIDS_NUM} -ne 1 ]; then
- printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
- clean_exit 1
- fi
- # Wait for the LFC to run the second time.
- wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 2
- if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
- printf "ERROR: Server did not execute LFC.\n"
- clean_exit 1
- fi
- # Send signal to Kea SIGTERM
- send_signal 15 ${bin}
- # Wait up to 10s for the server's graceful shutdown. The graceful shut down
- # should be recorded in the log file with the appropriate message.
- wait_for_message 10 "DHCP6_SHUTDOWN" 1
- if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
- printf "ERROR: Server did not record shutdown in the log.\n"
- clean_exit 1
- fi
- # Make sure the server is down.
- wait_for_server_down 5 ${bin}
- assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
- "Expected wait_for_server_down return %d, returned %d"
- # All ok. Shut down Kea and exit.
- test_finish 0
- }
- server_pid_file_test "${CONFIG}" DHCP6_ALREADY_RUNNING
- dynamic_reconfiguration_test
- shutdown_test "dhcpv6.sigterm_test" 15
- shutdown_test "dhcpv6.sigint_test" 2
- version_test "dhcpv6.version"
- logger_vars_test "dhcpv6.variables"
- lfc_timer_test
|