Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First stab at semiautomation. #280

Merged
merged 12 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions manifests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ arango-deployment-dev.yaml
arango-deployment-replication-dev.yaml
arango-storage-dev.yaml
arango-test-dev.yaml
arango-crd-dev.yaml
5 changes: 4 additions & 1 deletion tests/acceptance/cluster-local-storage.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ spec:
externalAccess:
type: LoadBalancer
mode: Cluster
storageClassName: acceptance
agents:
storageClassName: acceptance
dbservers:
storageClassName: acceptance
3 changes: 3 additions & 0 deletions tests/acceptance/cluster-sync.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ spec:
mode: Cluster
sync:
enabled: true
externalAccess:
type: LoadBalancer
accessPackageSecretNames: ["src-accesspackage"]
14 changes: 14 additions & 0 deletions tests/acceptance/cluster-sync2.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "acceptance-cluster2"
spec:
environment: @ENVIRONMENT@
image: @IMAGE@
externalAccess:
type: LoadBalancer
mode: Cluster
sync:
enabled: true
externalAccess:
type: LoadBalancer
2 changes: 2 additions & 0 deletions tests/acceptance/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ version="arangodb-preview:3.4.0-rc.3"
enterprise_secret="$ARANGO_EP_SECRET" #only the number
community="arangodb/$version"
enterprise="registry.arangodb.com/arangodb/$version-$enterprise_secret"
community="neunhoef/arangodb:3.4"
enterprise="neunhoef/arangodb:3.4"

rm -fr generated
mkdir -p generated
Expand Down
9 changes: 9 additions & 0 deletions tests/acceptance/local-storage.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: "storage.arangodb.com/v1alpha"
kind: "ArangoLocalStorage"
metadata:
name: "acceptance-local-storage"
spec:
storageClass:
name: acceptance
localPath:
- /var/lib/acceptance-test
18 changes: 18 additions & 0 deletions tests/acceptance/semiautomation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Semiautomation for the acceptance test

This is a collection of tools to perform the acceptance test faster.

## Prerequisites

- k8s cluster set up with `kubectl`
- `fish` shell installed
- `curl` installed
- Obi's generated templates in a subdirectory called `generated`

## Usage

Execute the tests like this:

./test1a.fish

and follow the instructions.
93 changes: 93 additions & 0 deletions tests/acceptance/semiautomation/helper.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
function printheader
echo "Test : $TESTNAME"
echo "Description : $TESTDESC"
echo "Yaml file : $YAMLFILE"
echo "Deployment name : $DEPLOYMENT"
echo
end

function waitForKubectl
if test (count $argv) -lt 5
return 1
end
set -l op (string split -- " " $argv[1])
set -l select $argv[2]
set -l good (string split -- ";" "$argv[3]")
set -l expected $argv[4]
set -l timeout $argv[5]

echo
echo "Testing `kubectl $op`"
echo " for occurrences of `$select`"
echo " that are `$good`, expecting `$expected`"
echo

set -l t 0
while true
set -l l (kubectl $op | grep $select)
set -l nfound (count $l)
set -l ngood 0
for line in $l
if string match -r $good $line > /dev/null
set ngood (math $ngood + 1)
end
end
echo -n "Good=$ngood, found=$nfound, expected=$expected, try $t ($timeout)"
echo -n -e "\r"
if test $ngood -eq $expected -a $nfound -eq $expected ; echo ; return 0 ; end
if test $t -gt $timeout ; echo ; echo Timeout ; return 2 ; end
set t (math $t + 1)
sleep 1
end
end

function output
if which say > /dev/null
say $argv[1] > /dev/null ^ /dev/null
end
echo
for l in $argv[2..-1] ; echo $l ; end
end

function log
echo "$argv[1] Test: $TESTNAME, Desc: $TESTDESC" >> testprotocol.log
end

function inputAndLogResult
read -P "Test result: " result
log $result
echo
end

function waitForUser
read -P "Hit enter to continue"
end

