"Fossies" - the Fresh Open Source Software Archive

Member "kea-1.6.2/src/bin/dhcp6/tests/dhcp6_process_tests.sh" (21 Feb 2020, 15694 Bytes) of package /linux/misc/kea-1.6.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "dhcp6_process_tests.sh": 1.6.1_vs_1.6.2.

    1 # Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
    2 #
    3 # This Source Code Form is subject to the terms of the Mozilla Public
    4 # License, v. 2.0. If a copy of the MPL was not distributed with this
    5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
    6 
    7 # Path to the temporary configuration file.
    8 CFG_FILE=/home/jenkins/workspace/kea-1.6/tarball-internal/kea/src/bin/dhcp6/tests/test_config.json
    9 # Path to the Kea log file.
   10 LOG_FILE=/home/jenkins/workspace/kea-1.6/tarball-internal/kea/src/bin/dhcp6/tests/test.log
   11 # Path to the Kea lease file.
   12 LEASE_FILE=/home/jenkins/workspace/kea-1.6/tarball-internal/kea/src/bin/dhcp6/tests/test_leases.csv
   13 # Expected version
   14 EXPECTED_VERSION="1.6.2"
   15 # Kea configuration to be stored in the configuration file.
   16 CONFIG="{
   17     \"Dhcp6\":
   18     {   \"interfaces-config\": {
   19           \"interfaces\": [ ]
   20         },
   21         \"server-id\": {
   22           \"type\": \"LLT\",
   23           \"persist\": false
   24         },
   25         \"preferred-lifetime\": 3000,
   26         \"valid-lifetime\": 4000,
   27         \"renew-timer\": 1000,
   28         \"rebind-timer\": 2000,
   29         \"lease-database\":
   30         {
   31             \"type\": \"memfile\",
   32             \"name\": \"$LEASE_FILE\",
   33             \"persist\": false,
   34             \"lfc-interval\": 0
   35         },
   36         \"subnet6\": [
   37         {
   38             \"subnet\": \"2001:db8:1::/64\",
   39             \"pools\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
   40         } ],
   41         \"dhcp-ddns\": {
   42             \"enable-updates\": true,
   43             \"qualifying-suffix\": \"\"
   44         }
   45     },
   46 
   47     \"Logging\":
   48     {
   49         \"loggers\": [
   50         {
   51             \"name\": \"kea-dhcp6\",
   52             \"output_options\": [
   53                 {
   54                     \"output\": \"$LOG_FILE\"
   55                 }
   56             ],
   57             \"severity\": \"INFO\"
   58         }
   59         ]
   60     }
   61 }"
   62 # Invalid configuration (syntax error) to check that Kea can check syntax.
   63 # This config has following errors:
   64 # - it should be interfaces-config/interfaces, not interfaces
   65 # - it should be subnet6/pools, no subnet6/pool
   66 CONFIG_BAD_SYNTAX="{
   67     \"Dhcp6\":
   68     {
   69         \"interfaces\": [ ],
   70         \"preferred-lifetime\": 3000,
   71         \"valid-lifetime\": 4000,
   72         \"renew-timer\": 1000,
   73         \"rebind-timer\": 2000,
   74         \"lease-database\":
   75         {
   76             \"type\": \"memfile\",
   77             \"persist\": false
   78         },
   79         \"subnet6\": [
   80         {
   81             \"subnet\": \"2001:db8:1::/64\",
   82             \"pool\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
   83         } ]
   84     },
   85 
   86     \"Logging\":
   87     {
   88         \"loggers\": [
   89         {
   90             \"name\": \"kea-dhcp6\",
   91             \"output_options\": [
   92                 {
   93                     \"output\": \"$LOG_FILE\"
   94                 }
   95             ],
   96             \"severity\": \"INFO\"
   97         }
   98         ]
   99     }
  100 }"
  101 # Invalid configuration (negative preferred-lifetime) to check that Kea
  102 # gracefully handles reconfiguration errors.
  103 CONFIG_INVALID="{
  104     \"Dhcp6\":
  105     {
  106         \"interfaces-config\": {
  107           \"interfaces\": [ ]
  108         },
  109         \"preferred-lifetime\": -3,
  110         \"valid-lifetime\": 4000,
  111         \"renew-timer\": 1000,
  112         \"rebind-timer\": 2000,
  113         \"lease-database\":
  114         {
  115             \"type\": \"memfile\",
  116             \"persist\": false
  117         },
  118         \"subnet6\": [
  119         {
  120             \"subnet\": \"2001:db8:1::/64\",
  121             \"pool\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
  122         } ]
  123     },
  124 
  125     \"Logging\":
  126     {
  127         \"loggers\": [
  128         {
  129             \"name\": \"kea-dhcp6\",
  130             \"output_options\": [
  131                 {
  132                     \"output\": \"$LOG_FILE\"
  133                 }
  134             ],
  135             \"severity\": \"INFO\"
  136         }
  137         ]
  138     }
  139 }"
  140 
  141 # This config has bad pool values. The pool it out of scope for the subnet
  142 # it is defined in. Syntactically the config is correct, though.
  143 CONFIG_BAD_VALUES="{
  144     \"Dhcp6\":
  145     {   \"interfaces-config\": {
  146           \"interfaces\": [ ]
  147         },
  148         \"server-id\": {
  149           \"type\": \"LLT\",
  150           \"persist\": false
  151         },
  152         \"preferred-lifetime\": 3000,
  153         \"valid-lifetime\": 4000,
  154         \"renew-timer\": 1000,
  155         \"rebind-timer\": 2000,
  156         \"lease-database\":
  157         {
  158             \"type\": \"memfile\",
  159             \"name\": \"$LEASE_FILE\",
  160             \"persist\": false,
  161             \"lfc-interval\": 0
  162         },
  163         \"subnet6\": [
  164         {
  165             \"subnet\": \"2001:db8::/64\",
  166             \"pools\": [ { \"pool\": \"3000::-3000::ffff\" } ]
  167         } ],
  168         \"dhcp-ddns\": {
  169             \"enable-updates\": true,
  170             \"qualifying-suffix\": \"\"
  171         }
  172     }
  173 }"
  174 
  175 
  176 # Set the location of the executable.
  177 bin="kea-dhcp6"
  178 bin_path=/home/jenkins/workspace/kea-1.6/tarball-internal/kea/src/bin/dhcp6
  179 
  180 # Import common test library.
  181 . /home/jenkins/workspace/kea-1.6/tarball-internal/kea/src/lib/testutils/dhcp_test_lib.sh
  182 
  183 # This test verifies that syntax checking works properly. This function
  184 # requires 3 parameters:
  185 # testname
  186 # config - string with a content of the config (will be written to a file)
  187 # exp_code - expected exit code returned by kea (0 - success, 1 - failure)
  188 syntax_check_test() {
  189     local TESTNAME="${1}"
  190     local CONFIG="${2}"
  191     local EXP_CODE="${3}"
  192 
  193     # Log the start of the test and print test name.
  194     test_start $TESTNAME
  195     # Remove dangling Kea instances and remove log files.
  196     cleanup
  197     # Create correct configuration file.
  198     create_config "${CONFIG}"
  199     # Check it
  200     printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\""
  201     ${bin_path}/${bin} -t ${CFG_FILE}
  202     exit_code=$?
  203     if [ ${exit_code} -ne $EXP_CODE ]; then
  204         printf "ERROR: expected exit code $EXP_CODE, got ${exit_code}\n"
  205         clean_exit 1
  206     fi
  207 
  208     test_finish 0
  209 }
  210 
  211 # This test verifies that DHCPv6 can be reconfigured with a SIGHUP signal.
  212 dynamic_reconfiguration_test() {
  213     # Log the start of the test and print test name.
  214     test_start "dhcpv6_srv.dynamic_reconfiguration"
  215     # Remove dangling Kea instances and remove log files.
  216     cleanup
  217     # Create new configuration file.
  218     create_config "${CONFIG}"
  219     # Instruct Kea to log to the specific file.
  220     set_logger
  221     # Start Kea.
  222     start_kea ${bin_path}/${bin}
  223     # Wait up to 20s for Kea to start.
  224     wait_for_kea 20
  225     if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  226         printf "ERROR: timeout waiting for Kea to start.\n"
  227         clean_exit 1
  228     fi
  229 
  230     # Check if it is still running. It could have terminated (e.g. as a result
  231     # of configuration failure).
  232     get_pid ${bin}
  233     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  234         printf "ERROR: expected one Kea process to be started. Found %d processes\
  235  started.\n" ${_GET_PIDS_NUM}
  236         clean_exit 1
  237     fi
  238 
  239     # Check in the log file, how many times server has been configured. It should
  240     # be just once on startup.
  241     get_reconfigs
  242     if [ ${_GET_RECONFIGS} -ne 1 ]; then
  243         printf "ERROR: server hasn't been configured.\n"
  244         clean_exit 1
  245     else
  246         printf "Server successfully configured.\n"
  247     fi
  248 
  249     # Now use invalid configuration.
  250     create_config "${CONFIG_INVALID}"
  251 
  252     # Try to reconfigure by sending SIGHUP
  253     send_signal 1 ${bin}
  254 
  255     # The configuration should fail and the error message should be there.
  256     wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
  257 
  258     # After receiving SIGHUP the server should try to reconfigure itself.
  259     # The configuration provided is invalid so it should result in
  260     # reconfiguration failure but the server should still be running.
  261     get_reconfigs
  262     if [ ${_GET_RECONFIGS} -ne 1 ]; then
  263         printf "ERROR: server has been reconfigured despite bogus configuration.\n"
  264         clean_exit 1
  265     elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
  266         printf "ERROR: server did not report reconfiguration error despite attempt\
  267  to configure it with invalid configuration.\n"
  268         clean_exit 1
  269     fi
  270 
  271     # Make sure the server is still operational.
  272     get_pid ${bin}
  273     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  274         printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  275         clean_exit 1
  276     fi
  277 
  278     # Restore the good configuration.
  279     create_config "${CONFIG}"
  280 
  281     # Reconfigure the server with SIGHUP.
  282     send_signal 1 ${bin}
  283 
  284     # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
  285     # Wait for it up to 10s.
  286     wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  287 
  288     # After receiving SIGHUP the server should get reconfigured and the
  289     # reconfiguration should be noted in the log file. We should now
  290     # have two configurations logged in the log file.
  291     if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  292         printf "ERROR: server hasn't been reconfigured.\n"
  293         clean_exit 1
  294     else
  295         printf "Server successfully reconfigured.\n"
  296     fi
  297 
  298     # Make sure the server is still operational.
  299     get_pid ${bin}
  300     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  301         printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  302         clean_exit 1
  303     fi
  304 
  305     # When the server receives a signal the call to select() function is
  306     # interrupted. This should not be logged as an error.
  307     get_log_messages "DHCP6_PACKET_RECEIVE_FAIL"
  308     assert_eq 0 ${_GET_LOG_MESSAGES} \
  309         "Expected get_log_messages DHCP6_PACKET_RECEIVE_FAIL return %d, \
  310 returned %d."
  311 
  312     # All ok. Shut down Kea and exit.
  313     test_finish 0
  314 }
  315 
  316 # This test verifies that DHCPv6 server is shut down gracefully when it
  317 # receives a SIGINT or SIGTERM signal.
  318 shutdown_test() {
  319     test_name=${1}  # Test name
  320     signum=${2}      # Signal number
  321 
  322     # Log the start of the test and print test name.
  323     test_start ${test_name}
  324     # Remove dangling Kea instances and remove log files.
  325     cleanup
  326     # Create new configuration file.
  327     create_config "${CONFIG}"
  328     # Instruct Kea to log to the specific file.
  329     set_logger
  330     # Start Kea.
  331     start_kea ${bin_path}/${bin}
  332     # Wait up to 20s for Kea to start.
  333     wait_for_kea 20
  334     if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  335         printf "ERROR: timeout waiting for Kea to start.\n"
  336         clean_exit 1
  337     fi
  338 
  339     # Check if it is still running. It could have terminated (e.g. as a result
  340     # of configuration failure).
  341     get_pid ${bin}
  342     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  343         printf "ERROR: expected one Kea process to be started. Found %d processes\
  344  started.\n" ${_GET_PIDS_NUM}
  345         clean_exit 1
  346     fi
  347 
  348     # Check in the log file, how many times server has been configured. It should
  349     # be just once on startup.
  350     get_reconfigs
  351     if [ ${_GET_RECONFIGS} -ne 1 ]; then
  352         printf "ERROR: server hasn't been configured.\n"
  353         clean_exit 1
  354     else
  355         printf "Server successfully configured.\n"
  356     fi
  357 
  358     # Send signal to Kea (SIGTERM, SIGINT etc.)
  359     send_signal ${signum} ${bin}
  360 
  361     # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  362     # should be recorded in the log file with the appropriate message.
  363     wait_for_message 10 "DHCP6_SHUTDOWN" 1
  364     if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  365         printf "ERROR: Server did not record shutdown in the log.\n"
  366         clean_exit 1
  367     fi
  368 
  369     # Make sure the server is down.
  370     wait_for_server_down 5 ${bin}
  371     assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  372         "Expected wait_for_server_down return %d, returned %d"
  373 
  374     # When the server receives a signal the call to select() function is
  375     # interrupted. This should not be logged as an error.
  376     get_log_messages "DHCP6_PACKET_RECEIVE_FAIL"
  377     assert_eq 0 ${_GET_LOG_MESSAGES} \
  378         "Expected get_log_messages DHCP6_PACKET_RECEIVE_FAIL return %d, \
  379 returned %d."
  380 
  381     test_finish 0
  382 }
  383 
  384 # This test verifies that DHCPv6 can be configured to run lease file cleanup
  385 # periodically.
  386 lfc_timer_test() {
  387     # Log the start of the test and print test name.
  388     test_start "dhcpv6_srv.lfc_timer_test"
  389     # Remove dangling Kea instances and remove log files.
  390     cleanup
  391     # Create a configuration with the LFC enabled, by replacing the section
  392     # with the lfc-interval and persist parameters.
  393     LFC_CONFIG=$(printf "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 3/g' \
  394                         | sed -e 's/\"persist\": false,/\"persist\": true,/g')
  395     # Create new configuration file.
  396     create_config "${LFC_CONFIG}"
  397     # Instruct Kea to log to the specific file.
  398     set_logger
  399     # Start Kea.
  400     start_kea ${bin_path}/${bin}
  401     # Wait up to 20s for Kea to start.
  402     wait_for_kea 20
  403     if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
  404         printf "ERROR: timeout waiting for Kea to start.\n"
  405         clean_exit 1
  406     fi
  407 
  408     # Check if it is still running. It could have terminated (e.g. as a result
  409     # of configuration failure).
  410     get_pid ${bin}
  411     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  412         printf "ERROR: expected one Kea process to be started. Found %d processes\
  413  started.\n" ${_GET_PIDS_NUM}
  414         clean_exit 1
  415     fi
  416 
  417     # Check if Kea emits the log message indicating that LFC is started.
  418     wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 1
  419     if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  420         printf "ERROR: Server did not execute LFC.\n"
  421         clean_exit 1
  422     fi
  423 
  424     # Give it a short time to run.
  425     sleep 1
  426 
  427     # Modify the interval.
  428     LFC_CONFIG=$(printf "${LFC_CONFIG}" | sed -e 's/\"lfc-interval\": 3/\"lfc-interval\": 4/g')
  429     # Create new configuration file.
  430     create_config "${LFC_CONFIG}"
  431 
  432     # Reconfigure the server with SIGHUP.
  433     send_signal 1 ${bin}
  434 
  435     # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
  436     # Wait for it up to 10s.
  437     wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  438 
  439     # After receiving SIGHUP the server should get reconfigured and the
  440     # reconfiguration should be noted in the log file. We should now
  441     # have two configurations logged in the log file.
  442     if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  443         printf "ERROR: server hasn't been reconfigured.\n"
  444         clean_exit 1
  445     else
  446         printf "Server successfully reconfigured.\n"
  447     fi
  448 
  449     # Make sure the server is still operational.
  450     get_pid ${bin}
  451     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
  452         printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
  453         clean_exit 1
  454     fi
  455 
  456     # Wait for the LFC to run the second time.
  457     wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 2
  458     if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  459         printf "ERROR: Server did not execute LFC.\n"
  460         clean_exit 1
  461     fi
  462 
  463     # Send signal to Kea SIGTERM
  464     send_signal 15 ${bin}
  465 
  466     # Wait up to 10s for the server's graceful shutdown. The graceful shut down
  467     # should be recorded in the log file with the appropriate message.
  468     wait_for_message 10 "DHCP6_SHUTDOWN" 1
  469     if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
  470         printf "ERROR: Server did not record shutdown in the log.\n"
  471         clean_exit 1
  472     fi
  473 
  474     # Make sure the server is down.
  475     wait_for_server_down 5 ${bin}
  476     assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  477         "Expected wait_for_server_down return %d, returned %d"
  478 
  479     # All ok. Shut down Kea and exit.
  480     test_finish 0
  481 }
  482 
  483 server_pid_file_test "${CONFIG}" DHCP6_ALREADY_RUNNING
  484 dynamic_reconfiguration_test
  485 shutdown_test "dhcpv6.sigterm_test" 15
  486 shutdown_test "dhcpv6.sigint_test" 2
  487 version_test "dhcpv6.version"
  488 logger_vars_test "dhcpv6.variables"
  489 lfc_timer_test
  490 syntax_check_test "dhcpv6.syntax_check_success" "${CONFIG}" 0
  491 syntax_check_test "dhcpv6.syntax_check_bad_syntax" "${CONFIG_BAD_SYNTAX}" 1
  492 syntax_check_test "dhcpv6.syntax_check_bad_values" "${CONFIG_BAD_VALUES}" 1