mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #28133 from freehan/e2ejunit
Automatic merge from submit-queue add junit recording in e2e runner 2nd part of #27825 Injected junit recorder at a few places.
This commit is contained in:
commit
6eae13e0c4
@ -21,9 +21,48 @@ set -o nounset
|
||||
set -o pipefail
|
||||
set -o xtrace
|
||||
|
||||
# include shell2junit library
|
||||
source <(curl -fsS --retry 3 'https://raw.githubusercontent.com/kubernetes/kubernetes/master/third_party/forked/shell2junit/sh2ju.sh')
|
||||
|
||||
# Have cmd/e2e run by goe2e.sh generate JUnit report in ${WORKSPACE}/junit*.xml
|
||||
ARTIFACTS=${WORKSPACE}/_artifacts
|
||||
mkdir -p ${ARTIFACTS}
|
||||
|
||||
# E2E runner stages
|
||||
STAGE_PRE="PRE-SETUP"
|
||||
STAGE_SETUP="SETUP"
|
||||
STAGE_CLEANUP="CLEANUP"
|
||||
STAGE_KUBEMARK="KUBEMARK"
|
||||
|
||||
: ${KUBE_GCS_RELEASE_BUCKET:="kubernetes-release"}
|
||||
: ${KUBE_GCS_DEV_RELEASE_BUCKET:="kubernetes-release-dev"}
|
||||
|
||||
# record_command runs the command and records its output/error messages in junit format
|
||||
# it expects the first argument to be the class and the second to be the name of the command
|
||||
# Example:
|
||||
# record_command PRESETUP curltest curl google.com
|
||||
# record_command CLEANUP check false
|
||||
#
|
||||
# WARNING: Variable changes in the command will NOT be effective after record_command returns.
|
||||
# This is because the command runs in subshell.
|
||||
function record_command() {
|
||||
set +o xtrace
|
||||
set +o nounset
|
||||
set +o errexit
|
||||
|
||||
local class=$1
|
||||
shift
|
||||
local name=$1
|
||||
shift
|
||||
echo "Recording: ${class} ${name}"
|
||||
echo "Running command: $@"
|
||||
juLog -output="${ARTIFACTS}" -class="${class}" -name="${name}" "$@"
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
set -o xtrace
|
||||
}
|
||||
|
||||
function running_in_docker() {
|
||||
grep -q docker /proc/self/cgroup
|
||||
}
|
||||
@ -114,7 +153,7 @@ function install_google_cloud_sdk_tarball() {
|
||||
tar xzf "${tarball}" -C "${install_dir}"
|
||||
|
||||
export CLOUDSDK_CORE_DISABLE_PROMPTS=1
|
||||
"${install_dir}/google-cloud-sdk/install.sh" --disable-installation-options --bash-completion=false --path-update=false --usage-reporting=false
|
||||
record_command "${STAGE_PRE}" "install_gcloud" "${install_dir}/google-cloud-sdk/install.sh" --disable-installation-options --bash-completion=false --path-update=false --usage-reporting=false
|
||||
export PATH=${install_dir}/google-cloud-sdk/bin:${PATH}
|
||||
}
|
||||
|
||||
@ -144,7 +183,7 @@ function dump_cluster_logs() {
|
||||
|
||||
### Pre Set Up ###
|
||||
if running_in_docker; then
|
||||
curl -fsSL --retry 3 --keepalive-time 2 -o "${WORKSPACE}/google-cloud-sdk.tar.gz" 'https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz'
|
||||
record_command "${STAGE_PRE}" "download_gcloud" curl -fsSL --retry 3 --keepalive-time 2 -o "${WORKSPACE}/google-cloud-sdk.tar.gz" 'https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz'
|
||||
install_google_cloud_sdk_tarball "${WORKSPACE}/google-cloud-sdk.tar.gz" /
|
||||
if [[ "${KUBERNETES_PROVIDER}" == 'aws' ]]; then
|
||||
pip install awscli
|
||||
@ -290,9 +329,6 @@ if [[ ! "${JOB_NAME}" =~ -pull- ]]; then
|
||||
JENKINS_BUILD_STARTED=true bash <(curl -fsS --retry 3 --keepalive-time 2 "https://raw.githubusercontent.com/kubernetes/kubernetes/master/hack/jenkins/upload-to-gcs.sh")
|
||||
fi
|
||||
|
||||
# Have cmd/e2e run by goe2e.sh generate JUnit report in ${WORKSPACE}/junit*.xml
|
||||
ARTIFACTS=${WORKSPACE}/_artifacts
|
||||
mkdir -p ${ARTIFACTS}
|
||||
# When run inside Docker, we need to make sure all files are world-readable
|
||||
# (since they will be owned by root on the host).
|
||||
trap "chmod -R o+r '${ARTIFACTS}'" EXIT SIGINT SIGTERM
|
||||
@ -411,11 +447,16 @@ fi
|
||||
# * neither started nor destroyed (soak test)
|
||||
if [[ "${E2E_UP:-}" == "${E2E_DOWN:-}" && -f "${gcp_resources_before}" && -f "${gcp_resources_after}" ]]; then
|
||||
difference=$(diff -sw -U0 -F'^\[.*\]$' "${gcp_resources_before}" "${gcp_resources_after}") || true
|
||||
noleak=true
|
||||
if [[ -n $(echo "${difference}" | tail -n +3 | grep -E "^\+") ]] && [[ "${FAIL_ON_GCP_RESOURCE_LEAK:-}" == "true" ]]; then
|
||||
noleak=false
|
||||
fi
|
||||
if ! ${noleak} ; then
|
||||
echo "${difference}"
|
||||
echo "!!! FAIL: Google Cloud Platform resources leaked while running tests!"
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
record_command "${STAGE_CLEANUP}" "gcp_resource_leak_check" ${noleak}
|
||||
fi
|
||||
|
||||
exit ${EXIT_CODE}
|
||||
|
16
third_party/forked/shell2junit/sh2ju.sh
vendored
16
third_party/forked/shell2junit/sh2ju.sh
vendored
@ -43,7 +43,7 @@ function eVal() {
|
||||
# Method to clean old tests
|
||||
function juLogClean() {
|
||||
echo "+++ Removing old junit reports from: $juDIR "
|
||||
rm -f "$juDIR"/TEST-*
|
||||
rm -f "$juDIR"/junit-*
|
||||
}
|
||||
|
||||
# Execute a command and record its results
|
||||
@ -151,23 +151,23 @@ $errMsg
|
||||
"
|
||||
## testsuite block
|
||||
|
||||
if [[ -e "$juDIR/TEST-$suite.xml" ]]; then
|
||||
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/TEST-$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/TEST-$suite.xml"
|
||||
sed -i "0,/errors=\"$failCount\"/ s/errors=\"$failCount\"/errors=\"$errors\"/" "$juDIR/TEST-$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/TEST-$suite.xml ## remove testSuite so we can add it later
|
||||
cat <<EOF >> "$juDIR/TEST-$suite.xml"
|
||||
sed -i "s^</testsuite>^^g" $juDIR/junit-$suite.xml ## remove testSuite so we can add it later
|
||||
cat <<EOF >> "$juDIR/junit-$suite.xml"
|
||||
$content
|
||||
</testsuite>
|
||||
EOF
|
||||
|
||||
else
|
||||
# no file exists. Adding a new file
|
||||
cat <<EOF > "$juDIR/TEST-$suite.xml"
|
||||
cat <<EOF > "$juDIR/junit-$suite.xml"
|
||||
<testsuite failures="$errors" assertions="$assertions" name="$suite" tests="1" errors="$errors" time="$total">
|
||||
$content
|
||||
</testsuite>
|
||||
|
Loading…
Reference in New Issue
Block a user