function getLoadBalancerIP
string trim -c '"' (kubectl get service $argv[1] -o=json | \
jq .status.loadBalancer.ingress[0].ip)
end

function testArangoDB
set -l ip $argv[1]
set -l timeout $argv[2]
set -l n 0
echo Waiting for ArangoDB to be ready...
while true
if set v (curl -k -s -m 3 "https://$ip:8529/_api/version" --user root: | jq .server)
if test "$v" = '"arango"' ; return 0 ; end
end
set n (math $n + 1)
if test "$n" -gt "$timeout"
echo Timeout
return 1
end
echo Waiting "$n($timeout)"...
sleep 1
end
end

function fail
output "Failed" $argv
exit 1
end
13 changes: 13 additions & 0 deletions tests/acceptance/semiautomation/replication.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: "replication.database.arangodb.com/v1alpha"
kind: "ArangoDeploymentReplication"
metadata:
name: "replication-internal"
spec:
source:
masterEndpoint: ["https://@ADDRESS@:8629"]
auth:
keyfileSecretName: src-accesspackage-auth
tls:
caSecretName: src-accesspackage-ca
destination:
deploymentName: "acceptance-cluster2"
32 changes: 32 additions & 0 deletions tests/acceptance/semiautomation/test1a.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/fish

source helper.fish

set -g TESTNAME test1a
set -g TESTDESC "Deployment of mode single (development)"
set -g YAMLFILE generated/single-community-dev.yaml
set -g DEPLOYMENT acceptance-single
printheader

# Deploy and check
kubectl apply -f $YAMLFILE
and waitForKubectl "get pod" "$DEPLOYMENT-sngl" "1/1 *Running" 1 120
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 180
or fail "Deployment did not get ready."

# Automatic check
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
testArangoDB $ip 120
or fail "ArangoDB was not reachable."

# Manual check
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
inputAndLogResult

# Cleanup
kubectl delete -f $YAMLFILE
waitForKubectl "get pod" $DEPLOYMENT-sngl "" 0 120
or fail "Could not delete deployment."

output "Ready" ""
34 changes: 34 additions & 0 deletions tests/acceptance/semiautomation/test1b.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/fish

source helper.fish

set -g TESTNAME test1b
set -g TESTDESC "Deployment of mode active/failover (development)"
set -g YAMLFILE generated/activefailover-community-dev.yaml
set -g DEPLOYMENT acceptance-activefailover
printheader

# Deploy and check
kubectl apply -f $YAMLFILE
and waitForKubectl "get pod" $DEPLOYMENT "1 *Running" 5 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*1/1 *Running" "" 1 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*0/1 *Running" "" 1 120
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 180
or fail "Deployment did not get ready."

# Automatic check
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
testArangoDB $ip 120
or fail "ArangoDB was not reachable."

# Manual check
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
inputAndLogResult

# Cleanup
kubectl delete -f $YAMLFILE
waitForKubectl "get pod" $DEPLOYMENT "" 0 120
or fail "Could not delete deployment."

output "Ready" ""
34 changes: 34 additions & 0 deletions tests/acceptance/semiautomation/test1c.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/fish

source helper.fish

set -g TESTNAME test1c
set -g TESTDESC "Deployment of mode cluster (development, enterprise)"
set -g YAMLFILE generated/cluster-enterprise-dev.yaml
set -g DEPLOYMENT acceptance-cluster
printheader

# Deploy and check
kubectl apply -f $YAMLFILE
and waitForKubectl "get pod" "$DEPLOYMENT-prmr" "1/1 *Running" 3 120
and waitForKubectl "get pod" "$DEPLOYMENT-agnt" "1/1 *Running" 3 120
and waitForKubectl "get pod" "$DEPLOYMENT-crdn" "1/1 *Running" 3 120
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 180
or fail "Deployment did not get ready."

# Automatic check
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
testArangoDB $ip 120
or fail "ArangoDB was not reachable."

# Manual check
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
inputAndLogResult

