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

View File

@ -5,7 +5,7 @@ if [ x"${srcdir}" = x ]; then
fi fi
. ${srcdir}/lib.sh . ${srcdir}/lib.sh
setup setup -m0
MSG="fwd and allow" MSG="fwd and allow"
@ -14,19 +14,16 @@ kern.* /dev/null
ntp.* @127.0.0.2:${PORT2} ;RFC5424 ntp.* @127.0.0.2:${PORT2} ;RFC5424
EOF EOF
reload
cat <<EOF >${CONFD2}/50-default.conf cat <<EOF >${CONFD2}/50-default.conf
kern.* /dev/null kern.* /dev/null
*.*;kern.none ${LOG2} ;RFC5424 *.*;kern.none ${LOG2} ;RFC5424
EOF 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} ../src/logger -t fwd -p ntp.notice -u ${SOCK} -m "NTP123" ${MSG}
sleep 3 sleep 3

View File

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

View File

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

View File

@ -4,15 +4,11 @@ if [ x"${srcdir}" = x ]; then
fi fi
. ${srcdir}/lib.sh . ${srcdir}/lib.sh
mkdir -p ${CONFD}
cat <<EOF > ${CONF} cat <<EOF > ${CONF}
# Match all log messages, store in RC5424 format and rotate every 10 MiB # Match all log messages, store in RC5424 format and rotate every 10 MiB
*.* -${LOG} ;rotate=10M:5,RFC5424 *.* -${LOG} ;rotate=10M:5,RFC5424
EOF EOF
../src/syslogd -K -m1 -b :${PORT} -d -sF -f ${CONF} -p ${SOCK} -p ${ALTSOCK} >${LOG2} & setup -m0 >"${LOG2}"
echo "$!" > ${PID}
cat ${PID} >> "$DIR/PIDs"
sleep 2
grep ';RFC5424,rotate=10000000:5' ${LOG2} || FAIL "Failed parsing RFC542 .conf" 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 cat <<-EOF >${CONFD2}/50-default.conf
*.* ${LOG2} *.* ${LOG2}
EOF EOF
../src/syslogd -K -a 127.0.0.2:* -b :${PORT2} -d -F -f ${CONF2} -p ${SOCK2} -m1 -C ${CACHE2} -P ${PID2} &
sleep 3 setup2 -m0 -a 127.0.0.2:* -b ":${PORT2}"
cat ${PID2} >> "$DIR/PIDs"
kill -USR1 `cat ${PID2}`
# Start collector in background, note: might need sudo! # Start collector in background, note: might need sudo!
#tshark -Qni lo -w ${CAP} port ${PORT} & #tshark -Qni lo -w ${CAP} port ${PORT} &