]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[gitlab9] keactrl version command implemented
authorTomek Mrugalski <tomasz@isc.org>
Thu, 9 Aug 2018 10:26:34 +0000 (12:26 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 9 Aug 2018 10:26:34 +0000 (12:26 +0200)
src/bin/keactrl/keactrl.in
src/bin/keactrl/tests/keactrl_tests.sh.in

index f5fa27e0edd496fcbfc1936575ee89daf8204ea8..e6626afed3cb99090a0d5aced6cdebb5595043b6 100644 (file)
@@ -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}."
index 64b2c18312f78c7b8f3d2356b279b6e74a5e239a..f5a4cd4e382b7337b3f9058dc02b60e70e40809b 100644 (file)
@@ -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