Merge pull request #58783 from cblecker/verify-junit

Automatic merge from submit-queue (batch tested with PRs 58783, 58800, 58846). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Produce junit results for verify job

**What this PR does / why we need it**:
Junit results may make the verify job clearer, and give us better insights into timings

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2018-01-26 10:19:33 -08:00 committed by GitHub
commit f4bab0b1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 36 deletions

View File

@ -123,7 +123,7 @@ verify:
@echo "$$VERIFY_HELP_INFO"
else
verify: verify_generated_files
KUBE_VERIFY_GIT_BRANCH=$(BRANCH) hack/make-rules/verify.sh -v
KUBE_VERIFY_GIT_BRANCH=$(BRANCH) hack/make-rules/verify.sh
endif
define QUICK_VERIFY_HELP_INFO

View File

@ -31,6 +31,8 @@ retry() {
export PATH=${GOPATH}/bin:${PWD}/third_party/etcd:/usr/local/go/bin:${PATH}
# Produce a JUnit-style XML test report
export KUBE_JUNIT_REPORT_DIR=${WORKSPACE}/artifacts
# Set artifacts directory
export ARTIFACTS_DIR=${WORKSPACE}/artifacts

View File

@ -21,6 +21,9 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/hack/lib/util.sh"
# include shell2junit library
source "${KUBE_ROOT}/third_party/forked/shell2junit/sh2ju.sh"
# Excluded check patterns are always skipped.
EXCLUDED_PATTERNS=(
"verify-all.sh" # this script calls the make rule and would cause a loop
@ -69,11 +72,19 @@ function is-quick {
}
function run-cmd {
local filename="${2##*/verify-}"
local testname="${filename%%.*}"
local output="${KUBE_JUNIT_REPORT_DIR:-/tmp/junit-results}"
local tr
if ${SILENT}; then
"$@" &> /dev/null
juLog -output="${output}" -class="verify" -name="${testname}" "$@" &> /dev/null
tr=$?
else
"$@"
juLog -output="${output}" -class="verify" -name="${testname}" "$@"
tr=$?
fi
return ${tr}
}
# Collect Failed tests in this Array , initalize it to nil
@ -118,30 +129,15 @@ function run-checks {
done
}
SILENT=true
QUICK=false
while getopts ":vQ" opt; do
case ${opt} in
v)
SILENT=false
;;
Q)
QUICK=true
;;
\?)
echo "Invalid flag: -${OPTARG}" >&2
exit 1
;;
esac
done
SILENT=${SILENT:-false}
QUICK=${QUICK:-false}
if ${SILENT} ; then
echo "Running in silent mode, run with -v if you want to see script logs."
echo "Running in silent mode, run with SILENT=false if you want to see script logs."
fi
if ${QUICK} ; then
echo "Running in quick mode (-Q flag). Only fast checks will run."
echo "Running in quick mode (QUICK=true). Only fast checks will run."
fi
ret=0
@ -149,7 +145,7 @@ run-checks "${KUBE_ROOT}/hack/verify-*.sh" bash
run-checks "${KUBE_ROOT}/hack/verify-*.py" python
if [[ ${ret} -eq 1 ]]; then
print-failed-tests
print-failed-tests
fi
exit ${ret}

View File

@ -32,6 +32,15 @@ juDIR=`pwd`/results
# The name of the suite is calculated based in your script name
suite=""
if LANG=C sed --help 2>&1 | grep -q GNU; then
SED="sed"
elif which gsed &>/dev/null; then
SED="gsed"
else
echo "Failed to find GNU sed as sed or gsed. If you are on Mac: brew install gnu-sed." >&2
exit 1
fi
# A wrapper for the eval method witch allows catching seg-faults and use tee
errfile=/tmp/evErr.$$.log
function eVal() {
@ -57,11 +66,11 @@ function juLog() {
ya=""; icase=""
while [ -z "$ya" ]; do
case "$1" in
-name=*) name=`echo "$1" | sed -e 's/-name=//'`; shift;;
-class=*) class=`echo "$1" | sed -e 's/-class=//'`; shift;;
-ierror=*) ereg=`echo "$1" | sed -e 's/-ierror=//'`; icase="-i"; shift;;
-error=*) ereg=`echo "$1" | sed -e 's/-error=//'`; shift;;
-output=*) juDIR=`echo "$1" | sed -e 's/-output=//'`; shift;;
-name=*) name=`echo "$1" | ${SED} -e 's/-name=//'`; shift;;
-class=*) class=`echo "$1" | ${SED} -e 's/-class=//'`; shift;;
-ierror=*) ereg=`echo "$1" | ${SED} -e 's/-ierror=//'`; icase="-i"; shift;;
-error=*) ereg=`echo "$1" | ${SED} -e 's/-error=//'`; shift;;
-output=*) juDIR=`echo "$1" | ${SED} -e 's/-output=//'`; shift;;
*) ya=1;;
esac
done
@ -83,7 +92,7 @@ function juLog() {
# calculate command to eval
[ -z "$1" ] && return
cmd="$1"; shift
while [ -n "$1" ]
while [ -n "${1:-}" ]
do
cmd="$cmd \"$1\""
shift
@ -108,8 +117,8 @@ function juLog() {
# set the appropriate error, based in the exit code and the regex
[ $evErr != 0 ] && err=1 || err=0
out=`cat $outf | sed -e 's/^\([^+]\)/| \1/g'`
if [ $err = 0 -a -n "$ereg" ]; then
out=`cat $outf | ${SED} -e 's/^\([^+]\)/| \1/g'`
if [ $err = 0 -a -n "${ereg:-}" ]; then
H=`echo "$out" | egrep $icase "$ereg"`
[ -n "$H" ] && err=1
fi
@ -148,14 +157,14 @@ $errMsg
if [[ -e "$juDIR/junit_$suite.xml" ]]; then
# file exists. first update the failures count
failCount=`sed -n "s/.*testsuite.*failures=\"\([0-9]*\)\".*/\1/p" "$juDIR/junit_$suite.xml"`
failCount=`${SED} -n "s/.*testsuite.*failures=\"\([0-9]*\)\".*/\1/p" "$juDIR/junit_$suite.xml"`
errors=$(($failCount+$errors))
sed -i "0,/failures=\"$failCount\"/ s/failures=\"$failCount\"/failures=\"$errors\"/" "$juDIR/junit_$suite.xml"
sed -i "0,/errors=\"$failCount\"/ s/errors=\"$failCount\"/errors=\"$errors\"/" "$juDIR/junit_$suite.xml"
${SED} -i "0,/failures=\"$failCount\"/ s/failures=\"$failCount\"/failures=\"$errors\"/" "$juDIR/junit_$suite.xml"
${SED} -i "0,/errors=\"$failCount\"/ s/errors=\"$failCount\"/errors=\"$errors\"/" "$juDIR/junit_$suite.xml"
# file exists. Need to append to it. If we remove the testsuite end tag, we can just add it in after.
sed -i "s^</testsuite>^^g" $juDIR/junit_$suite.xml ## remove testSuite so we can add it later
sed -i "s^</testsuites>^^g" $juDIR/junit_$suite.xml
${SED} -i "s^</testsuite>^^g" $juDIR/junit_$suite.xml ## remove testSuite so we can add it later
${SED} -i "s^</testsuites>^^g" $juDIR/junit_$suite.xml
cat <<EOF >> "$juDIR/junit_$suite.xml"
$content
</testsuite>