prow.sh: more efficient execution of individual tests

When running only some tests, sometimes extra, unnecessarily work was
done, like bringing up the cluster without alpha gates.
This commit is contained in:
Patrick Ohly
2019-04-08 08:51:11 +02:00
parent f3d1d2df5c
commit aa45a1cd9b

78
prow.sh
View File

@@ -202,18 +202,30 @@ configvar CSI_PROW_SANITY_CONTAINER "hostpath" "Kubernetes container with CSI dr
# is off by default. A CSI driver can change that default in its .prow.sh
# by setting CSI_PROW_TESTS_SANITY.
configvar CSI_PROW_TESTS "unit parallel serial parallel-alpha serial-alpha ${CSI_PROW_TESTS_SANITY}" "tests to run"
test_enabled () {
local test="$1"
# We want word-splitting here, so ignore: Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2086
set ${CSI_PROW_TESTS}
for t in "$@"; do
if [ "$t" = "$test" ]; then
tests_enabled () {
local t1 t2
# We want word-splitting here, so ignore: Quote to prevent word splitting, or split robustly with mapfile or read -a.
# shellcheck disable=SC2206
local tests=(${CSI_PROW_TESTS})
for t1 in "$@"; do
for t2 in "${tests[@]}"; do
if [ "$t1" = "$t2" ]; then
return
fi
done
done
return 1
}
tests_need_kind () {
tests_enabled "sanity" "parallel" "serial" "serial-alpha" "parallel-alpha"
}
tests_need_non_alpha_cluster () {
tests_enabled "sanity" "parallel" "serial"
}
tests_need_alpha_cluster () {
tests_enabled "parallel-alpha" "serial-alpha"
}
# Serial vs. parallel is always determined by these regular expressions.
# Individual regular expressions are seperated by spaces for readability
@@ -521,6 +533,15 @@ install_hostpath () {
return 1
fi
if ${CSI_PROW_BUILD_JOB}; then
# Ignore: Double quote to prevent globbing and word splitting.
# Ignore: To read lines rather than words, pipe/redirect to a 'while read' loop.
# shellcheck disable=SC2086 disable=SC2013
for i in $(grep '^\s*CMDS\s*=' Makefile | sed -e 's/\s*CMDS\s*=//'); do
kind load docker-image --name csi-prow $i:csiprow || die "could not load the $i:latest image into the kind cluster"
done
fi
if deploy_hostpath="$(find_deployment "$(pwd)/deploy")"; then
:
elif [ "${CSI_PROW_HOSTPATH_REPO}" = "none" ]; then
@@ -836,7 +857,7 @@ main () {
# might have been minor or unavoidable, for example when experimenting with
# changes in "release-tools" in a PR (that fails the "is release-tools unmodified"
# test).
if test_enabled "unit"; then
if tests_enabled "unit"; then
if ! run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make -k test 2>&1 | make_test_to_junit; then
warn "'make test' failed, proceeding anyway"
ret=1
@@ -846,8 +867,8 @@ main () {
run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make container || die "'make container' failed"
fi
if tests_need_kind; then
install_kind || die "installing kind failed"
start_cluster || die "starting the cluster failed"
if ${CSI_PROW_BUILD_JOB}; then
cmds="$(grep '^\s*CMDS\s*=' Makefile | sed -e 's/\s*CMDS\s*=//')"
@@ -863,7 +884,6 @@ main () {
# always pulling the image
# (https://github.com/kubernetes-sigs/kind/issues/328).
docker tag "$i:latest" "$i:csiprow" || die "tagging the locally built container image for $i failed"
kind load docker-image --name csi-prow "$i:csiprow" || die "could not load the $i:latest image into the kind cluster"
done
if [ -e deploy/kubernetes/rbac.yaml ]; then
@@ -878,21 +898,20 @@ main () {
fi
fi
# Installing the driver might be disabled, in which case we bail out early.
if ! install_hostpath "$images"; then
info "hostpath driver installation disabled, skipping E2E testing"
return "$ret"
fi
if tests_need_non_alpha_cluster; then
start_cluster || die "starting the non-alpha cluster failed"
# Installing the driver might be disabled.
if install_hostpath "$images"; then
collect_cluster_info
if test_enabled "sanity"; then
if tests_enabled "sanity"; then
if ! run_sanity; then
ret=1
fi
fi
if test_enabled "parallel"; then
if tests_enabled "parallel"; then
# Ignore: Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2086
if ! run_e2e parallel ${CSI_PROW_GINKO_PARALLEL} \
@@ -903,7 +922,7 @@ main () {
fi
fi
if test_enabled "serial"; then
if tests_enabled "serial"; then
if ! run_e2e serial \
-focus="External.Storage.*($(regex_join "${CSI_PROW_E2E_SERIAL}"))" \
-skip="$(regex_join "${CSI_PROW_E2E_ALPHA}" "${CSI_PROW_E2E_SKIP}")"; then
@@ -911,21 +930,18 @@ main () {
ret=1
fi
fi
fi
fi
if (test_enabled "parallel-alpha" || test_enabled "serial-alpha") && [ "${CSI_PROW_E2E_ALPHA_GATES}" ]; then
if tests_need_alpha_cluster && [ "${CSI_PROW_E2E_ALPHA_GATES}" ]; then
# Need to (re)create the cluster.
start_cluster "${CSI_PROW_E2E_ALPHA_GATES}" || die "starting alpha cluster failed"
if ${CSI_PROW_BUILD_JOB}; then
# Ignore: Double quote to prevent globbing and word splitting.
# Ignore: To read lines rather than words, pipe/redirect to a 'while read' loop.
# shellcheck disable=SC2086 disable=SC2013
for i in $(grep '^\s*CMDS\s*=' Makefile | sed -e 's/\s*CMDS\s*=//'); do
kind load docker-image --name csi-prow $i:csiprow || die "could not load the $i:latest image into the kind cluster"
done
fi
install_hostpath "$images" || die "hostpath driver installation failed unexpectedly on alpha cluster"
if test_enabled "parallel-alpha"; then
# Installing the driver might be disabled.
if install_hostpath "$images"; then
collect_cluster_info
if tests_enabled "parallel-alpha"; then
# Ignore: Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2086
if ! run_e2e parallel-alpha ${CSI_PROW_GINKO_PARALLEL} \
@@ -936,7 +952,7 @@ main () {
fi
fi
if test_enabled "serial-alpha"; then
if tests_enabled "serial-alpha"; then
if ! run_e2e serial-alpha \
-focus="External.Storage.*(($(regex_join "${CSI_PROW_E2E_SERIAL}")).*($(regex_join "${CSI_PROW_E2E_ALPHA}"))|($(regex_join "${CSI_PROW_E2E_ALPHA}")).*($(regex_join "${CSI_PROW_E2E_SERIAL}")))" \
-skip="$(regex_join "${CSI_PROW_E2E_SKIP}")"; then
@@ -945,6 +961,8 @@ main () {
fi
fi
fi
fi
fi
# Merge all junit files into one. This gets rid of duplicated "skipped" tests.
if ls "${ARTIFACTS}"/junit_*.xml 2>/dev/null >&2; then