Browse Source

[3406] Implemented test that checks dynamic reconfiguration of the server.

Marcin Siodelski 11 years ago
parent
commit
846a4c4c1a
2 changed files with 113 additions and 1 deletions
  1. 10 1
      src/bin/dhcp6/tests/Makefile.am
  2. 103 0
      src/bin/dhcp6/tests/dhcp6_reconfigure_test.sh

+ 10 - 1
src/bin/dhcp6/tests/Makefile.am

@@ -1,6 +1,7 @@
 PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
 PYTESTS = dhcp6_test.py
-EXTRA_DIST = $(PYTESTS)
+SHTESTS = dhcp6_reconfigure_test.sh
+EXTRA_DIST = $(PYTESTS) $(SHTESTS)
 
 # Explicitly specify paths to dynamic libraries required by loadable python
 # modules. That is required on Mac OS systems. Otherwise we will get exception
@@ -20,6 +21,12 @@ check-local:
 		$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
 	done
 
+	for shtest in $(SHTESTS) ; do \
+	echo Running test: $$shtest ; \
+	B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir) \
+	$(abs_srcdir)/$$shtest || exit ; \
+	done
+
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header
@@ -30,6 +37,7 @@ AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
 
 CLEANFILES  = $(builddir)/interfaces.txt $(builddir)/logger_lockfile
 CLEANFILES += $(builddir)/load_marker.txt $(builddir)/unload_marker.txt
+CLEANFILES += *.json *.log
 
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 if USE_CLANGPP
@@ -41,6 +49,7 @@ TESTS_ENVIRONMENT = \
         $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
 
 TESTS =
+TEST_EXTENSIONS = .sh
 if HAVE_GTEST
 # Build shared libraries for testing. The libtool way to create a shared library
 # is to specify "-avoid-version -export-dynamic -module" in the library LDFLAGS

+ 103 - 0
src/bin/dhcp6/tests/dhcp6_reconfigure_test.sh

@@ -0,0 +1,103 @@
+# Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+# Name of the Kea executable.
+BIN="../b10-dhcp6"
+# Path to the temporary configuration file.
+CFG_FILE="test_config.json"
+# Path to the Kea log file.
+LOG_FILE="test.log"
+# Kea configuration to be stored in the configuration file.
+CONFIG="{
+    \"Dhcp6\":
+    {
+        \"interfaces\": [ ],
+        \"preferred-lifetime\": 3000,
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\"
+        },
+        \"subnet6\": [
+        {
+            \"subnet\": \"2001:db8:1::/64\",
+            \"pool\": [ \"2001:db8:1::10-2001:db8:1::100\" ],
+            \"interface\": \"vboxnet0\"
+        } ]
+    }
+}"
+
+_GETPIDS1=
+_GETPIDS2=
+getpids() {
+    _GETPIDS1=`ps -o pid,command | grep b10-dhcp | grep -v grep | awk '{print $1}'`
+    _GETPIDS2=`printf "%s" "${_GETPIDS1}" | wc -w | awk '{print $1}'`
+}
+
+cleanup() {
+    getpids
+    for pid in ${_GETPIDS1}
+    do
+        printf "Shutting down Kea proccess having pid %d.\n" ${pid}
+        kill -9 ${pid}
+    done
+}
+
+cleanexit() {
+    cleanup
+    exit $1
+}
+
+printf "Creating Kea configuration file: %s.\n" ${CFG_FILE}
+printf "%b" ${CONFIG} > ${CFG_FILE}
+
+printf "Kea log will be stored in %s.\n" ${LOG_FILE}
+export B10_LOGGER_DESTINATION=${LOG_FILE}
+
+# Kill any dangling Kea processes.
+cleanup
+
+# Start fresh Kea process using a test configuration.
+printf "Running command %s.\n" "\"$BIN -c ${CFG_FILE}\""
+$BIN -c ${CFG_FILE} &
+
+# Wait a second. It may take a bit before it starts.
+sleep 1
+
+# Make sure that exactly one process has been started.
+getpids
+if [ ${_GETPIDS2} -ne 1 ]; then
+    printf "ERROR: expected one Kea process to be started. Found %d processes started.\n" ${_GETPIDS2}
+    cleanexit 1
+fi
+
+# Reconfigure the server with SIGUP.
+printf "Sending SIGUP to Kea process (pid=%s) to reconfigure the server.\n" ${_GETPIDS1}
+kill -SIGHUP ${_GETPIDS1}
+
+# Be patient. Kea may need a while to reconfigure or shut down if reconfiguration
+# didn't work.
+sleep 1
+
+# Make sure it is still operational.
+getpids
+if [ ${_GETPIDS2} -ne 1 ]; then
+    printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
+    cleanexit 1
+fi
+
+# All ok. Shut down Kea and exit.
+cleanexit 0