From: Tomek Mrugalski Date: Thu, 9 Aug 2018 10:26:34 +0000 (+0200) Subject: [gitlab9] keactrl version command implemented X-Git-Tag: gitlab29-base~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=531a33c8478b227591eb53d7ed371d37eed0d001;p=thirdparty%2Fkea.git [gitlab9] keactrl version command implemented --- diff --git a/src/bin/keactrl/keactrl.in b/src/bin/keactrl/keactrl.in index f5fa27e0ed..e6626afed3 100644 --- a/src/bin/keactrl/keactrl.in +++ b/src/bin/keactrl/keactrl.in @@ -55,7 +55,7 @@ is_in_list() { # Prints keactrl usage. usage() { printf "usage is %s command [-c keactrl-config-file] [-s server[,server,..]]\n" $( basename ${0} ) - printf "commands: start stop reload status\n" + printf "commands: start stop reload status version\n" } ### Functions managing Kea processes ### @@ -211,6 +211,24 @@ to process ${proc_name}, PID ${_pid}.\n" fi } +# Print Kea daemon verison +print_version() { + name=${1} + binary_path=${2} + + if [ -e ${binary_path} ]; then + ver=`${binary_path} -v` + if [ $? -ne 0 ]; then + log_error "Error checking version of binary file: ${binary_path}" + fi + else + # No file, means no pid + ver="unknown, ${binary_path} missing"; + fi + + echo "${name}: ${ver}" +} + ### Functions testing the existence of the Kea config file # Check if the Kea configuration file location has been specified in the @@ -289,7 +307,7 @@ if test "${command}" = "-v" || test "${command}" = "--version" ; then exit 0 fi -is_in_list "${command}" "start stop reload status" +is_in_list "${command}" "start stop reload status version" if [ ${_inlist} -eq 0 ]; then log_error "invalid command: ${command}" exit 1 @@ -465,6 +483,15 @@ ${args}" 1 exit 0 ;; + version) + echo "keactrl: ${VERSION}" + run_conditional "dhcp4" "print_version kea-dhcp4 ${dhcp4_srv}" 0 + run_conditional "dhcp6" "print_version kea-dhcp6 ${dhcp6_srv}" 0 + run_conditional "dhcp_ddns" "print_version kea-dhcp-ddns ${dhcp_ddns_srv}" 0 + run_conditional "ctrl_agent" "print_version kea-ctrl-agent ${ctrl_agent_srv}" 0 + + exit 0 ;; + # No other commands are supported. *) log_error "Invalid command: ${command}." diff --git a/src/bin/keactrl/tests/keactrl_tests.sh.in b/src/bin/keactrl/tests/keactrl_tests.sh.in index 64b2c18312..f5a4cd4e38 100644 --- a/src/bin/keactrl/tests/keactrl_tests.sh.in +++ b/src/bin/keactrl/tests/keactrl_tests.sh.in @@ -1083,9 +1083,8 @@ status_no_config_test() { test_finish 0 } -# This test checks version reported by kea-admin. It has nothing to do -# with memfile, but that is the only test file that is always ran, -# so decided to put the generic test here. +# This test checks version reported by keactrl. This reports the +# version of the keactrl tool itself. version_test() { test_start "version" @@ -1107,8 +1106,33 @@ version_test() { test_finish 0 } +# This test uses version command, which reports version of the keactrl +# tool itself, but also all the daemons. +version_command_test() { + test_start "version" + + # This is what we expect to get. We need to run it through echo + # to convert \n to actual LF (0xa). + exp="keactrl: @PACKAGE_VERSION@\n" + exp+="kea-dhcp4: @PACKAGE_VERSION@\n" + exp+="kea-dhcp6: @PACKAGE_VERSION@\n" + exp+="kea-dhcp-ddns: @PACKAGE_VERSION@\n" + exp+="kea-ctrl-agent: @PACKAGE_VERSION@" + EXPECTED_RESP=$(echo -e $exp) + + # Let's use short version: + reported_version=$(${keactrl} version) + + assert_str_eq "${EXPECTED_RESP}" "${reported_version}" \ + "Expected keactrl version to report %s, but it reported %s" + + test_finish 0 +} + + version_test +version_command_test start_all_servers_no_verbose_test start_all_servers_verbose_test start_v4_server_test