Skip to content

Commit 34854bd

Browse files
committed
fix(e2e): require numeric preserve flag
Accept only 0 or 1 for the Kubernetes preservation option and cover the rejection of boolean aliases before resource creation. Fixes: NVIDIA#3675 Signed-off-by: Daneyon Hansen <[email protected]>
1 parent 0bff5c4 commit 34854bd

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

‎e2e/with-kube-gateway.sh‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ e2e_align_docker_host_with_cli_context
9090

9191
PRESERVE_CLUSTER="${OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER:-0}"
9292
case "${PRESERVE_CLUSTER}" in
93-
0 | false | FALSE | no | NO) PRESERVE_CLUSTER=0 ;;
94-
1 | true | TRUE | yes | YES) PRESERVE_CLUSTER=1 ;;
93+
0 | 1) ;;
9594
*)
96-
echo "ERROR: OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER must be a boolean (0/1, true/false, or yes/no)" >&2
95+
echo "ERROR: OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER must be 0 or 1" >&2
9796
exit 2
9897
;;
9998
esac

‎tasks/scripts/test-kubernetes-e2e-preserve.sh‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,24 @@ run_harness() {
8686
RUN_COMMAND_LOG="${command_log}"
8787
}
8888

89-
# Invalid values fail before the wrapper creates a work directory or cluster.
90-
INVALID_TMP="${TMP_ROOT}/invalid"
91-
INVALID_OUT="${TMP_ROOT}/invalid.out"
92-
mkdir -p "${INVALID_TMP}"
93-
set +e
94-
TMPDIR="${INVALID_TMP}" OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER=invalid \
95-
bash "${WRAPPER}" /bin/true >"${INVALID_OUT}" 2>&1
96-
invalid_status=$?
97-
set -e
98-
[ "${invalid_status}" -eq 2 ] || fail "invalid value returned ${invalid_status}, expected 2"
99-
assert_contains "${INVALID_OUT}" "OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER must be a boolean"
100-
if find "${INVALID_TMP}" -mindepth 1 -print -quit | grep -q .; then
101-
fail "invalid value created a work directory"
102-
fi
89+
# Invalid values, including boolean aliases, fail before the wrapper creates a
90+
# work directory or cluster.
91+
for invalid_value in invalid true; do
92+
INVALID_TMP="${TMP_ROOT}/invalid-${invalid_value}"
93+
INVALID_OUT="${TMP_ROOT}/invalid-${invalid_value}.out"
94+
mkdir -p "${INVALID_TMP}"
95+
set +e
96+
TMPDIR="${INVALID_TMP}" OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER="${invalid_value}" \
97+
bash "${WRAPPER}" /bin/true >"${INVALID_OUT}" 2>&1
98+
invalid_status=$?
99+
set -e
100+
[ "${invalid_status}" -eq 2 ] \
101+
|| fail "invalid value ${invalid_value} returned ${invalid_status}, expected 2"
102+
assert_contains "${INVALID_OUT}" "OPENSHELL_E2E_KUBE_PRESERVE_CLUSTER must be 0 or 1"
103+
if find "${INVALID_TMP}" -mindepth 1 -print -quit | grep -q .; then
104+
fail "invalid value ${invalid_value} created a work directory"
105+
fi
106+
done
103107

104108
# Preservation is independent of the wrapped command's success or failure.
105109
run_harness preserve-success 1 1 0

0 commit comments

Comments
 (0)