Browse Source

[3422] Fixed a few issues in the keactrl.

Marcin Siodelski 11 years ago
parent
commit
0479498868
2 changed files with 347 additions and 5 deletions
  1. 3 3
      src/bin/keactrl/keactrl.in
  2. 344 2
      src/bin/keactrl/tests/keactrl_tests.sh.in

+ 3 - 3
src/bin/keactrl/keactrl.in

@@ -45,7 +45,7 @@ get_pids() {
     _get_pids=$(ps axwwo pid,command | grep ${proc_name} | grep -v grep \
         | awk '{print $1}')
     # Return the number of PIDs.
-    _get_pids_num=$(printf "%s" "${pids}" | wc -w | awk '{print $1}')
+    _get_pids_num=$(printf "%s" "${_get_pids}" | wc -w | awk '{print $1}')
 }
 
 # Checks if the specified process is running. Internally it calls get_pids
@@ -69,7 +69,7 @@ send_signal() {
     get_pids ${proc_name}
     # If no processes running, there is no process we can send the signal
     # to. This is not neccessarily an error.
-    if [ -z get_pids ]; then
+    if [ -z ${_get_pids} ]; then
         log_info "Skip sending signal ${sig} to process ${proc_name}: \
 process is not running\n"
         return
@@ -89,7 +89,7 @@ start_server() {
     # Extract the name of the binary from the path.
     local binary_name=$(basename ${binary_path})
     # Use the binary name to check if the process is already running.
-    check_running $(basename ${binary_name})
+    check_running ${binary_name}
     # If process is running, don't start another one. Just log a message.
     if [ ${_running} -ne 0 ]; then
         log_info "Skip starting ${binary_name} \

+ 344 - 2
src/bin/keactrl/tests/keactrl_tests.sh.in

@@ -72,7 +72,7 @@ config="{
 # shut down.
 start_both_servers_test() {
     # Test name.
-    TEST_NAME="keactrl.startStop"
+    TEST_NAME="keactrl.start_both_servers_test"
     # Create configuration file for keactrl. This configuration enables
     # both DHCPv4 and DHCPv6 server.
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=yes\n"
@@ -134,7 +134,243 @@ Expected wait_for_message return %d, returned %d."
     assert_eq 1 ${_WAIT_FOR_MESSAGE} \
         "Timeout waiting for ${kea4_name} to shutdown. \
 Expected wait_for_message return %d, returned %d."
-    
+
+    # Make sure that the servers are down.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} processes running, found %d processes running"
+
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} processes running, found %d processes running"
+
+    cleanup
+}
+
+# This test checks that only DHCPv4 server can be started and that the DHCPv6
+# server is not started.
+start_v4_server_test() {
+    # Test name.
+    TEST_NAME="keactrl.start_v4_server_test"
+    # Create configuration file for keactrl. This configuration enables
+    # DHCPv4 server but disables DHCPv6 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=no\n"
+
+    test_start
+
+    # Create configuration file for Kea and for keactrl.
+    create_config "${config}"
+    create_keactrl_config "${keactrl_config}"
+
+    # Set logging to a file.
+    set_logger
+
+    # Start DHCPv4 server using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv4 server to configure.
+    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Server may shut down imediatelly after configuration has competed.
+    # Give it some time to shutdown.
+    sleep 3
+
+    # Make sure that DHCPv4 server is running.
+    get_pids ${kea4_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    # Make sure that DHCPv6 server is not running.
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Use keactrl stop to shutdown the servers.
+    printf "Stopping Kea: ${keactrl} stop\n"
+    ${keactrl} stop
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
+
+    # Wait up to 10s for the DHCPv4 server to stop.
+    wait_for_message 10 "DHCP4_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
+    # Make sure that the servers are down.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} processes running, found %d processes running"
+
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} processes running, found %d processes running"
+
+    cleanup
+}
+
+# This test checks that only DHCPv6 server can be started and that the DHCPv4
+# server is not started.
+start_v6_server_test() {
+    # Test name.
+    TEST_NAME="keactrl.start_v6_server_test"
+    # Create configuration file for keactrl. This configuration enables
+    # DHCPv6 server but disables DHCPv4 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=no\nkea6=yes\n"
+
+    test_start
+
+    # Create configuration file for Kea and for keactrl.
+    create_config "${config}"
+    create_keactrl_config "${keactrl_config}"
+
+    # Set logging to a file.
+    set_logger
+
+    # Start DHCPv6 server using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv6 server to configure.
+    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Server may shut down imediatelly after configuration has competed.
+    # Give it some time to shutdown.
+    sleep 3
+
+    # Make sure that DHCPv6 server is running.
+    get_pids ${kea6_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Make sure that DHCPv4 server is not running.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    # Use keactrl stop to shutdown the servers.
+    printf "Stopping Kea: ${keactrl} stop\n"
+    ${keactrl} stop
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
+
+    # Wait up to 10s for the DHCPv6 server to stop.
+    wait_for_message 10 "DHCP6_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
+    # Make sure that the servers are down.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} processes running, found %d processes running"
+
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} processes running, found %d processes running"
+
+    cleanup
+}
+
+# This test checks that the DHCPv6 server can be started first, and then the
+# DHCPv4 server can be started while DHCPv6 server is already running.
+late_start_v4_server_test() {
+    # Test name.
+    TEST_NAME="keactrl.late_start_v4_server_test"
+    # Create configuration file for keactrl. This configuration enables
+    # DHCPv6 server but disables DHCPv4 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=no\nkea6=yes\n"
+
+    test_start
+
+    # Create configuration file for Kea and for keactrl.
+    create_config "${config}"
+    create_keactrl_config "${keactrl_config}"
+
+    # Set logging to a file.
+    set_logger
+
+    # Start DHCPv6 server using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv6 server to configure.
+    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Server may shut down imediatelly after configuration has competed.
+    # Give it some time to shutdown.
+    sleep 3
+
+    # Make sure that DHCPv6 server is running.
+    get_pids ${kea6_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Make sure that DHCPv4 server is not running.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    # Update keactrl config to enable v4 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=yes\n"
+    create_keactrl_config "${keactrl_config}"
+
+    # Start DHCPv4 server using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv4 server to configure.
+    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Make sure that DHCPv6 server is running.
+    get_pids ${kea6_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Make sure that DHCPv4 server is running.
+    get_pids ${kea4_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    # Use keactrl stop to shutdown the servers.
+    printf "Stopping Kea: ${keactrl} stop\n"
+    ${keactrl} stop
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
+
+    # Wait up to 10s for the DHCPv6 server to stop.
+    wait_for_message 10 "DHCP6_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
+    # Wait up to 10s for the DHCPv4 server to stop.
+    wait_for_message 10 "DHCP4_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
     # Make sure that the servers are down.
     get_pids ${kea4_name}
     assert_eq 0 ${_GET_PIDS_NUM} \
@@ -143,8 +379,114 @@ Expected wait_for_message return %d, returned %d."
     get_pids ${kea6_name}
     assert_eq 0 ${_GET_PIDS_NUM} \
         "Expected %d ${kea6_name} processes running, found %d processes running"
+
+    cleanup
+}
+
+# This test checks that the DHCPv4 server can be started first, and then the
+# DHCPv6 server can be started while DHCPv4 server is already running.
+late_start_v6_server_test() {
+    # Test name.
+    TEST_NAME="keactrl.late_start_v6_server_test"
+    # Create configuration file for keactrl. This configuration enables
+    # DHCPv4 server but disables DHCPv6 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=no\n"
+
+    test_start
+
+    # Create configuration file for Kea and for keactrl.
+    create_config "${config}"
+    create_keactrl_config "${keactrl_config}"
+
+    # Set logging to a file.
+    set_logger
+
+    # Start DHCPv4 server using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv4 server to configure.
+    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Server may shut down imediatelly after configuration has competed.
+    # Give it some time to shutdown.
+    sleep 3
+
+    # Make sure that DHCPv4 server is running.
+    get_pids ${kea4_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    # Make sure that DHCPv6 server is not running.
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Update keactrl config to enable v6 server.
+    keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=yes\n"
+    create_keactrl_config "${keactrl_config}"
+
+    # Start DHCPv6 server using keactrl script.
+    printf "Starting Kea: ${keactrl} start\n"
+    ${keactrl} start
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
+
+    # Wait up to 20s for the DHCPv6 server to configure.
+    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to start. \
+Expected wait_for_message return %d, returned %d."
+
+    # Make sure that DHCPv6 server is running.
+    get_pids ${kea6_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} process running, found %d processes running"
+
+    # Make sure that DHCPv4 server is running.
+    get_pids ${kea4_name}
+    assert_eq 1 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} process running, found %d processes running"
+
+    # Use keactrl stop to shutdown the servers.
+    printf "Stopping Kea: ${keactrl} stop\n"
+    ${keactrl} stop
+    ret=${?}
+    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
+
+    # Wait up to 10s for the DHCPv6 server to stop.
+    wait_for_message 10 "DHCP6_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea6_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
+    # Wait up to 10s for the DHCPv4 server to stop.
+    wait_for_message 10 "DHCP4_SHUTDOWN" 1
+    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
+        "Timeout waiting for ${kea4_name} to shutdown. \
+Expected wait_for_message return %d, returned %d."
+
+    # Make sure that the servers are down.
+    get_pids ${kea4_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea4_name} processes running, found %d processes running"
+
+    get_pids ${kea6_name}
+    assert_eq 0 ${_GET_PIDS_NUM} \
+        "Expected %d ${kea6_name} processes running, found %d processes running"
+
+    cleanup
 }
 
 start_both_servers_test
+start_v4_server_test
+start_v6_server_test
+late_start_v4_server_test
+late_start_v6_server_test
 
 clean_exit 0