forked from coin8086/hpcpack-rest-bvt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·92 lines (76 loc) · 1.88 KB
/
test.sh
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
#!/bin/bash
host=${BVT_HOST:?'BVT host should be specified by env var BVT_HOST!'}
username=${BVT_USERNAME:?'BVT user name should be specified by env var BVT_USERNAME!'}
password=${BVT_PASSWORD:?'BVT user password should be specified by env var BVT_PASSWORD!'}
apibase="https://$host/hpc"
req_cmd="request.cmd"
res_code="respose.code"
res_head="respose.head"
res_body="respose.body"
curl_err="curl.error"
function curl {
cmd="curl -k -u \"$username:$password\" -o \"$res_body\" -D \"$res_head\" -w \"%{http_code}\" -sS $@ 2>\"$curl_err\""
echo "$cmd" > "$req_cmd"
eval "command $cmd"
}
function assert_ok {
(( "$?" == 0 )) || exit 1
}
function assert_2xx {
[[ "$1" =~ ^20[0-9]$ ]] || exit 1
}
function assert_regex {
[[ "$1" =~ $2 ]] || exit 1
}
function assert_gte {
(( "$1" >= "$2" )) || exit 1
}
function validate_json_string {
read -r -d '' script <<'EOS'
import sys, json
a = json.load(sys.stdin)
if not isinstance(a, str):
raise AssertionError
print(len(a))
EOS
python3 -c "$script" <<<$1
(( $? == 0 )) || exit 1
}
function validate_json_array {
read -r -d '' script <<'EOS'
import sys, json
a = json.load(sys.stdin)
if not isinstance(a, list):
raise AssertionError
print(len(a))
EOS
python3 -c "$script" <<<$1
(( $? == 0 )) || exit 1
}
res=$(curl "$apibase/cluster/version")
assert_ok
assert_2xx "$res"
body=$(< "$res_body")
assert_regex "$body" '^\"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"$'
res=$(curl "$apibase/cluster/activeHeadNode")
assert_ok
assert_2xx "$res"
body=$(< "$res_body")
size=$(validate_json_string "$body")
assert_ok
assert_gte "$size" 1
res=$(curl "$apibase/cluster/info/dateTimeFormat")
assert_ok
assert_2xx "$res"
body=$(< "$res_body")
size=$(validate_json_string "$body")
assert_ok
assert_gte "$size" 1
res=$(curl "$apibase/nodes")
assert_ok
assert_2xx "$res"
body=$(< "$res_body")
size=$(validate_json_array "$body")
assert_ok
assert_gte "$size" 1
echo "OK"