From 1211204a427ecab48d85e6e8f16b0f1e48b3f5df Mon Sep 17 00:00:00 2001 From: Zhixiong Chi Date: Tue, 19 Jul 2022 20:27:46 -0700 Subject: [PATCH] Debian: stx-init-env: fix --nuke option KeyError exception Add the checking for minikube_exists to avoid the KeyError error, when the command './stx-init-env --nuke' is executed and the minikube cluster doesn't exist. Story: 2009897 Task: 45824 Test Plan: Pass: export MINIKUBENAME=abc ...... './stx-init-env --nuke' works without the KeyError exception. Signed-off-by: Zhixiong Chi Change-Id: I2cf46e01df312604ca2a0afa38a498e7397747b8 --- stx-init-env | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stx-init-env b/stx-init-env index 97b70e8a..ff3170d9 100755 --- a/stx-init-env +++ b/stx-init-env @@ -61,6 +61,8 @@ minikube_exists() { local script=$(cat <<'END' import json,sys data = json.load (sys.stdin) +if 'valid' not in data or 'invalid' not in data: + sys.exit(1) for x in data['valid']+data['invalid']: if x['Name'] == sys.argv[1]: sys.exit(0) @@ -218,6 +220,10 @@ if [ "$STX_PLATFORM" = "minikube" ]; then if minikube_exists ; then notice "Deleting minikube cluster \`$MINIKUBENAME'" $MINIKUBE delete -p "$MINIKUBENAME" || exit 1 + else + notice "Please check your minikube cluster MINIKUBENAME: \`$MINIKUBENAME'." + notice "It doesn't exist or it existed but not for your MINIKUBE_HOME: \`$MINIKUBE_HOME'." + notice "Please re-export the correct project variable pairs!!!" fi exit 0 fi