From 0f92c9cfd711147340ded088361916f2c6ed218e Mon Sep 17 00:00:00 2001 From: Gabriela Cervantes Date: Wed, 31 Jan 2024 17:05:47 +0000 Subject: [PATCH] tests: Improve variable definition in test/e2e scripts To have a better consistency across the test/e2e scripts this PR improves the variable definition by using local as a best practice. Signed-off-by: Gabriela Cervantes --- tests/e2e/lib.sh | 6 +++--- tests/e2e/operator.sh | 10 +++++----- tests/e2e/run-local.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/e2e/lib.sh b/tests/e2e/lib.sh index 0452644d..7a0181b4 100644 --- a/tests/e2e/lib.sh +++ b/tests/e2e/lib.sh @@ -104,9 +104,9 @@ wait_pods() { # Note: copied from kata-containers/tests/lib/common.bash # wait_for_process() { - wait_time="$1" - sleep_time="$2" - cmd="$3" + local wait_time="$1" + local sleep_time="$2" + local cmd="$3" while [ "$wait_time" -gt 0 ]; do if eval "$cmd"; then return 0 diff --git a/tests/e2e/operator.sh b/tests/e2e/operator.sh index 601c808d..a4e17f3d 100755 --- a/tests/e2e/operator.sh +++ b/tests/e2e/operator.sh @@ -147,7 +147,7 @@ install_ccruntime() { # Check if the runtime is up. # There could be a case where it is not even if the pods above are running. - cmd="kubectl get runtimeclass | grep -q ${runtimeclass}" + local cmd="kubectl get runtimeclass | grep -q ${runtimeclass}" if ! wait_for_process 300 30 "$cmd"; then echo "::error:: runtimeclass ${runtimeclass} is not up" return 1 @@ -260,11 +260,11 @@ uninstall_operator() { # wait_for_stabilization() { declare -A restart_counts - iteration=0 - count=0 + local iteration=0 + local count=0 while true; do - change=0 - pod_info=$(kubectl get pods -n "$op_ns" -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{range .status.containerStatuses[*]}{.name}{" "}{.restartCount}{"\n"}{end}{end}') + local change=0 + local pod_info=$(kubectl get pods -n "$op_ns" -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{range .status.containerStatuses[*]}{.name}{" "}{.restartCount}{"\n"}{end}{end}') while read -r pod container restart_count; do if [ "${restart_counts[$pod-$container]--1}" != "$restart_count" ]; then diff --git a/tests/e2e/run-local.sh b/tests/e2e/run-local.sh index 38bde695..26d113d4 100755 --- a/tests/e2e/run-local.sh +++ b/tests/e2e/run-local.sh @@ -114,7 +114,7 @@ main() { run 20m sudo -E PATH="$PATH" bash -c './operator.sh' echo "::info:: Run tests" - cmd="run 20m sudo -E PATH=\"$PATH\" bash -c " + local cmd="run 20m sudo -E PATH=\"$PATH\" bash -c " if [ -z "$runtimeclass" ]; then cmd+="'./tests_runner.sh'" else