From: Francis Dupont Date: Sat, 11 Mar 2017 13:02:12 +0000 (+0100) Subject: [5152] Finished (added system tests) X-Git-Tag: trac102b_base~3^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f2ade1993e2beaab4d90b52e97973c360b9cf34;p=thirdparty%2Fkea.git [5152] Finished (added system tests) --- diff --git a/src/bin/agent/tests/ca_process_tests.sh.in b/src/bin/agent/tests/ca_process_tests.sh.in index e4f8902160..498e600fa8 100644 --- a/src/bin/agent/tests/ca_process_tests.sh.in +++ b/src/bin/agent/tests/ca_process_tests.sh.in @@ -1,4 +1,4 @@ -# Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -34,12 +34,55 @@ CONFIG="{ } }" +# Invalid configuration (syntax error) to check that Kea can check syntax. +CONFIG_BAD_SYNTAX="{ + \"Control-agent\": + { + \"http-port\": BOGUS + } +}" + +# Invalid configuration (out of range port) to check that Kea can check syntax. +CONFIG_BAD_VALUE="{ + \"Control-agent\": + { + \"http-port\": 80000 + } +}" + bin="kea-ctrl-agent" bin_path=@abs_top_builddir@/src/bin/agent # Import common test library. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh +# This test verifies that syntax checking works properly. This function +# requires 3 parameters: +# testname +# config - string with a content of the config (will be written to a file) +# exp_code - expected exit code returned by kea (0 - success, 1 - failure) +syntax_check_test() { + local TESTNAME="${1}" + local CONFIG="${2}" + local EXP_CODE="${3}" + + # Log the start of the test and print test name. + test_start $TESTNAME + # Remove dangling Kea instances and remove log files. + cleanup + # Create correct configuration file. + create_config "${CONFIG}" + # Check it + printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" + ${bin_path}/${bin} -t ${CFG_FILE} + exit_code=$? + if [ ${exit_code} -ne $EXP_CODE ]; then + printf "ERROR: expected exit code ${EXP_CODE}, got ${exit_code}\n" + clean_exit 1 + fi + test_finish 0 +} + # This test verifies that Control Agent is shut down gracefully when it # receives a SIGINT or SIGTERM signal. shutdown_test() { @@ -102,4 +145,6 @@ shutdown_test() { server_pid_file_test "${CONFIG}" DCTL_ALREADY_RUNNING shutdown_test "ctrl-agent.sigterm_test" 15 shutdown_test "ctrl-agent.sigint_test" 2 - +syntax_check_test "ctrl-agent.syntax_check_success" "${CONFIG}" 0 +syntax_check_test "ctrl-agent.syntax_check_bad_syntax" "${CONFIG_BAD_SYNTAX}" 1 +syntax_check_test "ctrl-agent.syntax_check_bad_values" "${CONFIG_BAD_VALUE}" 1 diff --git a/src/bin/d2/tests/d2_process_tests.sh.in b/src/bin/d2/tests/d2_process_tests.sh.in index 61127315c9..6927dac2b8 100644 --- a/src/bin/d2/tests/d2_process_tests.sh.in +++ b/src/bin/d2/tests/d2_process_tests.sh.in @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -36,7 +36,59 @@ CONFIG="{ } }" -# Invalid configuration (invalid port) to check that D2 +# Invalid configuration (syntax error) to check that Kea can check syntax. +CONFIG_BAD_SYNTAX="{ + \"DhcpDdns\": + { + \"ip-address\": \"127.0.0.1\", + \"port\": BOGUS, + \"tsig-keys\": [], + \"forward-ddns\" : {}, + \"reverse-ddns\" : {} + }, + \"Logging\": + { + \"loggers\": [ + { + \"name\": \"kea-dhcp-ddns\", + \"output_options\": [ + { + \"output\": \"$LOG_FILE\" + } + ], + \"severity\": \"INFO\" + } + ] + } +}" + +# Invalid configuration (out of range port) to check that Kea can check syntax. +CONFIG_BAD_VALUE="{ + \"DhcpDdns\": + { + \"ip-address\": \"127.0.0.1\", + \"port\": 80000, + \"tsig-keys\": [], + \"forward-ddns\" : {}, + \"reverse-ddns\" : {} + }, + \"Logging\": + { + \"loggers\": [ + { + \"name\": \"kea-dhcp-ddns\", + \"output_options\": [ + { + \"output\": \"$LOG_FILE\" + } + ], + \"severity\": \"INFO\" + } + ] + } +}" + +# Invalid value configuration (invalid port) to check that D2 # gracefully handles reconfiguration errors. CONFIG_INVALID="{ \"DhcpDdns\": @@ -70,6 +122,33 @@ bin_path=@abs_top_builddir@/src/bin/d2 # Import common test library. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh +# This test verifies that syntax checking works properly. This function +# requires 3 parameters: +# testname +# config - string with a content of the config (will be written to a file) +# exp_code - expected exit code returned by kea (0 - success, 1 - failure) +syntax_check_test() { + local TESTNAME="${1}" + local CONFIG="${2}" + local EXP_CODE="${3}" + + # Log the start of the test and print test name. + test_start $TESTNAME + # Remove dangling Kea instances and remove log files. + cleanup + # Create correct configuration file. + create_config "${CONFIG}" + # Check it + printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" + ${bin_path}/${bin} -t ${CFG_FILE} + exit_code=$? + if [ ${exit_code} -ne $EXP_CODE ]; then + printf "ERROR: expected exit code ${EXP_CODE}, got ${exit_code}\n" + clean_exit 1 + fi + test_finish 0 +} + # This test verifies that D2 can be reconfigured with a SIGHUP signal. dynamic_reconfiguration_test() { # Log the start of the test and print test name. @@ -233,3 +312,6 @@ shutdown_test "dhcp-ddns.sigterm_test" 15 shutdown_test "dhcp-ddns.sigint_test" 2 version_test "dhcp-ddns.version" logger_vars_test "dhcp-ddns.variables" +syntax_check_test "dhcp-ddns.syntax_check_success" "${CONFIG}" 0 +syntax_check_test "dhcp-ddns.syntax_check_bad_syntax" "${CONFIG_BAD_SYNTAX}" 1 +syntax_check_test "dhcp-ddns.syntax_check_bad_values" "${CONFIG_BAD_VALUE}" 1 diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 5097ff3473..cbf0fe811b 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -530,7 +530,9 @@ DControllerBase::usage(const std::string & text) << std::endl << " -d: optional, verbose output " << std::endl << " -c : mandatory," - << " specifies name of configuration file " << std::endl; + << " specify name of configuration file" << std::endl + << " -t : check the" + << " configuration file and exit" << std::endl; // add any derivation specific usage std::cerr << getUsageText() << std::endl;