From: Marcin Siodelski Date: Fri, 11 Dec 2015 14:26:44 +0000 (+0100) Subject: [4224] Shell tests now use pid files to check if process is running. X-Git-Tag: trac4263_base~16^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9f7b33e0ea68b0ca0c2112e77bdbe4a8c10b70b;p=thirdparty%2Fkea.git [4224] Shell tests now use pid files to check if process is running. --- diff --git a/src/bin/d2/tests/d2_process_tests.sh.in b/src/bin/d2/tests/d2_process_tests.sh.in index 80f19c8e01..a1d1ecce90 100755 --- a/src/bin/d2/tests/d2_process_tests.sh.in +++ b/src/bin/d2/tests/d2_process_tests.sh.in @@ -99,7 +99,7 @@ dynamic_reconfiguration_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: expected one D2 process to be started. Found %d processes\ started.\n" ${_GET_PIDS_NUM} @@ -139,7 +139,7 @@ dynamic_reconfiguration_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: D2 was killed when attempting reconfiguration.\n" clean_exit 1 @@ -166,7 +166,7 @@ dynamic_reconfiguration_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: D2 was killed when attempting reconfiguration.\n" clean_exit 1 @@ -200,7 +200,7 @@ shutdown_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: expected one D2 process to be started. Found %d processes\ started.\n" ${_GET_PIDS_NUM} diff --git a/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in b/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in index 6959c94e76..f59d649938 100755 --- a/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in +++ b/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in @@ -132,7 +132,7 @@ dynamic_reconfiguration_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + 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} @@ -172,7 +172,7 @@ dynamic_reconfiguration_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: Kea process was killed when attempting reconfiguration.\n" clean_exit 1 @@ -199,7 +199,7 @@ dynamic_reconfiguration_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: Kea process was killed when attempting reconfiguration.\n" clean_exit 1 @@ -240,7 +240,7 @@ shutdown_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + 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} @@ -308,7 +308,7 @@ lfc_timer_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + 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} @@ -348,7 +348,7 @@ lfc_timer_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: Kea process was killed when attempting reconfiguration.\n" clean_exit 1 diff --git a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in index 834d74e4c6..45f4eec976 100755 --- a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in +++ b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in @@ -133,7 +133,7 @@ dynamic_reconfiguration_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + 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} @@ -173,7 +173,7 @@ dynamic_reconfiguration_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: Kea process was killed when attempting reconfiguration.\n" clean_exit 1 @@ -200,7 +200,7 @@ dynamic_reconfiguration_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: Kea process was killed when attempting reconfiguration.\n" clean_exit 1 @@ -242,7 +242,7 @@ shutdown_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + 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} @@ -311,7 +311,7 @@ lfc_timer_test() { # Check if it is still running. It could have terminated (e.g. as a result # of configuration failure). - get_pids ${bin} + 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} @@ -351,7 +351,7 @@ lfc_timer_test() { fi # Make sure the server is still operational. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 1 ]; then printf "ERROR: Kea process was killed when attempting reconfiguration.\n" clean_exit 1 diff --git a/src/bin/keactrl/tests/keactrl_tests.sh.in b/src/bin/keactrl/tests/keactrl_tests.sh.in index ff1623738c..748b984654 100644 --- a/src/bin/keactrl/tests/keactrl_tests.sh.in +++ b/src/bin/keactrl/tests/keactrl_tests.sh.in @@ -20,8 +20,10 @@ # Set location of the keactrl. keactrl=@abs_top_builddir@/src/bin/keactrl/keactrl +# Name of the configuration file without its extension. +CFG_FILE_NAME="test_config" # A name of the configuration file to be used by Kea. -CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/test_config.json +CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/${CFG_FILE_NAME}.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. @@ -186,15 +188,15 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that all servers are running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -290,15 +292,15 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that all servers are running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -369,17 +371,17 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that DHCPv4 server is running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" # Make sure that DHCPv6 server is not running. - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure that D2 server is not running. - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -450,17 +452,17 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that DHCPv6 server is running. - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure that DHCPv4 server is not running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" # Make sure that D2 server is not running. - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -532,12 +534,12 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that DHCPv6 server is running. - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure that DHCPv4 server is not running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" @@ -577,17 +579,17 @@ Expected wait_for_message return %d, returned %d." # Make sure that DHCPv6 server is running. - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure that DHCPv4 server is running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" # Make sure that D2 server is running. - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -681,17 +683,17 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that DHCPv4 server is running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" # Make sure that DHCPv6 server is not running. - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure that D2 server is not running. - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 0 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -731,17 +733,17 @@ Expected wait_for_message return %d, returned %d." # Make sure that DHCPv6 server is running. - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure that DHCPv4 server is running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" # Make sure that D2 server is running. - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -858,15 +860,15 @@ Expected wait_for_message return %d, returned %d." sleep 3 # Make sure that both servers are running. - get_pids ${kea4_name} + get_pid ${kea4_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea4_name} process running, found %d processes running" - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -888,12 +890,12 @@ Expected wait_for_message return %d, returned %d." "Expected wait_for_server_down return %d, returned %d" # Make sure DHCPv6 server is still running - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${kea6_name} process running, found %d processes running" # Make sure D2 server is still running - get_pids ${kea6_name} + get_pid ${kea6_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" @@ -915,7 +917,7 @@ Expected wait_for_message return %d, returned %d." "Expected wait_for_server_down return %d, returned %d" # Make sure D2 server is still running - get_pids ${d2_name} + get_pid ${d2_name} assert_eq 1 ${_GET_PIDS_NUM} \ "Expected %d ${d2_name} process running, found %d processes running" diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index 6e20791707..4f83aeabd5 100644 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -170,6 +170,52 @@ set_logger() { export KEA_LOGGER_DESTINATION=${LOG_FILE} } +# PID file path is by default var/kea, but can be overriden by the +# environmental variable. +PID_FILE_PATH=@localstatedir@/@PACKAGE@/ +if [ ! -z ${KEA_PIDFILE_DIR} ]; then + PID_FILE_PATH="${KEA_PIDFILE_DIR}" +fi + +# Returns 1 if specified Kea process is running, 0 otherwise +# This function uses PID file to make this determination. +# Return values: +# _GET_PID: holds a PID if process is running +# _GET_PIDS_NUM: 1 if process running, 0 otherwise +get_pid() { + local proc_name=${1} # Process name + local cfg_file_name=${2} # Configuration file name without extension. + + # PID file name includes process name. The process name is required. + if [ -z ${proc_name} ]; then + test_lib_error "get_pid requires process name" + clean_exit 1 + fi + + # PID file name includes server configuration file name. For most of + # the tests it is 'test-config' (excluding .json extension). It is + # possible to specify custom name if required. + if [ -z ${cfg_file_name} ]; then + cfg_file_name="test_config" + fi + + # Get the absolute location of the PID file for the specified process + # name. + abs_pidfile_path="${PID_FILE_PATH}/${cfg_file_name}.${proc_name}.pid" + _GET_PID=0 + _GET_PIDS_NUM=0 + + # If the PID file exists, get the PID and see if the process is alive. + if [ -e ${abs_pidfile_path} ]; then + pid=$( cat $abs_pidfile_path ) + kill -0 ${pid} > /dev/null 2>&1 + if [ $? -eq 0 ]; then + _GET_PID=${pid} + _GET_PIDS_NUM=1 + fi + fi +} + # Returns the number of running process pids and the list of pids. # Return values: # _GET_PIDS: holds space separated list of pids. @@ -236,13 +282,12 @@ cleanup() { # of them if running. for proc_name in ${KEA_PROCS} do - 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 + get_pid ${proc_name} + # Shut down running Kea process. + if [ ${_GET_PIDS_NUM} -ne 0 ]; then + printf "Shutting down Kea proccess having pid %d.\n" ${_GET_PID} + kill -9 ${_GET_PID} + fi done # Remove temporary files. @@ -391,7 +436,7 @@ wait_for_server_down() { test_lib_info "wait_for_server_down ${proc_name}: " "skip-new-line" while [ ${loops} -le ${timeout} ]; do printf "." - get_pids ${proc_name} + get_pid ${proc_name} if [ ${_GET_PIDS_NUM} -eq 0 ]; then printf "\n" _WAIT_FOR_SERVER_DOWN=1 @@ -421,15 +466,15 @@ must be a number" clean_exit 1 fi # Get Kea pid. - get_pids ${proc_name} + get_pid ${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 fi - printf "Sending signal ${sig} to Kea process (pid=%s).\n" ${_GET_PIDS} + printf "Sending signal ${sig} to Kea process (pid=%s).\n" ${_GET_PID} # Actually send a signal. - kill -${sig} ${_GET_PIDS} + kill -${sig} ${_GET_PID} } # Verifies that a server is up running by its PID file @@ -537,7 +582,7 @@ logger_vars_test() { sleep 1 # Check if it is still running. It should have terminated. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 0 ]; then printf "ERROR: expected Kea process to not start. Found %d processes" printf " running.\n" ${_GET_PIDS_NUM} @@ -569,7 +614,7 @@ logger_vars_test() { sleep 1 # Check if it is still running. It should have terminated. - get_pids ${bin} + get_pid ${bin} if [ ${_GET_PIDS_NUM} -ne 0 ]; then printf "ERROR: expected Kea process to not start. Found %d processes" printf " running.\n" ${_GET_PIDS_NUM}