#!/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 #export RSYSLOG_DEBUG="debug" USE_VALGRIND=false . ${srcdir:=.}/diag.sh init check_command_available timeout pwd=$( pwd ) k8s_srv_port=$( get_free_port ) generate_conf 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" busyretryinterval="1" token="dummy" kubernetesurl="http://localhost:'$k8s_srv_port'" 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 cat > ${RSYSLOG_DYNNAME}.spool/pod-error1.log < ${RSYSLOG_DYNNAME}.spool/pod-error2.log < ${RSYSLOG_DYNNAME}.spool/pod-name1_namespace-name1_container-name1-id1.log < ${RSYSLOG_DYNNAME}.spool/pod-name2.container-hash2_namespace-name2_container-name2-id2.log < ${RSYSLOG_DYNNAME}.spool/pod-name3.log < ${RSYSLOG_DYNNAME}.spool/pod-name4.log < ${RSYSLOG_DYNNAME}.spool/pod-name5.log < ${RSYSLOG_DYNNAME}.spool/pod-test-not-found-and-busy.log <> ${RSYSLOG_DYNNAME}.spool/pod-test-not-found-and-busy.log <> ${RSYSLOG_DYNNAME}.spool/pod-test-not-found-and-busy.log <> ${RSYSLOG_DYNNAME}.spool/pod-test-error.log <= 0: hsh = json.loads(line[jstart:]) if hsh["origin"] == "mmkubernetes": actual = hsh assert(expected == actual) ' $k8s_srv_port || { 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