mirror of
https://github.com/ovh/the-bastion.git
synced 2025-09-06 04:54:20 +08:00
chore: speedup tests by ~20%
This commit is contained in:
parent
896721aad6
commit
f97b761b83
2 changed files with 37 additions and 16 deletions
|
@ -157,6 +157,9 @@ prefix()
|
||||||
|
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
|
# display verbose output about the previous test if it was bad
|
||||||
|
# we do this here because this way we're sure that all checks have been done for it
|
||||||
|
# at this stage (retvalshouldbe, json, ...)
|
||||||
if [ "$isbad" = 1 ]; then
|
if [ "$isbad" = 1 ]; then
|
||||||
if [ -f "$outdir/$basename.script" ]; then
|
if [ -f "$outdir/$basename.script" ]; then
|
||||||
printf "%b%b%b\\n" "$WHITE_ON_BLUE" "[INFO] test script follows" "$NOC"
|
printf "%b%b%b\\n" "$WHITE_ON_BLUE" "[INFO] test script follows" "$NOC"
|
||||||
|
@ -177,6 +180,7 @@ run()
|
||||||
fi
|
fi
|
||||||
isbad=0
|
isbad=0
|
||||||
|
|
||||||
|
# now prepare for the current test
|
||||||
testno=$(( testno + 1 ))
|
testno=$(( testno + 1 ))
|
||||||
[ "$COUNTONLY" = 1 ] && return
|
[ "$COUNTONLY" = 1 ] && return
|
||||||
name=$1
|
name=$1
|
||||||
|
@ -184,20 +188,25 @@ run()
|
||||||
case=$1
|
case=$1
|
||||||
shift
|
shift
|
||||||
basename=$(printf '%03d-%s-%s' $testno $name $case | sed -re "s=/=_=g")
|
basename=$(printf '%03d-%s-%s' $testno $name $case | sed -re "s=/=_=g")
|
||||||
|
|
||||||
|
# if we're about to run a script, keep a copy there
|
||||||
if [ -x "$1" ] && [ "$#" -eq 1 ]; then
|
if [ -x "$1" ] && [ "$#" -eq 1 ]; then
|
||||||
cp "$1" "$outdir/$basename.script"
|
cp "$1" "$outdir/$basename.script"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf '%b %b*** [%03d/%03d] %b::%b %s(%b)\n' "$(prefix)" "$BOLD_CYAN" "$testno" "$testcount" "$name" "$case" "$NOC" "$*"
|
printf '%b %b*** [%03d/%03d] %b::%b %s(%b)\n' "$(prefix)" "$BOLD_CYAN" "$testno" "$testcount" "$name" "$case" "$NOC" "$*"
|
||||||
|
|
||||||
|
# special case for scp: we need to wait a bit before terminating the test
|
||||||
sleepafter=0
|
sleepafter=0
|
||||||
[ "$name" = "scp" ] && sleepafter=2
|
[ "$name" = "scp" ] && sleepafter=2
|
||||||
$screen "$outdir/$basename.log" -D -m -fn -ln flock "$outdir/$basename.log" bash -c "$* ; echo \$? > $outdir/$basename.retval ; sleep $sleepafter"
|
|
||||||
antiloop=30
|
# put an invalid value in this file, should be overwritten. we also use it as a lock file.
|
||||||
while [ ! -e "$outdir/$basename.retval" ] && [ $antiloop -gt 0 ]; do
|
echo -1 > $outdir/$basename.retval
|
||||||
sleep 0.1
|
# run the test
|
||||||
flock "$outdir/$basename.log" true
|
flock "$outdir/$basename.retval" $screen "$outdir/$basename.log" -D -m -fn -ln bash -c "$* ; echo \$? > $outdir/$basename.retval ; sleep $sleepafter"
|
||||||
antiloop=$((antiloop - 1))
|
flock "$outdir/$basename.retval" true
|
||||||
done
|
|
||||||
test -e $outdir/$basename.retval || echo -1 > $outdir/$basename.retval
|
# look for generally bad strings in the output
|
||||||
_bad='at /usr/share/perl|compilation error|compilation aborted|BEGIN failed|gonna crash|/opt/bastion/|sudo:|ontinuing anyway|MAKETESTFAIL'
|
_bad='at /usr/share/perl|compilation error|compilation aborted|BEGIN failed|gonna crash|/opt/bastion/|sudo:|ontinuing anyway|MAKETESTFAIL'
|
||||||
_badexclude='/etc/shells'
|
_badexclude='/etc/shells'
|
||||||
# shellcheck disable=SC2126
|
# shellcheck disable=SC2126
|
||||||
|
@ -205,21 +214,27 @@ run()
|
||||||
nbfailedgeneric=$(( nbfailedgeneric + 1 ))
|
nbfailedgeneric=$(( nbfailedgeneric + 1 ))
|
||||||
fail "BAD STRING" "(generic known-bad string found in output)"
|
fail "BAD STRING" "(generic known-bad string found in output)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# now run consistency check on the target, unless configured otherwise
|
||||||
if [ "$nocc" != 1 ]; then
|
if [ "$nocc" != 1 ]; then
|
||||||
$screen "$outdir/$basename.cc" -D -m -fn -ln flock "$outdir/$basename.cc" bash -c "$r0 /opt/bastion/bin/admin/check-consistency.pl ; echo \$? > $outdir/$basename.ccret ; $r0 test -s /var/log/bastion/bastion-warn.log ; echo \$? > $outdir/$basename.warnret ; $r0 test -s /var/log/bastion/bastion-die.log ; echo \$? > $outdir/$basename.dieret"
|
flock "$outdir/$basename.retval" $screen "$outdir/$basename.cc" -D -m -fn -ln $r0 '
|
||||||
sleep 0.2
|
/opt/bastion/bin/admin/check-consistency.pl ; echo _RETVAL_CC=$?= ;
|
||||||
flock "$outdir/$basename.cc" true
|
grep -Fw -e warn -e die -e code-warning /var/log/bastion/bastion.log | grep -Fv "'"${code_warn_exclude:-__none__}"'" | sed "s/^/_SYSLOG=/" ;
|
||||||
ccret=$(< $outdir/$basename.ccret)
|
: > /var/log/bastion/bastion.log
|
||||||
warnret=$(< $outdir/$basename.warnret)
|
'
|
||||||
dieret=$(< $outdir/$basename.dieret)
|
flock "$outdir/$basename.retval" true
|
||||||
|
ccret=$( grep _RETVAL_CC= "$outdir/$basename.cc" | cut -d= -f2)
|
||||||
|
syslogline=$(grep _SYSLOG= "$outdir/$basename.cc" | cut -d= -f2-)
|
||||||
if [ "$ccret" != 0 ]; then
|
if [ "$ccret" != 0 ]; then
|
||||||
nbfailedcon=$(( nbfailedcon + 1 ))
|
nbfailedcon=$(( nbfailedcon + 1 ))
|
||||||
fail "CONSISTENCY CHECK"
|
fail "CONSISTENCY CHECK"
|
||||||
fi
|
fi
|
||||||
if [ "$warnret" != 1 ] || [ $dieret != 1 ]; then
|
if [ -n "$syslogline" ]; then
|
||||||
nbfailedlog=$(( nbfailedlog + 1 ))
|
nbfailedlog=$(( nbfailedlog + 1 ))
|
||||||
fail "WARN/DIE TRIGGERED"
|
fail "WARN/DIE/CODE-WARN TRIGGERED"
|
||||||
fi
|
fi
|
||||||
|
# reset this for the next test
|
||||||
|
unset code_warn_exclude
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +289,11 @@ plgfail()
|
||||||
retvalshouldbe 100
|
retvalshouldbe 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignorecodewarn()
|
||||||
|
{
|
||||||
|
code_warn_exclude="$*"
|
||||||
|
}
|
||||||
|
|
||||||
get_json()
|
get_json()
|
||||||
{
|
{
|
||||||
[ "$COUNTONLY" = 1 ] && return
|
[ "$COUNTONLY" = 1 ] && return
|
||||||
|
|
|
@ -24,6 +24,7 @@ testsuite_activeness()
|
||||||
|
|
||||||
success activeness test_invalid_config_but_always_active $a3 --osh info
|
success activeness test_invalid_config_but_always_active $a3 --osh info
|
||||||
|
|
||||||
|
ignorecodewarn 'is not readable+executable'
|
||||||
run activeness test_invalid_config $a1 --osh info
|
run activeness test_invalid_config $a1 --osh info
|
||||||
retvalshouldbe 101
|
retvalshouldbe 101
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue