11#! /bin/bash
22
33set -o errexit
4- set -o xtrace
54
65test_dir=$( realpath " $( dirname " $0 " ) " )
76. " ${test_dir} /../functions"
87set_debug
98
109check_balancer () {
11- local expected=$1 # should be "full" (running balancer) or "off" (disabled balancer)
12-
10+ local cluster=$1
11+ local expected=$2 # should be "full" (running balancer) or "off" (disabled balancer)
12+ local delay=${3:- " 0" }
1313 local balancer_running
14+
15+ echo " sleeping for ${delay} seconds..."
16+ sleep ${delay}
17+
1418 balancer_running=$( run_mongos ' db.adminCommand({balancerStatus: 1}).mode' " clusterAdmin:clusterAdmin123456@$cluster -mongos.$namespace " \
1519 | grep -E -v " Percona Server for MongoDB|connecting to:|Implicit session:|versions do not match|Error saving history file:|bye" )
1620
21+ echo -n " checking if balancer status is ${expected} ..."
1722 if [[ $balancer_running != " $expected " ]]; then
23+ echo
1824 echo " Unexpected output from \" db.adminCommand({balancerStatus: 1}).mode\" : $balancer_running "
1925 echo " Expected $expected "
2026 exit 1
2127 fi
28+ echo " OK"
2229}
2330
24- check_service () {
25- state=$1
26- svc_name=$2
27- if [ $state = " present" ]; then
28- echo -n " check that $svc_name was created"
29- local timeout=0
30- until kubectl_bin get service/$svc_name -o ' jsonpath={.spec.type}' 2>&1 | grep -vq NotFound; do
31- sleep 1
32- timeout=$(( timeout + 1 ))
33- echo -n ' .'
34- if [[ ${timeout} -gt 900 ]]; then
35- echo " Waiting timeout has been reached. Service $svc_name is not present. Exiting..."
36- exit 1
37- fi
38- done
39- echo " .OK"
40- elif [ $state = " removed" ]; then
41- echo -n " check that $svc_name was removed"
42- if [[ -z $( kubectl_bin get service/$svc_name -o ' jsonpath={.spec.type}' 2>&1 | grep NotFound) ]]; then
43- echo " $svc_name was not removed."
44- exit 1
45- else
46- echo " .OK"
47- fi
48- else
49- echo " unknown state $state "
50- fi
31+ check_backup_and_restore () {
32+ local cluster=$1
33+ local backup_suffix=$2
34+ local balancer_end_state=$3
35+ local backup_name=" backup-minio-${backup_suffix} "
36+
37+ echo " running backup: ${backup_name} "
38+ run_backup " minio" " ${backup_name} "
39+ wait_backup " ${backup_name} " " requested"
40+
41+ echo " checking if balancer is disabled"
42+ check_balancer ${cluster} " off"
43+
44+ wait_backup " ${backup_name} " " ready"
45+
46+ echo " checking if balancer is ${balancer_end_state} after backup"
47+ check_balancer ${cluster} ${balancer_end_state} 10
48+
49+ echo " running restore: restore-${backup_name} "
50+ run_restore " ${backup_name} "
51+ wait_restore ${backup_name} ${cluster} " requested"
52+
53+ echo " checking if balancer is disabled"
54+ check_balancer ${cluster} " off"
55+
56+ wait_restore ${backup_name} ${cluster} " ready"
57+
58+ echo " checking if balancer is ${balancer_end_state} after restore"
59+ check_balancer ${cluster} ${balancer_end_state} 10
5160}
5261
5362main () {
5463 create_infra " $namespace "
5564
65+ deploy_minio
66+ apply_s3_storage_secrets
67+
5668 desc ' create first PSMDB cluster'
5769 cluster=" some-name"
5870 kubectl_bin apply \
@@ -73,27 +85,19 @@ main() {
7385 wait_for_running $cluster -rs0 3
7486 wait_for_running $cluster -cfg 3 " false"
7587 wait_for_running $cluster -mongos 3
76- sleep 20
77- check_balancer " full"
88+ check_balancer ${cluster} " full" 10
89+
90+ check_backup_and_restore ${cluster} " 0" " full"
7891
7992 desc ' disabling balancer'
8093 kubectl patch psmdb some-name --type=merge -p ' {"spec":{"sharding":{"balancer":{"enabled":false}}}}'
81- sleep 20
82- check_balancer " off"
94+ check_balancer ${cluster} " off" 10
95+
96+ check_backup_and_restore ${cluster} " 1" " off"
8397
8498 desc ' enabling balancer'
8599 kubectl patch psmdb some-name --type=merge -p ' {"spec":{"sharding":{"balancer":{"enabled":true}}}}'
86- sleep 20
87- check_balancer " full"
88-
89- # Add check that servicePerPod creates 3 services for the running cluster
90- desc ' enabling servicePerPod for mongos'
91- kubectl patch psmdb some-name --type=merge -p ' {"spec":{"sharding":{"mongos":{"expose":{"servicePerPod":true}}}}}'
92- wait_for_running $cluster -mongos 3
93- check_service present $cluster -mongos-0
94- check_service present $cluster -mongos-1
95- check_service present $cluster -mongos-2
96- check_service removed $cluster -mongos
100+ check_balancer ${cluster} " full" 10
97101
98102 destroy " $namespace "
99103}
0 commit comments