# 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 ###
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
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
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}."
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"
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