Browse Source

[3422] Implemented Kea startup with the keactrl script.

Marcin Siodelski 11 years ago
parent
commit
5dc9661031

+ 3 - 0
configure.ac

@@ -1458,6 +1458,8 @@ AC_CONFIG_FILES([compatcheck/Makefile
                  src/bin/dhcp6/tests/test_libraries.h
                  src/bin/keactrl/keactrl
                  src/bin/keactrl/Makefile
+                 src/bin/keactrl/tests/keactrl_tests.sh
+                 src/bin/keactrl/tests/Makefile
                  src/bin/Makefile
                  src/bin/msgq/Makefile
                  src/bin/msgq/msgq.py
@@ -1590,6 +1592,7 @@ AC_CONFIG_FILES([compatcheck/Makefile
            chmod +x src/bin/cmdctl/run_b10-cmdctl.sh
            chmod +x src/bin/cmdctl/tests/cmdctl_test
            chmod +x src/bin/keactrl/keactrl
+           chmod +x src/bin/keactrl/tests/keactrl_tests.sh
            chmod +x src/bin/msgq/run_msgq.sh
            chmod +x src/bin/sysinfo/run_sysinfo.sh
            chmod +x src/bin/usermgr/run_b10-cmdctl-usermgr.sh

+ 4 - 4
src/bin/dhcp4/dhcp4_messages.mes

@@ -324,10 +324,10 @@ A debug message listing the data returned to the client.
 The DHCPv4 server has encountered a fatal error and is terminating.
 The reason for the failure is included in the message.
 
-% DHCP4_SESSION_FAIL failed to establish BIND 10 session (%1), running stand-alone
-The server has failed to establish communication with the rest of BIND
-10 and is running in stand-alone mode.  (This behavior will change once
-the DHCPv4 server is properly integrated with the rest of BIND 10.)
+% DHCP4_INIT_FAIL failed to initialize Kea server: %1
+The server has failed to initialize. This may be because the configuration
+was not successful, or it encountered any other critical error on startup.
+Attached error message provides more details about the issue.
 
 % DHCP4_SHUTDOWN server shutdown
 The DHCPv4 server has terminated normally.

+ 1 - 1
src/bin/dhcp4/main.cc

@@ -115,7 +115,7 @@ main(int argc, char* argv[]) {
             // Initialize the server.
             server.init(config_file);
         } catch (const std::exception& ex) {
-            LOG_ERROR(dhcp4_logger, DHCP4_SESSION_FAIL).arg(ex.what());
+            LOG_ERROR(dhcp4_logger, DHCP4_INIT_FAIL).arg(ex.what());
 
             // We should not continue if were told to configure (either read
             // config file or establish Bundy control session).

+ 5 - 5
src/bin/dhcp6/tests/dhcp6_reconfigure_test.sh

@@ -88,7 +88,7 @@ fi
 
 # Check if it is still running. It could have terminated (e.g. as a result
 # of configuration failure).
-get_pids
+get_pids ${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
@@ -108,7 +108,7 @@ fi
 create_config "${CONFIG_INVALID}"
 
 # Try to reconfigure by sending SIGHUP
-send_signal 1
+send_signal 1 ${BIN}
 
 # The configuration should fail and the error message should be there.
 wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
@@ -127,7 +127,7 @@ elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
 fi
 
 # Make sure the server is still operational.
-get_pids
+get_pids ${BIN}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     clean_exit 1
@@ -137,7 +137,7 @@ fi
 create_config "${CONFIG}"
 
 # Reconfigure the server with SIGHUP.
-send_signal 1
+send_signal 1 ${BIN}
 
 # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
 # Wait for it up to 10s.
@@ -154,7 +154,7 @@ else
 fi
 
 # Make sure the server is still operational.
-get_pids
+get_pids ${BIN}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     clean_exit 1

+ 3 - 3
src/bin/dhcp6/tests/dhcp6_shutdown_test.sh

@@ -73,7 +73,7 @@ fi
 
 # Check if it is still running. It could have terminated (e.g. as a result
 # of configuration failure).
-get_pids
+get_pids ${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
@@ -90,7 +90,7 @@ else
 fi
 
 # Send signal to Kea (SIGTERM, SIGINT etc.)
-send_signal ${SIG_NUM}
+send_signal ${SIG_NUM} ${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.
@@ -101,7 +101,7 @@ if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
 fi
 
 # Server should have shut down.
-get_pids
+get_pids ${BIN}
 if [ ${_GET_PIDS_NUM} -ne 0 ]; then
     printf "ERROR: Kea did not shut down after receiving signal.\n" ${_GET_PIDS_NUM}
     clean_exit 1

+ 1 - 0
src/bin/keactrl/.gitignore

@@ -0,0 +1 @@
+keactrl

+ 3 - 2
src/bin/keactrl/Makefile.am

@@ -1,6 +1,7 @@
-SUBDIRS = .
+SUBDIRS = . tests
 
-sbin_SCRIPTS = keactrl
+sbin_SCRIPTS  = keactrl
+CLEAN_FILES = keactrl
 
 EXTRA_DIST = keactrl.in
 

+ 173 - 25
src/bin/keactrl/keactrl.in

@@ -1,13 +1,123 @@
 #!/bin/sh
 
+# 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.
+
 # This is keactrl script responsible for starting up Kea processes.
 # This script is used to run Kea from installation directory,
 # as well as for running tests.
 
-# Set locations of the Kea binaries.
+### Logging functions ###
+
+# Logs message at the error level.
+log_error() {
+    printf "ERROR/keactrl: ${1}\n"
+}
+
+# Logs message at the warning level.
+log_warning() {
+    printf "WARNING/keactrl: ${1}\n"
+}
+
+# Logs message at the info level.
+log_info() {
+    printf "INFO/keactrl: ${1}\n"
+}
+
+# Returns a list of existing PIDs and a number of PIDs for the process
+# having a name specified as an argument to the function.
+get_pids() {
+    local proc_name=${1}  # Process name.
+    # Return the list of PIDs.
+    _get_pids=$(ps axwwo pid,command | grep ${proc_name} | grep -v grep \
+        | awk '{print $1}')
+    # Return the number of PIDs.
+    _get_pids_num=$(printf "%s" "${pids}" | wc -w | awk '{print $1}')
+}
+
+# Checks if the specified process is running. Internally it calls get_pids
+# to get the number of processes.
+check_running() {
+    local proc_name=${1} # Process name.
+    # Initially mark the process as not running.
+    _running=0
+    get_pids ${proc_name}
+    # If the number of pids is non-zero, the process is running.
+    if [ ${_get_pids_num} -gt 0 ]; then
+        _running=1
+    fi
+}
+
+# Sends a signal to a group of processes having a specified name.
+send_signal() {
+    local sig=${1}        # Signal number
+    local proc_name=${2}  # Process name.
+    # Get all PIDs for the specified process name.
+    get_pids ${proc_name}
+    # If no processes running, there is no process we can send the signal
+    # to. This is not neccessarily an error.
+    if [ -z get_pids ]; then
+        log_info "Skip sending signal ${sig} to process ${proc_name}: \
+process is not running\n"
+        return
+    fi
+    # Send a signal to all processes.
+    kill -${sig} ${_get_pids} >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+        log_error "Failed to send signal ${sig} to process ${proc_name}.\n"
+    fi
+}
+
+# Start the Kea process. Do not start the process if there is an instance
+# already running.
+start_server() {
+    binary_path=${1}  # Full path to the binary.
+    binary_args=${2}  # Arguments.
+    # Extract the name of the binary from the path.
+    local binary_name=$(basename ${binary_path})
+    # Use the binary name to check if the process is already running.
+    check_running $(basename ${binary_name})
+    # If process is running, don't start another one. Just log a message.
+    if [ ${_running} -ne 0 ]; then
+        log_info "Skip starting ${binary_name} \
+as another instance is already running."
+    else
+        log_info "Starting ${binary_name} ${args}"
+        # Start the process.
+        ${binary_path} ${args} &
+    fi
+}
+
+command=
+if [ $# -ne 1 ]; then
+    log_error "No command specified. Use: start, stop, commit."
+    exit 1
+
+elif [ "${1}" != "start" -a "${1}" != "stop" -a "${1}" != "commit" ]; then
+    log_error "Illegal command: ${1}"
+    exit 1
+
+else
+    command=${1}
+fi
+
+# Set locations of the Kea binaries. The location depends on whether we
+# are running unit tests or we're running the installed binaries.
 dhcpv4_srv=
 dhcpv6_srv=
 dhcp_ddns=
+keactrl_conf=
 
 # The environment variable is set when the script is ran from the
 # tests. If not set, the Kea installation directory is used.
@@ -18,34 +128,72 @@ if test -n "${KEACTRL_BUILD_DIR}"; then
 else
     prefix=@prefix@
     exec_prefix=@exec_prefix@
-    dhcpv4_srv=@libexecdir@/@PACKAGE@/b10-dhcp4
+    dhcpv4_srv=@libexecdir@/@PACKAGE@/dhcp4/b10-dhcp4
     dhcpv6_srv=@libexecdir@/@PACKAGE@/dhcp6/b10-dhcp6
     dhcp_ddns=@libexecdir@/@PACKAGE@/b10-dhcp-ddns
+    keactrl_conf=@etcdir@/@PACKAGE@/keactrl.conf
 fi
 
-optstring=c:v:46
-
-config_file=
-verbose=0
-kea4=0
-kea6=0
-
-while getopts ${optstring} opt
-do
-    case ${opt} in
-        c) config_file=${OPTARG} ;;
-        v) verbose=$(( ${verbose} + 1 )) ;;
-        4) kea4=$(( ${kea4} + 1 )) ;;
-        6) kea6=$(( ${kea6} + 1 )) ;;
-        *) exit 1;
-    esac
-done
-
-if [ ${kea4} -eq 0 -a ${kea6} -eq 0 ]; then
-    kea4=1
-    kea6=1
+# KEACTRL_CONF environment variable may hold a location of the keactrl
+# configuration file. If this is the case, it overrides the default
+# location.
+if test -n "${KEACTRL_CONF}"; then
+    keactrl_conf=${KEACTRL_CONF}
 fi
 
-printf "${kea4}\n"
-printf "${kea6}\n"
+# Check if the file exists. If it doesn't, it is a fatal error.
+if [ ! -f ${keactrl_conf} ]; then
+    log_error "keactrl configuration file doesn't exist."
+    exit 1
+fi
+
+# Include the configuration file.
+. ${keactrl_conf}
+
+# Check if the Kea configuration file location has been specified in the
+# keactrl configuration file. If not, it is a fatal error.
+if [ -z ${kea_config_file} ]; then
+    log_error "Configuration file for Kea not specified."
+    exit 1
+fi
+
+# kea4 and kea6 (=yes) indicate if we should start DHCPv4 and DHCPv6 server
+# respectively.
+kea4=$( printf "%s" ${kea4} | tr [:upper:] [:lower:] )
+kea6=$( printf "%s" ${kea6} | tr [:upper:] [:lower:] )
+
+case ${command} in
+    # Start the servers.
+    start)
+        args="-c ${kea_config_file}"
+
+        if [ ${kea4} == "yes" ]; then
+            start_server ${dhcpv4_srv} "${args}"
+        fi
 
+        if [ ${kea6} == "yes" ]; then
+            start_server ${dhcpv6_srv} "${args}"
+        fi
+
+        exit 0 ;;
+
+    # Stop running servers.
+    stop)
+        send_signal 15 $(basename ${dhcpv4_srv})
+        send_signal 15 $(basename ${dhcpv6_srv})
+
+        exit 0 ;;
+
+    # Reconfigure the servers.
+    commit)
+        send_signal 1 $(basename ${dhcpv4_srv})
+        send_signal 1 $(basename ${dhcpv6_srv})
+
+        exit 0 ;;
+
+    # No other commands are supported.
+    *)
+        log_error "Invalid command:  ${command}."
+        exit 1 ;;
+esac
+fi

