# Import common test library.
. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
+run_kea_shell() {
+ # shellcheck disable=SC2086
+ # SC2086: Double quote to prevent globbing and word splitting.
+ # reason: ${auth} can be empty here, if we quote, it will be interpreted as
+ # an empty string which is not desired as it will result in unrecognized
+ # argument from kea-shell.
+ echo | "${shell_bin_path}/${shell_bin}" --host 127.0.0.1 --port 8081 \
+ ${auth} "${cmd}" > "${tmpfile_path}/shell-stdout.txt"
+}
+
# This test verifies that Control Agent is shut down gracefully when it
# receives a SIGINT or SIGTERM signal.
shell_command_test() {
127.0.0.1 --port 8081 ${auth} ${cmd} > ${tmpfile_path}/shell-stdout.txt"
echo "Executing kea-shell ($tmp)"
- set +e
- # shellcheck disable=SC2086
- # SC2086: Double quote to prevent globbing and word splitting.
- # reason: ${auth} can be empty here, if we quote, it will be interpreted as
- # an empty string which is not desired as it will result in unrecognized
- # argument from kea-shell.
- echo | ${shell_bin_path}/${shell_bin} --host 127.0.0.1 \
- --port 8081 ${auth} "${cmd}" > ${tmpfile_path}/shell-stdout.txt
- shell_exit_code=$?
- set -e
+ run_command \
+ run_kea_shell
# Check the exit code
if [ "${exp_result}" = "fail" ]; then
- if [ "${shell_exit_code}" -eq 0 ]; then
+ if [ "${EXIT_CODE}" -eq 0 ]; then
echo "ERROR:" \
- "kea-shell returned ${shell_exit_code} exit code, expected 1."
+ "kea-shell returned ${EXIT_CODE} exit code, expected 1."
else
- echo "kea-shell returned ${shell_exit_code} exit code as expected."
+ echo "kea-shell returned ${EXIT_CODE} exit code as expected."
fi
- elif [ "${shell_exit_code}" -ne 0 ]; then
+ elif [ "${EXIT_CODE}" -ne 0 ]; then
echo "ERROR:" \
- "kea-shell returned ${shell_exit_code} exit code, expected 0."
+ "kea-shell returned ${EXIT_CODE} exit code, expected 0."
else
- echo "kea-shell returned ${shell_exit_code} exit code as expected."
+ echo "kea-shell returned ${EXIT_CODE} exit code as expected."
fi
# Now check the response
rm -f ${tmpfile_path}/shell-expected.txt
printf '%s\n' "${exp_rsp}" > ${tmpfile_path}/shell-expected.txt
- set +e
- diff ${tmpfile_path}/shell-stdout.txt ${tmpfile_path}/shell-expected.txt
- diff_code=$?
- set -e
- if [ "${diff_code}" -ne 0 ]; then
+ if diff "${tmpfile_path}/shell-stdout.txt" "${tmpfile_path}/shell-expected.txt"; then
+ echo "Content returned by kea-shell meets expectation."
+ rm ${tmpfile_path}/shell-*.txt
+ else
echo "ERROR:" \
"content returned is different than expected." \
"See ${tmpfile_path}/shell-*.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.