From a5c1e02e0e67f75f4120450981ce1624fdba6bb3 Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Thu, 23 Jun 2016 15:51:38 -0700 Subject: [PATCH 1/2] add junit recording in e2e runner --- hack/jenkins/e2e-runner.sh | 51 ++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/hack/jenkins/e2e-runner.sh b/hack/jenkins/e2e-runner.sh index c93b6d9cd0e..12c09ffde08 100755 --- a/hack/jenkins/e2e-runner.sh +++ b/hack/jenkins/e2e-runner.sh @@ -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" / fi @@ -280,9 +319,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 @@ -401,11 +437,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} From 586bb1f02877d2988b7ba273e5455f82a4a21a75 Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Tue, 28 Jun 2016 15:02:36 -0700 Subject: [PATCH 2/2] rename junit file --- third_party/forked/shell2junit/sh2ju.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/third_party/forked/shell2junit/sh2ju.sh b/third_party/forked/shell2junit/sh2ju.sh index 866ea504e55..d96e7b7a98f 100755 --- a/third_party/forked/shell2junit/sh2ju.sh +++ b/third_party/forked/shell2junit/sh2ju.sh @@ -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^^^g" $juDIR/TEST-$suite.xml ## remove testSuite so we can add it later - cat <> "$juDIR/TEST-$suite.xml" + sed -i "s^^^g" $juDIR/junit-$suite.xml ## remove testSuite so we can add it later + cat <> "$juDIR/junit-$suite.xml" $content EOF else # no file exists. Adding a new file - cat < "$juDIR/TEST-$suite.xml" + cat < "$juDIR/junit-$suite.xml" $content