Skip to content

Commit

Permalink
Handle unexpected error when the test is aborted (#5295)
Browse files Browse the repository at this point in the history
When the conformance test is aborted by Jenkins, the results log
is actually an incomplete file. Since run-k8s-e2e-tests.sh already
checks the result and returns with different exit error codes, we can
check the codes and print the right message. Otherwise, the result will show
`All tests passed.` when the test is actually running and aborted
unexpectedly, which is misleading.

Signed-off-by: Lan Luo <luola@vmware.com>
  • Loading branch information
luolanzone committed Jun 6, 2024
1 parent 5af9311 commit 431eb81
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
15 changes: 11 additions & 4 deletions ci/jenkins/test-rancher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,26 @@ function run_conformance {
kubectl rollout status deployment.apps/antrea-controller -n kube-system
kubectl rollout status daemonset/antrea-agent -n kube-system

set +e
if [[ "$TESTCASE" =~ "conformance" ]]; then
${WORKSPACE}/ci/run-k8s-e2e-tests.sh --e2e-conformance --log-mode $MODE --image-pull-policy ${IMAGE_PULL_POLICY} --kubernetes-version "auto" > ${WORKSPACE}/test-result.log
else
${WORKSPACE}/ci/run-k8s-e2e-tests.sh --e2e-network-policy --log-mode $MODE --image-pull-policy ${IMAGE_PULL_POLICY} --kubernetes-version "auto" > ${WORKSPACE}/test-result.log
fi

cat ${WORKSPACE}/test-result.log
if grep -Fxq "Failed tests:" ${WORKSPACE}/test-result.log; then
echo "Failed cases exist."
TEST_SCRIPT_RC=$?
if [[ $TEST_SCRIPT_RC -eq 0 ]]; then
echo "All tests passed."
echo "=== SUCCESS !!! ==="
elif [[ $TEST_SCRIPT_RC -eq 1 ]]; then
echo "Failed test cases exist."
echo "=== FAILURE !!! ==="
TEST_FAILURE=true
else
echo "All tests passed."
echo "Unexpected error when running tests but not a test failure."
echo "=== FAILURE !!! ==="
fi
set -e
}

function clean_tmp() {
Expand Down
16 changes: 10 additions & 6 deletions ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ function run_conformance {

set +e
kubectl taint nodes --selector='!node-role.kubernetes.io/control-plane' node.cluster.x-k8s.io/uninitialized-
set -e

if [[ "$TESTCASE" == "conformance" ]]; then
${GIT_CHECKOUT_DIR}/ci/run-k8s-e2e-tests.sh --e2e-conformance --e2e-sig-network --log-mode ${MODE} --kubeconfig ${GIT_CHECKOUT_DIR}/jenkins/out/kubeconfig > ${GIT_CHECKOUT_DIR}/vmc-test.log
Expand All @@ -602,14 +601,19 @@ function run_conformance {
${GIT_CHECKOUT_DIR}/ci/run-k8s-e2e-tests.sh --e2e-network-policy --log-mode ${MODE} --kubeconfig ${GIT_CHECKOUT_DIR}/jenkins/out/kubeconfig > ${GIT_CHECKOUT_DIR}/vmc-test.log
fi

cat ${GIT_CHECKOUT_DIR}/vmc-test.log
if grep -Fxq "Failed tests:" ${GIT_CHECKOUT_DIR}/vmc-test.log
then
echo "Failed cases exist."
TEST_SCRIPT_RC=$?
if [[ $TEST_SCRIPT_RC -eq 0 ]]; then
echo "All tests passed."
echo "=== SUCCESS !!! ==="
elif [[ $TEST_SCRIPT_RC -eq 1 ]]; then
echo "Failed test cases exist."
echo "=== FAILURE !!! ==="
TEST_FAILURE=true
else
echo "All tests passed."
echo "Unexpected error when running tests but not a test failure."
echo "=== FAILURE !!! ==="
fi
set -e

if [[ "$COVERAGE" == true ]]; then
rm -rf ${GIT_CHECKOUT_DIR}/conformance-coverage
Expand Down
15 changes: 10 additions & 5 deletions ci/jenkins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -676,15 +676,20 @@ function run_conformance {
else
${WORKSPACE}/ci/run-k8s-e2e-tests.sh --e2e-network-policy --e2e-skip "$NETWORKPOLICY_SKIP" --log-mode $MODE --image-pull-policy ${IMAGE_PULL_POLICY} --kubernetes-version "auto" > ${WORKSPACE}/test-result.log
fi
set -e

cat ${WORKSPACE}/test-result.log
if grep -Fxq "Failed tests:" ${WORKSPACE}/test-result.log; then
echo "Failed cases exist."
TEST_SCRIPT_RC=$?
if [[ $TEST_SCRIPT_RC -eq 0 ]]; then
echo "All tests passed."
echo "=== SUCCESS !!! ==="
elif [[ $TEST_SCRIPT_RC -eq 1 ]]; then
echo "Failed test cases exist."
echo "=== FAILURE !!! ==="
TEST_FAILURE=true
else
echo "All tests passed."
echo "Unexpected error when running tests but not a test failure."
echo "=== FAILURE !!! ==="
fi
set -e
}

function run_e2e_windows {
Expand Down

0 comments on commit 431eb81

Please sign in to comment.