]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1961] centralize shell test preparation
authorAndrei Pavel <andrei@isc.org>
Mon, 5 Jul 2021 13:18:57 +0000 (16:18 +0300)
committerAndrei Pavel <andrei@isc.org>
Mon, 5 Jul 2021 13:18:57 +0000 (16:18 +0300)
12 files changed:
src/bin/admin/tests/memfile_tests.sh.in
src/bin/agent/tests/ca_process_tests.sh.in
src/bin/d2/tests/d2_process_tests.sh.in
src/bin/dhcp4/tests/dhcp4_process_tests.sh.in
src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
src/bin/keactrl/tests/keactrl_tests.sh.in
src/bin/netconf/tests/shtests/netconf_tests.sh.in
src/bin/shell/tests/Makefile.am
src/bin/shell/tests/basic_auth_tests.sh.in
src/bin/shell/tests/shell_process_tests.sh.in
src/bin/shell/tests/tls_ca_process_tests.sh.in
src/lib/testutils/dhcp_test_lib.sh.in

index 6591297ebfc7dac71211d2e3ceda25f7f37f3124..0fc3e6542f46d9e19ea7274c0039de21cb5670d3 100644 (file)
@@ -28,9 +28,7 @@ clean_up() {
     remove_if_exists \
         "${config_file-}" \
         "${csv-}" \
-        "${csv_2-}" \
-        "${KEA_LOCKFILE_DIR-}" \
-        "${KEA_PIDFILE_DIR-}"
+        "${csv_2-}"
 }
 
 # Print location of CSV file. Accepts 4 or 6 as parameter.
@@ -122,8 +120,6 @@ memfile_init_test() {
             clean_up
             clean_exit 1
         fi
-        mkdir -p "${KEA_LOCKFILE_DIR}"
-        mkdir -p "${KEA_PIDFILE_DIR}"
         start_kea_dhcp "${v}"
         # This assumes that the CSV creation + writing to CSV is atomic. Not
         # sure if it is, but if this ever fails on the comparison further below,
index dc9007a680ea12ab84e59089356e3b0422a3e661..b5331523ec86a841e2101afd05dfb846c8a9807e 100644 (file)
@@ -95,8 +95,6 @@ syntax_check_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}"
     # Check it
@@ -117,8 +115,6 @@ shutdown_test() {
     signum=${2}      # Signal number
     # Log the start of the test and print test name.
     test_start "${test_name}"
-    # Remove dangling D2 instances and remove log files.
-    cleanup
     # Create new configuration file.
     create_config "${CONFIG}"
     # Instruct Control Agent to log to the specific file.
index 9743fa1d3986c6e7ede0f72aeeccd06d032d8f11..99e6baf6063cb7849cd2afdd105137d7e42f3a72 100644 (file)
@@ -154,8 +154,6 @@ syntax_check_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}"
     # Check it