# Cleanup
kubectl delete -f $YAMLFILE
waitForKubectl "get pod" $DEPLOYMENT "" 0 120
or fail "Could not delete deployment."

output "Ready" ""
38 changes: 38 additions & 0 deletions tests/acceptance/semiautomation/test1d.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/fish

source helper.fish

set -g TESTNAME test1d
set -g TESTDESC "Deployment of mode cluster with sync (development, enterprise)"
set -g YAMLFILE generated/cluster-sync-enterprise-dev.yaml
set -g DEPLOYMENT acceptance-cluster
printheader

# Deploy and check
kubectl apply -f $YAMLFILE
and waitForKubectl "get pod" "$DEPLOYMENT" "1/1 *Running" 15 120
and waitForKubectl "get pod" "$DEPLOYMENT-prmr" "1/1 *Running" 3 120
and waitForKubectl "get pod" "$DEPLOYMENT-agnt" "1/1 *Running" 3 120
and waitForKubectl "get pod" "$DEPLOYMENT-crdn" "1/1 *Running" 3 120
and waitForKubectl "get pod" "$DEPLOYMENT-syma" "1/1 *Running" 3 120
and waitForKubectl "get pod" "$DEPLOYMENT-sywo" "1/1 *Running" 3 120
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 180
and waitForKubectl "get service" "$DEPLOYMENT-sync *LoadBalancer" "-v;pending" 1 180
or fail "Deployment did not get ready."

# Automatic check
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
testArangoDB $ip 120
or fail "ArangoDB was not reachable."

# Manual check
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
inputAndLogResult

# Cleanup
kubectl delete -f $YAMLFILE
waitForKubectl "get pod" $DEPLOYMENT "" 0 120
or fail "Could not delete deployment."

output "Ready" ""
50 changes: 50 additions & 0 deletions tests/acceptance/semiautomation/test2a.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/fish

source helper.fish

set -g TESTNAME test2a
set -g TESTDESC "Scale an active failover deployment (enterprise)"
set -g YAMLFILE generated/activefailover-enterprise-dev.yaml
set -g DEPLOYMENT acceptance-activefailover
printheader

# Deploy and check
kubectl apply -f $YAMLFILE
and waitForKubectl "get pod" $DEPLOYMENT "1 *Running" 5 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*1/1 *Running" "" 1 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*0/1 *Running" "" 1 120
and waitForKubectl "get service" "$DEPLOYMENT *ClusterIP" 8529 1 120
and waitForKubectl "get service" "$DEPLOYMENT-ea *LoadBalancer" "-v;pending" 1 180
or fail "Deployment did not get ready."

# Automatic check
set ip (getLoadBalancerIP "$DEPLOYMENT-ea")
testArangoDB $ip 120
or fail "ArangoDB was not reachable."

# Scale up the deployment
output "Next" "Patching Spec for Scaling up"
kubectl patch arango $DEPLOYMENT --type='json' -p='[{"op": "replace", "path": "/spec/single/count", "value":3}]'
and waitForKubectl "get pod" $DEPLOYMENT "1 *Running" 6 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*1/1 *Running" "" 1 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*0/1 *Running" "" 2 120
or fail "Patched deployment did not get ready."

# Scale down the deployment
output "Next" "Patching Spec for Scaling down"
kubectl patch arango $DEPLOYMENT --type='json' -p='[{"op": "replace", "path": "/spec/single/count", "value":2}]'
and waitForKubectl "get pod" $DEPLOYMENT "1 *Running" 5 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*1/1 *Running" "" 1 120
and waitForKubectl "get pod" "$DEPLOYMENT-sngl.*0/1 *Running" "" 1 120
or fail "Patched deployment did not get ready."

# Manual check
output "Work" "Now please check external access on this URL with your browser:" " https://$ip:8529/" "then type the outcome followed by ENTER."
inputAndLogResult

# Cleanup
kubectl delete -f $YAMLFILE
waitForKubectl "get pod" $DEPLOYMENT-sngl "" 0 120
or fail "Could not delete deployment."

output "Ready" ""
Loading