-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·100 lines (77 loc) · 3.81 KB
/
test.sh
File metadata and controls
executable file
·100 lines (77 loc) · 3.81 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
#!/usr/bin/env bash
set -eof pipefail
puts-step() {
echo "-----> $@"
}
puts-error() {
echo "!!! $@"
}
kill-containers() {
puts-step "destroying containers"
docker rm -f "$MINIO_JOB" "$PG_JOB"
}
# make sure we are in this dir
CURRENT_DIR=$(cd $(dirname $0); pwd)
puts-step "creating fake postgres credentials"
# create fake postgres credentials
mkdir -p $CURRENT_DIR/tmp/creds
echo "testuser" > $CURRENT_DIR/tmp/creds/user
echo "icanttellyou" > $CURRENT_DIR/tmp/creds/password
puts-step "creating fake minio credentials"
# create fake AWS credentials for minio admin credentials
mkdir -p $CURRENT_DIR/tmp/aws-admin
# needs to be 20 characters long
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-key-id
# needs to be 40 characters long
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-secret-key
# create fake AWS credentials for minio user credentials
mkdir -p $CURRENT_DIR/tmp/aws-user
# needs to be 20 characters long
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/accesskey
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-key-id
# needs to be 40 characters long
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/secretkey
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-secret-key
puts-step "creating fake kubernetes service account token"
# create fake k8s serviceaccount token for minio to "discover" itself
mkdir -p $CURRENT_DIR/tmp/k8s
echo "token" > $CURRENT_DIR/tmp/k8s/token
echo "cert" > $CURRENT_DIR/tmp/k8s/ca.crt
# boot minio
MINIO_JOB=$(docker run -dv $CURRENT_DIR/tmp/aws-admin:/var/run/secrets/deis/minio/admin -v $CURRENT_DIR/tmp/aws-user:/var/run/secrets/deis/minio/user -v $CURRENT_DIR/tmp/k8s:/var/run/secrets/kubernetes.io/serviceaccount quay.io/deisci/minio:canary boot server /home/minio/)
# boot postgres, linking the minio container and setting DEIS_MINIO_SERVICE_HOST and DEIS_MINIO_SERVICE_PORT
PG_JOB=$(docker run -d --link $MINIO_JOB:minio -e BACKUP_FREQUENCY=1s -e DATABASE_STORAGE=minio -e DEIS_MINIO_SERVICE_HOST=minio -e DEIS_MINIO_SERVICE_PORT=9000 -v $CURRENT_DIR/tmp/creds:/var/run/secrets/deis/database/creds -v $CURRENT_DIR/tmp/aws-user:/var/run/secrets/deis/objectstore/creds $1)
# kill containers when this script exits or errors out
trap kill-containers INT TERM
# wait for postgres to boot
puts-step "sleeping for 90s while postgres is booting..."
sleep 90s
# display logs for debugging purposes
puts-step "displaying minio logs"
docker logs $MINIO_JOB
puts-step "displaying postgres logs"
docker logs $PG_JOB
# check if postgres is running
puts-step "checking if postgres is running"
docker exec $PG_JOB is_running
# check if minio has the 5 backups
puts-step "checking if minio has 5 backups"
BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep json)"
NUM_BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep -c json)"
if [[ ! "$NUM_BACKUPS" -eq "5" ]]; then
puts-error "did not find 5 base backups, which is the default (found $NUM_BACKUPS)"
puts-error "$BACKUPS"
exit 1
fi
# kill off postgres, then reboot and see if it's running after recovering from backups
puts-step "shutting off postgres, then rebooting to test data recovery"
docker rm -f $PG_JOB
PG_JOB=$(docker run -d --link $MINIO_JOB:minio -e BACKUP_FREQUENCY=1s -e DATABASE_STORAGE=minio -e DEIS_MINIO_SERVICE_HOST=minio -e DEIS_MINIO_SERVICE_PORT=9000 -v $CURRENT_DIR/tmp/creds:/var/run/secrets/deis/database/creds -v $CURRENT_DIR/tmp/aws-user:/var/run/secrets/deis/objectstore/creds $1)
# wait for postgres to boot
puts-step "sleeping for 90s while postgres is recovering from backup..."
sleep 90s
puts-step "displaying postgres logs"
docker logs $PG_JOB
# check if postgres is running
puts-step "checking if postgres is running"
docker exec $PG_JOB is_running