Browse Source

[3785] Fixed the check kea.conf first for status

Francis Dupont 10 years ago
parent
commit
d965378d75
2 changed files with 41 additions and 12 deletions
  1. 24 11
      src/bin/keactrl/keactrl.in
  2. 17 1
      src/bin/keactrl/tests/keactrl_tests.sh.in

+ 24 - 11
src/bin/keactrl/keactrl.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
 #
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -164,6 +164,21 @@ run_conditional() {
     fi
 }
 
+### Functions testing the existence of the Kea config file
+
+# Check if the Kea configuration file location has been specified in the
+# keactrl configuration file. If not, it is a warning or a fatal error.
+check_kea_conf() {
+    local conf_file=${1} # Kea config file name.
+    if [ -z ${conf_file} ]; then
+        log_error "Configuration file for Kea not specified."
+        exit 1
+    elif [ ! -f ${conf_file} ]; then
+        log_error "Configuration file for Kea does not exist: ${conf_file}."
+        exit 1
+    fi
+}
+
 ### Script starts here ###
 
 # Configure logger to log messages into the file.
@@ -265,16 +280,6 @@ if [ -z ${dhcp_ddns} ]; then
     exit 1
 fi
 
-# Check if the Kea configuration file location has been specified in the
-# keactrl configuration file. If not, it is a fatal error.
-if [ -z ${kea_config_file} ]; then
-    log_error "Configuration file for Kea not specified."
-    exit 1
-elif [ ! -f ${kea_config_file} ]; then
-    log_error "Configuration file for Kea does not exist: ${kea_config_file}."
-    exit 1
-fi
-
 # dhcp4 and dhcp6 (=yes) indicate if we should start DHCPv4 and DHCPv6 server
 # respectively.
 dhcp4=$( printf "%s" ${dhcp4} | tr [:upper:] [:lower:] )
@@ -284,6 +289,8 @@ dhcp_ddns=$( printf "%s" ${dhcp_ddns} | tr [:upper:] [:lower:] )
 case ${command} in
     # Start the servers.
     start)
+        check_kea_conf ${kea_config_file}
+
         args="-c ${kea_config_file}"
 
         if [ "${kea_verbose}" = "yes" ]; then
@@ -300,6 +307,8 @@ case ${command} in
 
     # Stop running servers.
     stop)
+        check_kea_conf ${kea_config_file}
+
         # Stop all servers or servers specified from the command line.
         run_conditional "dhcp4" "send_signal 15 $(basename ${dhcp4_srv})" 0
         run_conditional "dhcp6" "send_signal 15 $(basename ${dhcp6_srv})" 0
@@ -309,6 +318,8 @@ case ${command} in
 
     # Reconfigure the servers.
     reload)
+        check_kea_conf ${kea_config_file}
+
         # Reconfigure all servers or servers specified from the command line.
         run_conditional "dhcp4" "send_signal 1 $(basename ${dhcp4_srv})" 0
         run_conditional "dhcp6" "send_signal 1 $(basename ${dhcp6_srv})" 0
@@ -340,6 +351,8 @@ case ${command} in
         printf "Kea configuration file: %s\n" ${kea_config_file}
         printf "keactrl configuration file: %s\n" ${keactrl_conf}
 
+        check_kea_conf ${kea_config_file}
+
         exit 0 ;;
 
     # No other commands are supported.

+ 17 - 1
src/bin/keactrl/tests/keactrl_tests.sh.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
 #
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -392,6 +392,22 @@ Expected wait_for_message return %d, returned %d."
     assert_string_contains "DHCP DDNS: inactive" "${output}" \
         "Expected keactrl status command return %s"
 
+    # Make sure that the status command no longer checks first config file
+    printf "Getting status without a Kea config file\n"
+    mv ${CFG_FILE} ${CFG_FILE}.saved
+    output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
+    ret=${?}
+    mv ${CFG_FILE}.saved ${CFG_FILE}
+    assert_eq 1 ${ret} "Expected keactrl to return %d, returned %d"
+    assert_string_contains "DHCPv4 server: active" "${output}" \
+        "Expected keactrl status command return %s"
+    assert_string_contains "DHCPv6 server: inactive" "${output}" \
+        "Expected keactrl status command return %s"
+    assert_string_contains "DHCP DDNS: inactive" "${output}" \
+        "Expected keactrl status command return %s"
+    assert_string_contains "Configuration file for Kea does not exist" \
+	"${output}" "Expected keactrl status command return %s"
+
     # Use keactrl stop to shutdown the servers.
     printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
     ${keactrl} stop -c ${KEACTRL_CFG_FILE}