#!/bin/bash # added 2018-04-06 by richm, released under ASL 2.0 # # Note: on buildbot VMs (where there is no environment cleanup), the # kubernetes test server may be kept running if the script aborts or # is aborted (buildbot master failure!) for some reason. As such we # execute it under "timeout" control, which ensure it always is # terminated. It's not a 100% great method, but hopefully does the # trick. -- rgerhards, 2018-07-21 . ${srcdir:=.}/diag.sh init check_command_available timeout pwd=$( pwd ) k8s_srv_port=$( get_free_port ) generate_conf cachettl=10 add_conf ' global(workDirectory="'$RSYSLOG_DYNNAME.spool'") module(load="../plugins/impstats/.libs/impstats" interval="1" log.file="'"$RSYSLOG_DYNNAME.spool"'/mmkubernetes-stats.log" log.syslog="off" format="cee") module(load="../plugins/imfile/.libs/imfile") module(load="../plugins/mmjsonparse/.libs/mmjsonparse") module(load="../contrib/mmkubernetes/.libs/mmkubernetes") template(name="mmk8s_template" type="list") { property(name="$!all-json-plain") constant(value="\n") } input(type="imfile" file="'$RSYSLOG_DYNNAME.spool'/pod-*.log" tag="kubernetes" addmetadata="on") action(type="mmjsonparse" cookie="") action(type="mmkubernetes" token="dummy" kubernetesurl="http://localhost:'$k8s_srv_port'" cacheexpireinterval="1" cacheentryttl="'$cachettl'" filenamerules=["rule=:'$pwd/$RSYSLOG_DYNNAME.spool'/%pod_name:char-to:.%.%container_hash:char-to:_%_%namespace_name:char-to:_%_%container_name_and_id:char-to:.%.log", "rule=:'$pwd/$RSYSLOG_DYNNAME.spool'/%pod_name:char-to:_%_%namespace_name:char-to:_%_%container_name_and_id:char-to:.%.log"] ) action(type="omfile" file=`echo $RSYSLOG_OUT_LOG` template="mmk8s_template") ' testsrv=mmk8s-test-server echo starting kubernetes \"emulator\" timeout 2m $PYTHON -u $srcdir/mmkubernetes_test_server.py $k8s_srv_port ${RSYSLOG_DYNNAME}${testsrv}.pid ${RSYSLOG_DYNNAME}${testsrv}.started > ${RSYSLOG_DYNNAME}.spool/mmk8s_srv.log 2>&1 & BGPROCESS=$! wait_process_startup ${RSYSLOG_DYNNAME}${testsrv} ${RSYSLOG_DYNNAME}${testsrv}.started echo background mmkubernetes_test_server.py process id is $BGPROCESS if [ "x${USE_VALGRIND:-NO}" == "xYES" ] ; then export EXTRA_VALGRIND_SUPPRESSIONS="--suppressions=$srcdir/mmkubernetes.supp" startup_vg else startup if [ -n "${USE_GDB:-}" ] ; then echo attach gdb here sleep 54321 || : fi fi # add 3 logs - then wait $cachettl - the first log should prime the cache - the next two should be pulled from the cache cat > ${RSYSLOG_DYNNAME}.spool/pod-name.log <> ${RSYSLOG_DYNNAME}.spool/pod-name.log <> ${RSYSLOG_DYNNAME}.spool/pod-name.log <> ${RSYSLOG_DYNNAME}.spool/pod-name.log <= 0: hsh = json.loads(line[jstart:]) if hsh.get("origin") == "mmkubernetes" and hsh["recordseen"] in expectedvalues: expected = expectedvalues[hsh["recordseen"]] for key in expected: if not expected[key] == hsh.get(key): print("Error: expected value [%s] not equal to actual value [%s] in record [%d] for stat [%s]".format( str(expected[key]), str(hsh[key]), hsh["recordseen"], key)) ' || { rc=$?; echo error: expected stats not found in ${RSYSLOG_DYNNAME}.spool/mmkubernetes-stats.log; } else echo error: stats file ${RSYSLOG_DYNNAME}.spool/mmkubernetes-stats.log not found rc=1 fi if [ ${rc:-0} -ne 0 ]; then echo echo "FAIL: expected data not found. $RSYSLOG_OUT_LOG is:" cat ${RSYSLOG_DYNNAME}.spool/mmk8s_srv.log cat $RSYSLOG_OUT_LOG cat ${RSYSLOG_DYNNAME}.spool/mmkubernetes-stats.log error_exit 1 fi exit_test