diff options
author | Andrei Pavel <andrei@isc.org> | 2021-07-05 15:18:57 +0200 |
---|---|---|
committer | Andrei Pavel <andrei@isc.org> | 2021-07-05 15:18:57 +0200 |
commit | 55fe8df497b03b93220d4e6379e1f1a857fc6fc0 (patch) | |
tree | 6175ccaa421cc30b0130767f1836c8e7a526d2e0 /src/lib/testutils | |
parent | [#1920] Fix in PgSQL tests (diff) | |
download | kea-55fe8df497b03b93220d4e6379e1f1a857fc6fc0.tar.xz kea-55fe8df497b03b93220d4e6379e1f1a857fc6fc0.zip |
[#1961] centralize shell test preparation
Diffstat (limited to 'src/lib/testutils')
-rw-r--r-- | src/lib/testutils/dhcp_test_lib.sh.in | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index f0a7544cb2..4003fea4c4 100644 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -234,9 +234,18 @@ test_start() { # Announce test start. printf "${green-}[ RUN ]${reset-} %s\n" "${TEST_NAME}" - # Reset variables that are used in error reporting. - ERROR= - OUTPUT= + # Remove dangling Kea instances and remove log files. + cleanup + + # Make sure lockfile and pidfile directories exist. They are used in some + # tests. + mkdir -p "${KEA_LOCKFILE_DIR}" + # There are certain tests that intentionally run without a KEA_PIDFILE_DIR + # e.g. keactrl.status_test. Only create the directory if we test requires + # one. + if test -n "${KEA_PIDFILE_DIR+x}"; then + mkdir -p "${KEA_PIDFILE_DIR}" + fi # Start timer in milliseconds. START_TIME=$(get_current_time) @@ -256,7 +265,6 @@ test_finish() { report_test_result_in_xml "${TEST_NAME}" "${exit_code}" "${duration}" if [ "${exit_code}" -eq 0 ]; then - cleanup printf "${green-}[ OK ]${reset-} %s\n" "${TEST_NAME}" else # Dump log file for debugging purposes if specified and exists. @@ -266,10 +274,12 @@ test_finish() { printf 'Log file dump:\n' cat "${LOG_FILE}" fi - cleanup printf "${red-}[ FAILED ]${reset-} %s\n" "${TEST_NAME}" fi + # Remove dangling Kea instances and log files. + cleanup + # Reset traps. traps_off @@ -436,12 +446,24 @@ get_pid() { local proc_name=${1-} # Process name local cfg_file_name=${2-} # Configuration file name without extension. + # Reset PID results. + _GET_PID=0 + _GET_PIDS_NUM=0 + # 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 + # There are certain tests that intentionally run without a KEA_PIDFILE_DIR + # e.g. keactrl.status_test. We can't get the PID if KEA_PIDFILE_DIR is not + # defined. In this case, this function is reporting process not running + # (_GET_PID == 0). + if test -z "${KEA_PIDFILE_DIR+x}"; then + return + 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. @@ -452,8 +474,6 @@ get_pid() { # Get the absolute location of the PID file for the specified process # name. abs_pidfile_path="${KEA_PIDFILE_DIR}/${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. pid=$(cat "${abs_pidfile_path}" 2> /dev/null || true) @@ -638,6 +658,8 @@ cleanup() { "${DHCP4_CFG_FILE-}" \ "${DHCP6_CFG_FILE-}" \ "${KEACTRL_CFG_FILE-}" \ + "${KEA_LOCKFILE_DIR-}" \ + "${KEA_PIDFILE_DIR-}" \ "${NC_CFG_FILE-}" # Use ${var+x} to test if ${var} is defined. @@ -897,9 +919,6 @@ version_test() { # Log the start of the test and print test name. test_start "${test_name}" - # Remove dangling Kea instances and remove log files. - cleanup - # If set to anything other than empty string, reset it to the long version # parameter. if test -n "${long_version}"; then @@ -931,8 +950,6 @@ logger_vars_test() { # Log the start of the test and print test name. test_start "${test_name}" - # Remove dangling Kea instances and remove log files. - cleanup # Create bogus configuration file. We don't really want the server to start, # just want it to log something and die. Empty config is an easy way to @@ -1023,8 +1040,6 @@ server_pid_file_test() { # Log the start of the test and print test name. test_start "${bin}.server_pid_file_test" - # Remove dangling DHCP4 instances and remove log files. - cleanup # Create new configuration file. create_config "${CONFIG}" # Instruct server to log to the specific file. @@ -1072,8 +1087,6 @@ password_redact_test() { # Log the start of the test and print test name. test_start "${test_name}" - # Remove dangling Kea instances and remove log files. - cleanup # Create correct configuration file. create_config "${config}" # Instruct Control Agent to log to the specific file. |