-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_runner.sh
More file actions
111 lines (89 loc) · 2.59 KB
/
test_runner.sh
File metadata and controls
111 lines (89 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
PROGRAM="${0##*/}"
TEST_NAME=""
usage() {
echo "Usage: $PROGRAM TEST_NAME"
}
teardown() {
if [[ "$TB_NAME" != "" ]]; then
if [[ "$LOG_PATH" != "" ]]; then
minikube delete -p ${TB_NAME} 2>&1 >> ${LOG_PATH}
else
minikube delete -p ${TB_NAME}
fi
fi
}
die() {
teardown
echo "$PROGRAM: $*" >&2
exit 1
}
json_tb() {
python3 -c "import sys, test; test.Test.model_validate_json(sys.stdin.read()).print_values()"
}
parse_options() {
TEMP=$(getopt -o h --long help -- "$@")
if [ $? != 0 ]; then exit 1; fi
eval set -- "$TEMP"
while true; do
case "$1" in
-h | --help)
usage
exit 0
;;
--)
shift
break
;;
esac
done
TEST_NAME="$1"
}
parse_options "$@"
LOG_PATH="/tmp/test-${TEST_NAME}-$(TZ='America/Chicago' date +%Z-%m_%d_%Y-%H_%M_%S).log"
# Ensure that the test setup directory exists
TEST_DIR="./troubleshooting/${TEST_NAME}"
GOOSE="${TEST_DIR}/goose.sh"
TESTBENCH="${TEST_DIR}/testbench.json"
if [[ "$TEST_NAME" == "" ]]; then
die "No test specified"
elif ! [ -d "$TEST_DIR" ] || ! [ -f "$GOOSE" ] || ! [ -f "$TESTBENCH" ]; then
die "Directory '$TEST_DIR' does not exist or goose/testbench files are missing"
fi
# Get testbench parameters
_parsed=(`json_tb < ${TESTBENCH}`)
if [ "$?" -ne 0 ]; then
die "Failed to read testbench parameters"
fi
INVERT_TEST_RESULT=${_parsed[0]}
NUM_NODES=${_parsed[1]}
TB_NAME=${_parsed[2]}
unset _parsed
touch "$LOG_PATH"
# Make sure minikube uses kvm for creating nodes
minikube config set driver kvm2 >> ${LOG_PATH} 2>&1
# Create cluster
minikube start --driver=kvm2 --cni=calico -p ${TB_NAME} -n $(( ${NUM_NODES} + 1 )) >> $LOG_PATH 2>&1 || die "Failed to create testbench '$TB_NAME'"
# This was used when the test runner had the option to not initialize a cluster, so we could verify the cluster existed
#minikube -p ${TB_NAME} node list 2>&1 >/dev/null || NO_TEARDOWN=true die "Testbench '${TB_NAME}' does not exist"
# Apply test case to k8s cluster
echo -n "Test [${TEST_NAME}]... "
exit_code=( 0 )
statement=$(cd ${TEST_DIR}; . ../util/catch.sh && export -f catch && cluster_name=${TB_NAME} ./goose.sh 2>> $LOG_PATH)
if [ "$?" -ne 0 ]; then
echo "ERROR :|"
die "Test script ${TEST_NAME} failed to complete"
fi
python3 kubellm_json.py <<< "$statement" >> "$LOG_PATH" 2>&1
exit_code="$?"
if [ "$exit_code" -eq 1 ]; then
echo "ERROR :|"
die "KubeLLM failed to complete"
elif [ "$exit_code" -eq 2 ]; then
echo "FAILED :("
elif [ "$exit_code" -eq 0 ]; then
echo "PASSED :)"
fi
# Testing finished, teardown cluster
teardown || echo "Failed to delete testbench '$TB_NAME'"
exit $exit_code