+ 1 - 0
src/bin/keactrl/tests/.gitignore

@@ -0,0 +1 @@
+keactrl_tests.sh

+ 16 - 0
src/bin/keactrl/tests/Makefile.am

@@ -0,0 +1,16 @@
+SUBDIRS = .
+
+SHTESTS = keactrl_tests.sh
+
+noinst_SCRIPTS = keactrl_tests.sh
+
+EXTRA_DIST = keactrl_tests.sh.in
+
+check-local:
+	for shtest in $(SHTESTS) ; do \
+	echo Running test: $$shtest ; \
+	chmod +x $(abs_builddir)/$$shtest ; \
+	export KEACTRL_BUILD_DIR=$(abs_top_builddir); \
+	export KEACTRL_CONF=$(abs_top_builddir)/src/bin/keactrl/tests/keactrl_test.conf; \
+	$(abs_srcdir)/$$shtest || exit ; \
+	done

+ 150 - 0
src/bin/keactrl/tests/keactrl_tests.sh.in

@@ -0,0 +1,150 @@
+#!/bin/sh
+
+# 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.
+
+# Include common test library.
+. @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
+
+# Set location of the keactrl.
+keactrl=@abs_top_builddir@/src/bin/keactrl/keactrl
+
+# A name of the configuration file to be used by Kea.
+CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/test_config.json
+# A name of the keactrl config file
+KEACTRL_CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/keactrl_test.conf
+# Path to the Kea log file.
+LOG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/test.log
+# Binaries' names
+kea4_name="b10-dhcp4"
+kea6_name="b10-dhcp6"
+# Kea configuration
+config="{
+    \"Dhcp4\":
+    {
+        \"interfaces\": [ ],
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"persist\": false
+        },
+        \"subnet4\": [
+        {
+            \"subnet\": \"10.0.0.0/24\",
+            \"pool\": [ \"10.0.0.10-10.0.0.100\" ]
+        } ]
+    },
+    \"Dhcp6\":
+    {
+        \"interfaces\": [ ],
+        \"preferred-lifetime\": 3000,
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"persist\": false
+        },
+        \"subnet6\": [
+        {
+            \"subnet\": \"2001:db8:1::/64\",
+            \"pool\": [ \"2001:db8:1::10-2001:db8:1::100\" ]
+        } ]
+    }
+}"
+
+# This test checks that both DHCPv4 and DHCPv6 server can be started and
+# shut down.
+start_both_servers_test() {
+    # Test name.
+    TEST_NAME="keactrl.startStop"
+    # Create configuration file for keactrl. This configuration enables
+    # both DHCPv4 and DHCPv6 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=yes\n"
+
+    test_start
+
+    # Create configuration file for Kea and for keactrl.
+    create_config "${config}"
+    create_keactrl_config "${keactrl_config}"
+
+    # Set logging to a file.
+    set_logger
+
+    # Start servers using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv6 server to configure.
+    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Wait up to 20s for the DHCPv4 server to configure.
+    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Server may shut down imediatelly after configuration has competed.
+    # Give it some time to shutdown.
+    sleep 3
+
+    # Make sure that both servers are running.
+    get_pids ${kea4_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    get_pids ${kea6_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Use keactrl stop to shutdown the servers.
+    printf "Stopping Kea: ${keactrl} stop\n"
+    ${keactrl} stop
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
+
+    # Wait up to 10s for the DHCPv6 server to stop.
+    wait_for_message 10 "DHCP6_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
+    # Wait up to 10s for the DHCPv4 server to stop.
+    wait_for_message 10 "DHCP4_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+    
+    # Make sure that the servers are down.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} processes running, found %d processes running"
+
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} processes running, found %d processes running"
+}
+
+start_both_servers_test
+
+clean_exit 0

+ 45 - 16
src/lib/testutils/dhcp_test_lib.sh

@@ -18,6 +18,20 @@
 # - BIN_PATH - Path to the Kea executable (excluding an executable name),
 #              e.g. ../
 
+# A list of Kea processes, mainly used by the cleanup functions.
+KEA_PROCS="b10-dhcp4 b10-dhcp6 b10-dhcp-ddns"
+
+assert_eq() {
+    val1=${1}
+    val2=${2}
+    detailed_err=${3}
+    if [ ${val1} -ne ${val2} ]; then
+        printf "Assertion failure: ${val1} != ${val2}, for val1=${val1}, val2=${val2}\n"
+        printf "${detailed_err}\n" ${val1} ${val2}
+        clean_exit 1
+    fi
+}
+
 # Begins a test by prining its name.
 # It requires the ${TEST_NAME} variable to hold the test name.
 test_start() {
@@ -31,6 +45,11 @@ create_config() {
     printf "%b" ${1} > ${CFG_FILE}
 }
 
+create_keactrl_config() {
+    printf "Creating keactrl configuration file: %s.\n" ${KEACTRL_CFG_FILE}
+    printf "%b" ${1} > ${KEACTRL_CFG_FILE}
+}
+
 # Sets Kea logger to write to the file specified by the global value
 # ${LOG_FILE}.
 set_logger() {
@@ -42,18 +61,22 @@ set_logger() {
 _GET_PIDS=     # Return value: holds space separated list of DHCPv6 pids.
 _GET_PIDS_NUM= # Return value: holds the number of DHCPv6 server pids.
 get_pids() {
-    _GET_PIDS=`ps axwwo pid,command | grep ${BIN} | grep -v grep | awk '{print $1}'`
+    proc_name=${1} # Process name
+    _GET_PIDS=`ps axwwo pid,command | grep ${proc_name} | grep -v grep | awk '{print $1}'`
     _GET_PIDS_NUM=`printf "%s" "${_GET_PIDS}" | wc -w | awk '{print $1}'`
 }
 
 # Returns the number of occurrences of the Kea log message in the
 # log file.
-_GET_LOG_MESSAGES= # Holds the number of log message occurrences.
+_GET_LOG_MESSAGES=0 # Holds the number of log message occurrences.
 get_log_messages() {
-    # Grep log file for the logger message occurrences.
-    _GET_LOG_MESSAGES=`grep -o ${1} ${LOG_FILE} | wc -w`
-    # Remove whitespaces.
-    ${_GET_LOG_MESSAGES##*[! ]}
+    _GET_LOG_MESSAGES=0
+    if [ -s ${LOG_FILE} ]; then
+        # Grep log file for the logger message occurrences.
+        _GET_LOG_MESSAGES=`grep -o ${1} ${LOG_FILE} | wc -w`
+        # Remove whitespaces.
+        ${_GET_LOG_MESSAGES##*[! ]}
+    fi
 }
 
 # Returns the number of server configurations performed so far. Also
@@ -75,19 +98,24 @@ get_reconfigs() {
 # Performs cleanup for a test.
 # It shuts down running Kea processes and removes temporary files.
 # The location of the log file and the configuration file should be set
-# in the ${LOG_FILE} and ${CFG_FILE} variables recpectively, prior to
-# calling this function.
+# in the ${LOG_FILE}, ${CFG_FILE} and ${KEACTRL_CFG_FILE} variables
+# recpectively, prior to calling this function.
 cleanup() {
-    get_pids
-    # Shut down running Kea processes.
-    for pid in ${_GET_PIDS}
+    for proc_name in ${KEA_PROCS}
     do
-        printf "Shutting down Kea proccess having pid %d.\n" ${pid}
-        kill -9 ${pid}
+        get_pids ${proc_name}
+        # Shut down running Kea processes.
+        for pid in ${_GET_PIDS}
+        do
+            printf "Shutting down Kea proccess having pid %d.\n" ${pid}
+            kill -9 ${pid}
+        done
+        shift
     done
     # Remove temporary files.
     rm -rf ${LOG_FILE}
     rm -rf ${CFG_FILE}
+    rm -rf ${KEACTRL_CFG_FILE}
 }
 
 # Exists the test in the clean way.
@@ -159,7 +187,7 @@ wait_for_message() {
     loops=0          # Number of loops performed so far.
     _WAIT_FOR_MESSAGE=0
     # Check if log file exists and if we reached timeout.
-    while [ ! -s {LOG_FILE} ] && [ ${loops} -le ${timeout} ]; do
+    while [ ${loops} -le ${timeout} ]; do
         printf "."
         # Check if the message has been logged.
         get_log_messages ${message}
@@ -178,9 +206,10 @@ wait_for_message() {
 
 # Sends specified signal to the Kea process.
 send_signal() {
-    sig=${1}  # Signal number.
+    sig=${1}       # Signal number.
+    proc_name=${2} # Process name
     # Get Kea pid.
-    get_pids
+    get_pids ${proc_name}
     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