Skip to content

Commit b8c4144

Browse files
committed
First stab at semiautomation.
1 parent 1a6101c commit b8c4144

File tree

5 files changed

+205
-0
lines changed

5 files changed

+205
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Semiautomation for the acceptance test
2+
3+
This is a collection of tools to perform the acceptance test faster.
4+
5+
## Prerequisites
6+
7+
- k8s cluster set up with `kubectl`
8+
- `fish` shell installed
9+
- `curl` installed
10+
- Obi's generated templates in a subdirectory called `generated`
11+
12+
## Usage
13+
14+
Execute the tests like this:
15+
16+
./test1a.fish
17+
18+
and follow the instructions.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
function printheader
2+
echo "Test : $TESTNAME"
3+
echo "Description : $TESTDESC"
4+
echo "Yaml file : $YAMLFILE"
5+
echo "Deployment name : $DEPLOYMENT"
6+
echo
7+
end
8+
9+
function waitForKubectl
10+
if test (count $argv) -lt 5
11+
return 1
12+
end
13+
set -l op (string split -- " " $argv[1])
14+
set -l select $argv[2]
15+
set -l good (string split -- ";" "$argv[3]")
16+
set -l expected $argv[4]
17+
set -l timeout $argv[5]
18+
19+
echo
20+
echo "Testing `kubectl $op`"
21+
echo " for occurrences of `$select`"
22+
echo " that are `$good`, expecting `$expected`"
23+
echo
24+
25+
set -l t 0
26+
while true
27+
set -l l (kubectl $op | grep $select)
28+
set -l nfound (count $l)
29+
set -l ngood 0
30+
for line in $l
31+
if string match -r $good $line > /dev/null
32+
set ngood (math $ngood + 1)
33+
end
34+
end
35+
echo -n "Good=$ngood, found=$nfound, expected=$expected, try $t ($timeout)"
36+
echo -n -e "\r"
37+
if test $ngood -eq $expected -a $nfound -eq $expected ; echo ; return 0 ; end
38+
if test $t -gt $timeout ; echo ; echo Timeout ; return 2 ; end
39+
set t (math $t + 1)
40+
sleep 1
41+
end
42+
end
43+
44+
function output
45+
if which say > /dev/null
46+
say $argv[1] > /dev/null ^ /dev/null
47+
end
48+
for l in $argv[2..-1] ; echo $l ; end
49+
end
50+
51+
function log
52+
echo "$argv[1] Test: $TESTNAME, Desc: $TESTDESC" >> testprotocol.log
53+
end
54+
55+
function inputAndLogResult
56+
read -P "Test result: " result
57+
log $result
58+
end
59+
60+
function waitForUser
61+
read -P "Hit enter to continue"
62+
end
63+
64+
function getLoadBalancerIP
65+
string trim -c '"' (kubectl get service $argv[1] -o=json | \
66+
jq .status.loadBalancer.ingress[0].ip)
67+
end
68+
69+
function testArangoDB
70+
set -l ip $argv[1]
71+
set -l timeout $argv[2]
72+
set -l n 0
73+
echo Waiting for ArangoDB to be ready...
74+
while true
75+
if set v (curl -k -s -m 3 "https://$ip:8529/_api/version" --user root: | jq .server)
76+
if test "$v" = '"arango"' ; return 0 ; end
77+
end
78+
set n (math $n + 1)
79+
if test "$n" -gt "$timeout"
80+
echo Timeout
81+
return 1
82+
end
83+
echo Waiting "$n($timeout)"...
84+
end
85+
end
86+
87+
function fail
88+
output "Failed" $argv
89+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/fish
2+
3+
source helper.fish
4+
5+
set -g TESTNAME test1a
6+
set -g TESTDESC "Deployment of mode single"
7+
set -g YAMLFILE generated/single-community-dev.yaml
8+
set -g DEPLOYMENT acceptance-single
9+
printheader
10+
11+
# Deploy and check
12+
kubectl apply -f $YAMLFILE
13+
and waitForKubectl "get pod" "$DEPLOYMENT-sngl" "1/1 *Running" 1 120
14+
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
15+
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 120
16+
or fail "Deployment did not get ready."
17+
18+
# Automatic check
19+
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
20+
testArangoDB $ip 60
21+
or fail "ArangoDB was not reachable."
22+
23+
# Manual check
24+
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
25+
inputAndLogResult
26+
27+
# Cleanup
28+
kubectl delete -f $YAMLFILE
29+
waitForKubectl "get pod" $DEPLOYMENT-sngl "" 0 120
30+
or fail "Could not delete deployment."
31+
32+
output "Ready" ""
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/fish
2+
3+
source helper.fish
4+
5+
set -g TESTNAME test1b
6+
set -g TESTDESC "Deployment of mode active/failover"
7+
set -g YAMLFILE generated/activefailover-community-pro.yaml
8+
set -g DEPLOYMENT acceptance-activefailover
9+
printheader
10+
11+
# Deploy and check
12+
kubectl apply -f $YAMLFILE
13+
and waitForKubectl "get pod" $DEPLOYMENT "1 *Running" 5 120
14+
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*1/1 *Running" "" 1 120
15+
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*0/1 *Running" "" 1 120
16+
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
17+
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 120
18+
or fail "Deployment did not get ready."
19+
20+
# Automatic check
21+
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
22+
testArangoDB $ip 60
23+
or fail "ArangoDB was not reachable."
24+
25+
# Manual check
26+
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
27+
inputAndLogResult
28+
29+
# Cleanup
30+
kubectl delete -f $YAMLFILE
31+
waitForKubectl "get pod" $DEPLOYMENT "" 0 120
32+
or fail "Could not delete deployment."
33+
34+
output "Ready" ""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/fish
2+
3+
source helper.fish
4+
5+
set -g TESTNAME test1b
6+
set -g TESTDESC "Deployment of mode cluster (enterprise)"
7+
set -g YAMLFILE generated/cluster-enterprise-dev.yaml
8+
set -g DEPLOYMENT acceptance-cluster
9+
printheader
10+
11+
# Deploy and check
12+
kubectl apply -f $YAMLFILE
13+
and waitForKubectl "get pod" $DEPLOYMENT "1/1 *Running" 9 120
14+
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
15+
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 120
16+
or fail "Deployment did not get ready."
17+
18+
# Automatic check
19+
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
20+
testArangoDB $ip 60
21+
or fail "ArangoDB was not reachable."
22+
23+
# Manual check
24+
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
25+
inputAndLogResult
26+
27+
# Cleanup
28+
kubectl delete -f $YAMLFILE
29+
waitForKubectl "get pod" $DEPLOYMENT "" 0 120
30+
or fail "Could not delete deployment."
31+
32+
output "Ready" ""

0 commit comments

Comments
 (0)