@@ -173,8 +171,6 @@ syntax_check_test() {
 dynamic_reconfiguration_test() {
     # Log the start of the test and print test name.
     test_start "dhcp_ddns.dynamic_reconfiguration"
-    # Remove dangling D2 instances and remove log files.
-    cleanup
     # Create new configuration file.
     create_config "${CONFIG}"
     # Instruct D2 to log to the specific file.
@@ -274,8 +270,6 @@ shutdown_test() {
     local signum=${2}       # Signal number
     # Log the start of the test and print test name.
     test_start "${test_name}"
-    # Remove dangling D2 instances and remove log files.
-    cleanup
     # Create new configuration file.
     create_config "${CONFIG}"
     # Instruct D2 to log to the specific file.
index 8e839fe8866b611b82fcc8dd117161255a4ae233..8cc8d93b6d9257d1991c188b534c2e052b60c511 100644 (file)
@@ -187,8 +187,6 @@ syntax_check_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}"
     # Check it
@@ -206,8 +204,6 @@ syntax_check_test() {
 dynamic_reconfiguration_test() {
     # Log the start of the test and print test name.
     test_start "dhcpv4_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.
@@ -314,8 +310,6 @@ shutdown_test() {
     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.
@@ -378,8 +372,6 @@ shutdown_test() {
 lfc_timer_test() {
     # Log the start of the test and print test name.
     test_start "dhcpv4_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 '%s' "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 3/g' \
index 5e5e6fc099ac74f2301e188b39580f3d18aa4ff9..1b134ed0c987b08079196b444c14f8543217cec8 100644 (file)
@@ -192,8 +192,6 @@ syntax_check_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}"
     # Check it
@@ -212,8 +210,6 @@ syntax_check_test() {
 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.
@@ -321,8 +317,6 @@ shutdown_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 new configuration file.
     create_config "${CONFIG}"
     # Instruct Kea to log to the specific file.
@@ -386,8 +380,6 @@ returned %d."
 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 '%s' "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 3/g' \
index 1fd5de65cc98c66e33849cd7d657d696538a409f..f4809a14d29080c4b381201b1a6a94f484310e22 100644 (file)
@@ -56,6 +56,7 @@ kea_dhcp6_config_file=${DHCP6_CFG_FILE}\n\
 kea_dhcp_ddns_config_file=${D2_CFG_FILE}\n\
 kea_ctrl_agent_config_file=${CA_CFG_FILE}\n\
 kea_netconf_config_file=${NC_CFG_FILE}"
+KEACTRL_BUILD_DIR="@abs_top_builddir@"
 # 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.
index af897a7506506c2606de856766bb99cfefd95624..bda7d34292db3b5e3335a33e52208cf7b168d037 100644 (file)
@@ -87,8 +87,6 @@ usage_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}"
@@ -111,8 +109,6 @@ no_argument_test() {
 
     # Log the start of the test and print test name.
     test_start "${test_name}"
-    # Remove dangling Kea instances and remove log files.
-    cleanup
 
     # Check it
     printf "Running command %s.\n" "\"${bin_path}/${bin}\""
@@ -137,8 +133,6 @@ syntax_check_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}"
     # Check it
@@ -159,8 +153,6 @@ shutdown_test() {
     signum=${2}      # Signal number
     # Log the start of the test and print test name.
     test_start "${test_name}"
-    # Remove dangling Netconf instances and remove log files.
-    cleanup
     # Create new configuration file.
     create_config "${CONFIG}"
     # Instruct Netconf Agent to log to the specific file.
index 4a2bcf16100a86b17e939c82b1f024d7309a7680..c1751ecf3d6081753cd5f6d5b570e5ac4f4f99f9 100644 (file)
@@ -1,5 +1,8 @@
 SUBDIRS = .
 
+# Needed by shell_unittest.py to access python modules like kea_conn.
+TESTS_ENVIRONMENT = PYTHONPATH="$(abs_top_srcdir)/src/bin/shell"
+
 # Python tests
 PYTESTS = shell_unittest.py
 
index 245900a15bb299b7965813e55970288495389b74..902f745cb4fbddb161390a3619819aeba571ca93 100644 (file)
@@ -92,9 +92,6 @@ shell_command_test() {
     # Log the start of the test and print test name.
     test_start "${test_name}"
 
-    # Remove any dangling CA instances and remove log files.
-    cleanup
-
     # Create new configuration file.
     create_config "${CONFIG}"
 
index 7de71755cea157b26fcf73920944fc3c93500348..a28936b9fdc594875c375681f542bf20021ac4d0 100644 (file)
@@ -70,9 +70,6 @@ shell_command_test() {
     # Log the start of the test and print test name.
     test_start "${test_name}"
 
-    # Remove any dangling CA instances and remove log files.
-    cleanup
-
     # Create new configuration file.
     create_config "${CONFIG}"
 
@@ -170,9 +167,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
-
     REPORTED_VERSION=$(${shell_bin_path}/${shell_bin} -v)
 
     if test "${REPORTED_VERSION}" = "${EXPECTED_VERSION}"; then
index ec57a0db3df803f154356d6616bbdef81a75e0a3..52ec3c57a525e4ff75574f9a1495e3970650724b 100644 (file)
@@ -121,9 +121,6 @@ list_commands_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}"
 
index f0a7544cb2b0c5d9c6f43fafdcb399b6ae88ab7e..4003fea4c43f6a6ab2bc24aae92f3bd0bc7a782e 100644 (file)
@@ -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.