test: refactor and generalize setup(), adding a setup2()

This patch refactors the way the primary and secondary syslogd is
started by the test framework.  The generalizations not only make the
code more readable, it hopefully also makes it easier to add new tests
in the future.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2022-03-06 00:56:03 +01:00
parent 7707715c78
commit f29f31340c
6 changed files with 78 additions and 45 deletions

View File

@ -15,8 +15,7 @@ echo "= Phase 2 - syslog() with openlog() & custom facility ==="
cat <<EOF >${CONFD}/console.conf
console.* -${LOGCONS}
EOF
kill -HUP `cat ${PID}`
sleep 2
reload
./api -i foo
grep "foo: ${MSG}" ${LOGCONS}
@ -29,8 +28,7 @@ echo "= Phase 4 - Verify RFC5424 API with syslogp() ==========="
cat <<EOF >${CONFD}/v1.conf
ftp.* -${LOGV1} ;RFC5424
EOF
kill -HUP `cat ${PID}`
sleep 2
reload
./api -i troglobit -p
sleep 2

View File

@ -5,7 +5,7 @@ if [ x"${srcdir}" = x ]; then
fi
. ${srcdir}/lib.sh
setup
setup -m0
MSG="fwd and allow"
@ -14,19 +14,16 @@ kern.* /dev/null
ntp.* @127.0.0.2:${PORT2} ;RFC5424
EOF
reload
cat <<EOF >${CONFD2}/50-default.conf
kern.* /dev/null
*.*;kern.none ${LOG2} ;RFC5424
EOF
../src/syslogd -K -a 127.0.0.2:* -b :${PORT2} -d -F -f ${CONF2} -p ${SOCK2} -m1 -C ${CACHE2} -P ${PID2} &
setup2 -m0 -a 127.0.0.2:* -b ":${PORT2}"
kill -HUP `cat ${PID}`
sleep 2
# Enable debug for second syslogd
cat ${PID2} >> "$DIR/PIDs"
kill -USR1 `cat ${PID2}`
../src/logger -t fwd -p ntp.notice -u ${SOCK} -m "NTP123" ${MSG}
sleep 3

View File

@ -73,40 +73,81 @@ tenacious()
FAIL "Timeed out $*"
}
setup()
# shellcheck disable=SC2046,SC2086
do_setup()
{
order=$1
pidfn=$2
shift 2
opts="$*"
ip link set lo up
cat <<-EOF > ${CONF}
# Nothing here yo
print "Starting $order syslogd ..."
../src/syslogd -dKF ${opts} &
sleep 2
[ -f "${pidfn}" ] || FAIL "Failed starting $order syslogd"
cat "${pidfn}" >> "$DIR/PIDs"
# Enable debugging ...
kill -USR1 $(cat "${pidfn}")
sleep 1
}
# set up and start primary syslogd
setup()
{
if [ ! -f "${CONF}" ]; then
cat <<-EOF > "${CONF}"
include ${CONFD}/*.conf
EOF
mkdir -p ${CONFD2}
cat <<-EOF > ${CONF2}
# Nothing here yo
include ${CONFD2}/*.conf
EOF
cat <<-EOF > ${CONFD}/foo.conf
cat <<-EOF > "${CONFD}/foo.conf"
# Local log file, avoid sync to disk
*.* -${LOG}
EOF
cat <<-EOF > ${CONFD}/bar.conf
cat <<-EOF > "${CONFD}/bar.conf"
# For remote logging
*.* @127.0.0.2
*.* @127.0.0.2:${PORT2} ;RFC3164
EOF
fi
../src/syslogd -K -m1 -b :${PORT} -d -sF -f ${CONF} -p ${SOCK} -p ${ALTSOCK} -C ${CACHE} -P ${PID} &
do_setup "primary" "${PID}" "$*" -b ":${PORT}" -f "${CONF}" -p "${SOCK}" \
-p "${ALTSOCK}" -C "${CACHE}" -P "${PID}"
}
sleep 2
cat ${PID} >> "$DIR/PIDs"
kill -USR1 `cat ${PID}`
# set up and start second syslogd, e.g., for remote.sh
setup2()
{
cat <<-EOF > "${CONF2}"
include ${CONFD2}/*.conf
EOF
do_setup "secondary" "${PID2}" "$*" -f "${CONF2}" -p "${SOCK2}" \
-C "${CACHE2}" -P "${PID2}"
}
do_reload()
{
# shellcheck disable=SC2046
kill -HUP $(cat "$1")
sleep 1
}
reload()
{
do_reload "${PID}"
}
reload2()
{
do_reload "${PID2}"
}
# Stop all lingering collectors and other tools
kill_pids()
{
@ -157,6 +198,7 @@ trapit()
}
# Runs once when including lib.sh
mkdir -p ${CONFD}
mkdir -p "${CONFD}"
mkdir -p "${CONFD2}"
touch "$DIR/PIDs"
trapit signal INT TERM QUIT EXIT

View File

@ -4,7 +4,9 @@ if [ x"${srcdir}" = x ]; then
srcdir=.
fi
. ${srcdir}/lib.sh
setup
# Enable MARK messages every minute, full secure mode
setup -m1 -ss
check_mark()
{

View File

@ -4,15 +4,11 @@ if [ x"${srcdir}" = x ]; then
fi
. ${srcdir}/lib.sh
mkdir -p ${CONFD}
cat <<EOF > ${CONF}
# Match all log messages, store in RC5424 format and rotate every 10 MiB
*.* -${LOG} ;rotate=10M:5,RFC5424
EOF
../src/syslogd -K -m1 -b :${PORT} -d -sF -f ${CONF} -p ${SOCK} -p ${ALTSOCK} >${LOG2} &
echo "$!" > ${PID}
cat ${PID} >> "$DIR/PIDs"
setup -m0 >"${LOG2}"
sleep 2
grep ';RFC5424,rotate=10000000:5' ${LOG2} || FAIL "Failed parsing RFC542 .conf"

View File

@ -15,10 +15,8 @@ export MSG="kilroy"
cat <<-EOF >${CONFD2}/50-default.conf
*.* ${LOG2}
EOF
../src/syslogd -K -a 127.0.0.2:* -b :${PORT2} -d -F -f ${CONF2} -p ${SOCK2} -m1 -C ${CACHE2} -P ${PID2} &
sleep 3
cat ${PID2} >> "$DIR/PIDs"
kill -USR1 `cat ${PID2}`
setup2 -m0 -a 127.0.0.2:* -b ":${PORT2}"
# Start collector in background, note: might need sudo!
#tshark -Qni lo -w ${CAP} port ${PORT} &