-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathrun
More file actions
executable file
·137 lines (100 loc) · 3.58 KB
/
Copy pathrun
File metadata and controls
executable file
·137 lines (100 loc) · 3.58 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
#!/bin/bash
set -o errexit
test_dir=$(realpath "$(dirname "$0")")
. "${test_dir}/../functions"
set_debug
check_balancer() {
local cluster=$1
local expected=$2 # should be "true" (enabled) or "false" (disabled)
local delay=${3:-"0"}
local balancer_running
log "sleeping for ${delay} seconds..."
sleep ${delay}
balancer_running=$(run_mongosh 'sh.getBalancerState()' "clusterAdmin:clusterAdmin123456@${cluster}-cfg.${namespace}" \
| grep -E -v 'Warning|cfg' | grep -E 'true|false')
echo -n "checking if balancer status is ${expected}..."
if [[ $balancer_running != "$expected" ]]; then
echo
log "Unexpected output from \"sh.getBalancerState()\": $balancer_running"
log "Expected: $expected"
exit 1
fi
echo "OK"
}
check_backup_and_restore() {
local cluster=$1
local backup_suffix=$2
local balancer_end_state=$3
local backup_name="backup-minio-${backup_suffix}"
log "running backup: ${backup_name}"
run_backup "minio" "${backup_name}"
wait_backup "${backup_name}" "requested"
log "checking if balancer is disabled"
check_balancer ${cluster} "false"
wait_backup "${backup_name}" "ready"
log "checking if balancer is ${balancer_end_state} after backup"
check_balancer ${cluster} ${balancer_end_state} 10
log "running restore: restore-${backup_name}"
run_restore "${backup_name}"
wait_restore ${backup_name} ${cluster} "requested" 0
log "checking if balancer is disabled"
check_balancer ${cluster} "false" 5
wait_restore ${backup_name} ${cluster} "ready" 1
log "checking if balancer is ${balancer_end_state} after restore"
check_balancer ${cluster} ${balancer_end_state} 10
}
write_data() {
local cluster=$1
log 'create user'
run_mongosh_mongos \
'db.createUser({user:"user",pwd:"pass",roles:[{db:"app",role:"readWrite"}]})' \
"userAdmin:userAdmin123456@$cluster-mongos.$namespace" \
"mongodb" ".svc.cluster.local" "--quiet" "27017" "mongosh"
sleep 2
log 'enable sharding'
run_mongosh_mongos \
'sh.enableSharding("app")' \
"clusterAdmin:clusterAdmin123456@$cluster-mongos.$namespace" \
"mongodb" ".svc.cluster.local" "--quiet" "27017" "mongosh"
sleep 2
log 'shard collection'
run_mongosh_mongos \
'sh.shardCollection("app.city", { _id: 1 } )' \
"clusterAdmin:clusterAdmin123456@$cluster-mongos.$namespace" \
"mongodb" ".svc.cluster.local" "--quiet" "27017" "mongosh"
log 'write data (this can take some time, be patient)'
run_script_mongosh_mongos "${test_dir}/data.js" "user:pass@$cluster-mongos.$namespace" \
"mongodb" ".svc.cluster.local" "--quiet" "mongosh"
}
main() {
create_infra "$namespace"
deploy_minio
apply_s3_storage_secrets
log 'create PSMDB cluster'
cluster="some-name"
kubectl_bin apply \
-f "$conf_dir/secrets.yml" \
-f "$conf_dir/client-70.yml"
apply_cluster "$test_dir/conf/$cluster-rs0.yml"
log 'check if cfg pods started'
wait_for_running $cluster-cfg 3 "false"
log 'check if all shards started'
wait_for_running $cluster-rs0 3 "false"
wait_for_running $cluster-rs1 3 "false"
wait_for_running $cluster-rs2 3 "false"
log 'check if mongos pods started'
wait_for_running $cluster-mongos 3
check_balancer ${cluster} "true" 10
write_data ${cluster}
check_backup_and_restore ${cluster} "0" "true"
log 'disabling balancer'
kubectl patch psmdb some-name --type=merge -p '{"spec":{"sharding":{"balancer":{"enabled":false}}}}'
check_balancer ${cluster} "false" 10
check_backup_and_restore ${cluster} "1" "false"
log 'enabling balancer'
kubectl patch psmdb some-name --type=merge -p '{"spec":{"sharding":{"balancer":{"enabled":true}}}}'
check_balancer ${cluster} "true" 10
destroy "$namespace"
desc 'test passed'
}
main