-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathrun
More file actions
executable file
·143 lines (116 loc) · 5.52 KB
/
run
File metadata and controls
executable file
·143 lines (116 loc) · 5.52 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
set -o errexit
test_dir=$(realpath $(dirname $0))
. ${test_dir}/../functions
set_debug
max_conn=17
create_infra $namespace
desc 'create secrets and start client'
kubectl_bin apply \
-f "$test_dir/conf/secrets_with_tls.yml" \
-f "$conf_dir/client.yml"
desc 'create custom RuntimeClass'
if version_gt "1.19" && [ $EKS -ne 1 ]; then
cat "$conf_dir/container-rc.yaml" | $sed 's/docker/runc/g' | kubectl_bin apply -f -
elif version_gt "1.24" && [ $EKS -eq 1 ]; then
cat "$conf_dir/container-rc.yaml" | $sed 's/docker/runc/g' | kubectl_bin apply -f -
else
kubectl_bin apply -f "$conf_dir/container-rc.yaml"
fi
cluster="some-name-rs0"
desc "create first PSMDB cluster $cluster"
apply_cluster $conf_dir/$cluster.yml
desc 'check if all 3 Pods started'
wait_for_running $cluster 3
desc 'check if service and statefulset created with expected config'
compare_kubectl statefulset/$cluster
compare_kubectl service/$cluster
desc 'check if users created'
secret_name="some-users"
user=$(getUserData "$secret_name" "MONGODB_USER_ADMIN_USER")
pass=$(getUserData "$secret_name" "MONGODB_USER_ADMIN_PASSWORD")
compare_mongo_user "$user:$pass@$cluster.$namespace" "userAdmin"
user=$(getUserData "$secret_name" "MONGODB_BACKUP_USER")
pass=$(getUserData "$secret_name" "MONGODB_BACKUP_PASSWORD")
compare_mongo_user "$user:$pass@$cluster.$namespace" "backup"
user=$(getUserData "$secret_name" "MONGODB_CLUSTER_ADMIN_USER")
pass=$(getUserData "$secret_name" "MONGODB_CLUSTER_ADMIN_PASSWORD")
compare_mongo_user "$user:$pass@$cluster.$namespace" "clusterAdmin"
user=$(getUserData "$secret_name" "MONGODB_CLUSTER_MONITOR_USER")
pass=$(getUserData "$secret_name" "MONGODB_CLUSTER_MONITOR_PASSWORD")
compare_mongo_user "$user:$pass@$cluster.$namespace" "clusterMonitor"
# check that test user don't have access
(run_mongo 'db.runCommand({connectionStatus:1,showPrivileges:true})' "test:test@$cluster.$namespace" || :) 2>&1 \
| grep 'Authentication failed'
desc 'create user'
run_mongo \
'db.createUser({user:"myApp",pwd:"myPass",roles:[{db:"myApp",role:"readWrite"}]})' \
"userAdmin:userAdmin123456@$cluster.$namespace"
sleep 2
desc 'write data, read from all'
run_mongo \
'use myApp\n db.test.insert({ x: 100500 })' \
"myApp:myPass@$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-2.$cluster.$namespace"
desc 'check number of connections'
conn_count=$(run_mongo 'db.serverStatus().connections.current' "clusterAdmin:clusterAdmin123456@$cluster.$namespace" | grep -E -v 'I NETWORK|W NETWORK|Error saving history file|Percona Server for MongoDB|connecting to:|Unable to reach primary for set|Implicit session:|versions do not match|bye')
if [ ${conn_count} -gt ${max_conn} ]; then
echo "error: connection count (${conn_count}) exceeds maximum allowed (${max_conn})"
exit 1
fi
desc 'kill Primary Pod, check reelection, check data'
initial_primary=$(get_mongo_primary "clusterAdmin:clusterAdmin123456@$cluster.$namespace" "$cluster")
kubectl_bin delete pods --grace-period=0 --force $initial_primary
wait_for_running $cluster 3
changed_primary=$(get_mongo_primary "clusterAdmin:clusterAdmin123456@$cluster.$namespace" "$cluster")
[ "$initial_primary" != "$changed_primary" ]
run_mongo \
'use myApp\n db.test.insert({ x: 100501 })' \
"myApp:myPass@$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"
compare_mongo_cmd "find" "myApp:myPass@$cluster-2.$cluster.$namespace" "-2nd"
desc 'check if possible to create second cluster'
cluster2="another-name-rs0"
apply_s3_storage_secrets
apply_cluster $test_dir/conf/$cluster2.yml
desc 'check if all 3 Pods started'
wait_for_running $cluster2 3
desc 'check if service and statefulset created with expected config'
compare_kubectl statefulset/$cluster2
compare_kubectl service/$cluster2
desc 'write data, read from all'
run_mongo \
'db.createUser({user:"myApp",pwd:"myPass",roles:[{db:"myApp",role:"readWrite"}]})' \
"userAdmin:userAdmin123456@$cluster2.$namespace"
run_mongo \
'use myApp\n db.test.insert({ x: 100502 })' \
"myApp:myPass@$cluster2.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster2-0.$cluster2.$namespace" "-3rd"
compare_mongo_cmd "find" "myApp:myPass@$cluster2-1.$cluster2.$namespace" "-3rd"
compare_mongo_cmd "find" "myApp:myPass@$cluster2-2.$cluster2.$namespace" "-3rd"
desc 'check number of connections with backup'
max_conn=50
sleep 300
conn_count=$(run_mongo 'db.serverStatus().connections.current' "clusterAdmin:clusterAdmin123456@$cluster2.$namespace" | egrep -v 'I NETWORK|W NETWORK|Error saving history file|Percona Server for MongoDB|connecting to:|Unable to reach primary for set|Implicit session:|versions do not match|bye')
if [ ${conn_count} -gt ${max_conn} ]; then
echo "error: connection count (${conn_count}) exceeds maximum allowed (${max_conn}) with backup enabled"
exit 1
fi
desc 'check if mongod log files exist in pod'
log_files=$(kubectl exec "${cluster2}-0" -c "mongod" -- ls "/data/db/logs" 2>/dev/null)
if ! echo "$log_files" | grep -q 'mongod.log' || ! echo "$log_files" | grep -q 'mongod.full.log'; then
echo "error, files found:"
echo "$log_files"
return 1
fi
echo "found mongod.log and mongod.full.log in /data/db/logs"
# Temporarily skipping this check
# desc 'check for passwords leak'
# check_passwords_leak
desc 'delete custom RuntimeClass'
kubectl_bin delete -f "$conf_dir/container-rc.yaml"
destroy $namespace
desc 'test passed'