Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
67f0a792
Commit
67f0a792
authored
Mar 07, 2017
by
Tomek Mrugalski
🛰
Browse files
[5137] shell tests implemented.
parent
14a6d2ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/bin/shell/tests/Makefile.am
0 → 100644
View file @
67f0a792
PYTESTS
=
kea-shell_unittest.py
SHTESTS
=
shell_process_tests.sh
noinst_SCRIPTS
=
$(PYTESTS)
shell_process_tests.sh
EXTRA_DIST
=
testdata/plugins/testplugin.py
# test using command-line arguments, so use check-local target instead of TESTS
check-local
:
@
for
pytest
in
$(PYTESTS)
;
do
\
echo
Running python
test
:
$$
pytest
;
\
chmod
+x
$(abs_builddir)
/
$$
pytest
;
\
PYTHONPATH
=
$(PYTHONPATH)
:
$(abs_top_builddir)
/src/bin/shell python
$(abs_builddir)
/
$$
pytest
||
exit
;
\
done
@for
shtest
in
$(SHTESTS)
;
do
\
echo Running shell test
:
$$shtest ;
\
export KEA_LOCKFILE_DIR=$(abs_top_builddir);
\
export KEA_PIDFILE_DIR=$(abs_top_builddir);
\
${SHELL} $(abs_builddir)/$$shtest || exit ;
\
done
CLEANDIRS
=
__pycache__
clean-local
:
rm
-rf
$(CLEANDIRS)
src/bin/shell/tests/kea-shell_unittest.py
0 → 100755
View file @
67f0a792
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import
unittest
class
CARequestUnitTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
print
(
"Setting up"
)
def
runTest
(
self
):
print
(
"Run test"
)
def
tearDown
(
self
):
print
(
"Tearing down"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
src/bin/shell/tests/shell_process_tests.sh.in
0 → 100644
View file @
67f0a792
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Path to the temporary configuration file.
CFG_FILE=@abs_top_builddir@/src/bin/shell/tests/test_config.json
# Path to the Control Agent log file.
LOG_FILE=@abs_top_builddir@/src/bin/shell/tests/test.log
# Expected version
EXPECTED_VERSION="@PACKAGE_VERSION@"
# Control Agent configuration to be stored in the configuration file.
# todo: use actual configuration once we support it.
CONFIG="{
\"Control-agent\":
{
\"http-host\": \"127.0.0.1\",
\"http-port\": 8081
},
\"Logging\":
{
\"loggers\": [
{
\"name\": \"kea-ctrl-agent\",
\"output_options\": [
{
\"output\": \"$LOG_FILE\"
}
],
\"severity\": \"DEBUG\"
}
]
}
}"
ca_bin="kea-ctrl-agent"
ca_bin_path=@abs_top_builddir@/src/bin/agent
shell_bin="kea-shell"
shell_bin_path=@abs_top_builddir@/src/bin/shell
tmpfile_path=@abs_top_builddir@/src/bin/shell/tests
# Import common test library.
. @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
# This test verifies that Control Agent is shut down gracefully when it
# receives a SIGINT or SIGTERM signal.
shell_command_test() {
test_name=${1} # Test name
cmd=${2} # Command to be sent
exp_rsp=${3} # Expected response
params=${4} # Any extra parameters
# Setup phase: start CA.
# Log the start of the test and print test name.
test_start ${test_name}
# Remove any dangling CA instances and remove log files.
cleanup
# Create new configuration file.
create_config "${CONFIG}"
# Instruct Control Agent to log to the specific file.
set_logger
# Start Control Agent.
start_kea ${ca_bin_path}/${ca_bin}
# Wait up to 20s for Control Agent to start.
wait_for_kea 20
if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
printf "ERROR: timeout waiting for Control Agent to start.\n"
clean_exit 1
fi
# Check if it is still running. It could have terminated (e.g. as a result
# of configuration failure).
get_pid ${ca_bin}
if [ ${_GET_PIDS_NUM} -ne 1 ]; then
printf "ERROR: expected one Control Agent process to be started. Found %d processes\
started.\n" ${_GET_PIDS_NUM}
clean_exit 1
fi
# Check in the log file, how many times server has been configured.
# It should be just once on startup.
get_reconfigs
if [ ${_GET_RECONFIGS} -ne 1 ]; then
printf "ERROR: server been configured ${_GET_RECONFIGS} time(s), but exactly 1 was expected.\n"
clean_exit 1
else
printf "Server successfully configured.\n"
fi
# Main test phase: send command, check response.
tmp="echo \"${params}\" | ${shell_bin_path}/${shell_bin} --host 127.0.0.1 --port 8081 ${cmd} > ${tmpfile_path}/shell-stdout.txt"
echo "Executing kea-shell ($tmp)"
echo "${params}" | ${shell_bin_path}/${shell_bin} --host 127.0.0.1 --port 8081 ${cmd} > ${tmpfile_path}/shell-stdout.txt
# Check the exit code
shell_exit_code=$?
if [ ${shell_exit_code} -ne 0 ]; then
echo "ERROR: kea-shell returned ${shell_exit_code} exit code, expected 0."
else
echo "kea-shell returned ${shell_exit_code} exit code as expected."
fi
# Now check the response
rm -f ${tmpfile_path}/shell-expected.txt
echo ${exp_rsp} > ${tmpfile_path}/shell-expected.txt
diff ${tmpfile_path}/shell-stdout.txt ${tmpfile_path}/shell-expected.txt
diff_code=$?
if [ ${diff_code} -ne 0 ]; then
echo "ERROR: content returned is different than expected. See ${tmpfile_path}/shell-*.txt"
echo "EXPECTED:"
cat ${tmpfile_path}/shell-expected.txt
echo "ACTUAL RESULT:"
cat ${tmpfile_path}/shell-stdout.txt
clean_exit 1
else
echo "Content returned by kea-shell meets expectation."
rm ${tmpfile_path}/shell-*.txt
fi
# Main test phase ends.
# Cleanup phase: shutdown CA
# Send SIGTERM signal to Control Agent
send_signal 15 ${ca_bin}
# Now wait for process to log that it is exiting.
wait_for_message 10 "DCTL_SHUTDOWN" 1
if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
printf "ERROR: Control Agent did not log shutdown.\n"
clean_exit 1
fi
# Make sure the server is down.
wait_for_server_down 5 ${ca_bin}
assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
"Expected wait_for_server_down return %d, returned %d"
test_finish 0
}
shell_command_test "shell.list-commands" "list-commands" "[ { \"arguments\": [ \"list-commands\" ], \"result\": 0 } ]" ""
shell_command_test "shell.bogus" "give-me-a-beer" "[ { \"result\": 1, \"text\": \"'give-me-a-beer' command not supported.\" } ]" ""
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment