|
2 | 2 |
|
3 | 3 | set -eof pipefail |
4 | 4 |
|
5 | | -# kill containers when this script exits or errors out |
6 | | -trap exit-script INT TERM |
7 | | - |
8 | | -puts-step() { |
9 | | - echo "-----> $@" |
10 | | -} |
11 | | - |
12 | | -puts-error() { |
13 | | - echo "!!! $@" |
14 | | -} |
15 | | - |
16 | | -exit-script() { |
17 | | - kill-containers |
18 | | - kill-swift |
19 | | -} |
20 | | - |
21 | | -kill-containers() { |
22 | | - # docker containers |
23 | | - puts-step "destroying postgres container" |
24 | | - docker rm -f deis-postgres-swift |
25 | | -} |
26 | | - |
27 | | -kill-swift() { |
28 | | - # swift containers |
29 | | - puts-step "cleaning swift" |
30 | | - swift delete deis-swift-test > /dev/null |
31 | | -} |
| 5 | +TEST_ROOT=$(dirname "${BASH_SOURCE}")/ |
| 6 | +source "${TEST_ROOT}/test.sh" |
32 | 7 |
|
33 | 8 | # make sure we are in this dir |
34 | 9 | CURRENT_DIR=$(cd $(dirname $0); pwd) |
35 | 10 |
|
36 | | -puts-step "creating fake postgres credentials" |
37 | | - |
38 | | -# create fake postgres credentials |
39 | | -mkdir -p $CURRENT_DIR/tmp/creds |
40 | | -echo "testuser" > $CURRENT_DIR/tmp/creds/user |
41 | | -echo "icanttellyou" > $CURRENT_DIR/tmp/creds/password |
| 11 | +create-postgres-creds |
42 | 12 |
|
43 | 13 | puts-step "fetching openstack credentials" |
44 | 14 |
|
45 | | -# check if openstack creds are not already in environment |
46 | | -if [[ -z $OS_USERNAME ]]; then |
47 | | - echo "it appears that you have not loaded your openstack credentials into your environment" |
48 | | - exit 1 |
49 | | -fi |
50 | | - |
51 | 15 | # turn creds into something that we can use. |
52 | 16 | mkdir -p $CURRENT_DIR/tmp/swift |
53 | 17 |
|
54 | 18 | # guess which value to use for tenant: |
55 | | -TENANT=${OS_TENANT_NAME:-$OS_PROJECT_NAME} |
56 | | -TENANT=${TENANT:-$OS_USERNAME} |
| 19 | +TENANT="" |
57 | 20 |
|
58 | | -echo ${OS_USERNAME} > $CURRENT_DIR/tmp/swift/username |
59 | | -echo ${OS_PASSWORD} > $CURRENT_DIR/tmp/swift/password |
| 21 | +echo "test:tester" > $CURRENT_DIR/tmp/swift/username |
| 22 | +echo "testing" > $CURRENT_DIR/tmp/swift/password |
60 | 23 | echo ${TENANT} > $CURRENT_DIR/tmp/swift/tenant |
61 | | -echo ${OS_AUTH_URL} > $CURRENT_DIR/tmp/swift/authurl |
| 24 | +echo "http://swift:8080/auth/v1.0" > $CURRENT_DIR/tmp/swift/authurl |
| 25 | +echo "1" > $CURRENT_DIR/tmp/swift/authversion |
62 | 26 | echo "deis-swift-test" > $CURRENT_DIR/tmp/swift/database-container |
63 | 27 |
|
| 28 | +# kill containers when this script exits or errors out |
| 29 | +trap 'kill-container $SWIFT_DATA' INT TERM |
| 30 | +# boot swift |
| 31 | +SWIFT_DATA=$(docker run -v /srv --name SWIFT_DATA busybox) |
| 32 | + |
| 33 | +# kill containers when this script exits or errors out |
| 34 | +trap 'kill-container $SWIFT_JOB' INT TERM |
| 35 | +SWIFT_JOB=$(docker run --name onlyone --hostname onlyone -d -p 12345:8080 --volumes-from SWIFT_DATA -t deis/swift-onlyone:git-8516d23) |
| 36 | + |
| 37 | + |
64 | 38 | # postgres container command |
65 | | -PG_CMD="docker run -d -e BACKUP_FREQUENCY=3s \ |
| 39 | +PG_CMD="docker run -d --link $SWIFT_JOB:swift -e BACKUP_FREQUENCY=3s \ |
66 | 40 | -e DATABASE_STORAGE=swift \ |
67 | 41 | -v $CURRENT_DIR/tmp/creds:/var/run/secrets/deis/database/creds \ |
68 | 42 | -v $CURRENT_DIR/tmp/swift:/var/run/secrets/deis/objectstore/creds \ |
69 | 43 | $1" |
70 | 44 |
|
71 | | -# boot postgres |
72 | | -PG_JOB=$(${PG_CMD}) |
73 | | - |
74 | | -# wait for postgres to boot |
75 | | -puts-step "sleeping for 90s while postgres is booting..." |
76 | | -sleep 90s |
| 45 | +# kill containers when this script exits or errors out |
| 46 | +trap 'kill-container $PG_JOB' INT TERM |
| 47 | +start-postgres "$PG_CMD" |
77 | 48 |
|
78 | 49 | # display logs for debugging purposes |
79 | | -puts-step "displaying postgres logs" |
80 | | -docker logs $PG_JOB |
| 50 | +puts-step "displaying swift logs" |
| 51 | +docker logs $SWIFT_JOB |
81 | 52 |
|
82 | | -# check if postgres is running |
83 | | -puts-step "checking if postgres is running" |
84 | | -docker exec $PG_JOB is_running |
| 53 | +check-postgres $PG_JOB |
85 | 54 |
|
86 | 55 | # check if swift has some backups ... 3 ? |
87 | 56 | puts-step "checking if swift has at least 3 backups" |
88 | 57 |
|
89 | | -BACKUPS="$(swift list deis-swift-test | grep basebackups_005 | grep json)" |
90 | | -NUM_BACKUPS="$(swift list deis-swift-test | grep basebackups_005 | grep -c json)" |
91 | | -if [[ ! "$NUM_BACKUPS" -gt "3" ]]; then |
92 | | - puts-error "did not find at least 3 base backups, which is the default (found $NUM_BACKUPS)" |
| 58 | +BACKUPS="$(swift -A http://127.0.0.1:12345/auth/v1.0 -U test:tester -K testing list deis-swift-test | grep basebackups_005 | grep json)" |
| 59 | +NUM_BACKUPS="$(swift -A http://127.0.0.1:12345/auth/v1.0 -U test:tester -K testing list deis-swift-test | grep basebackups_005 | grep -c json)" |
| 60 | +# NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking |
| 61 | +# in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case |
| 62 | +if [[ ! "$NUM_BACKUPS" -eq "5" && ! "$NUM_BACKUPS" -eq "6" ]]; then |
| 63 | + puts-error "did not find 5 or 6 base backups. 5 is the default, but 6 may exist if a backup is currently in progress (found $NUM_BACKUPS)" |
93 | 64 | puts-error "$BACKUPS" |
94 | | - exit-script |
95 | 65 | exit 1 |
96 | 66 | fi |
97 | 67 |
|
98 | | -puts-step "found $NUM_BACKUPS" |
99 | | - |
100 | 68 | # kill off postgres, then reboot and see if it's running after recovering from backups |
101 | 69 | puts-step "shutting off postgres, then rebooting to test data recovery" |
102 | | -docker rm -f $PG_JOB |
103 | | -PG_JOB=$(${PG_CMD}) |
104 | | - |
105 | | -# wait for postgres to boot |
106 | | -puts-step "sleeping for 90s while postgres is recovering from backup..." |
107 | | -sleep 90s |
| 70 | +kill-container $PG_JOB |
108 | 71 |
|
109 | | -puts-step "displaying postgres logs" |
110 | | -docker logs $PG_JOB |
| 72 | +start-postgres "$PG_CMD" |
111 | 73 |
|
112 | | -# check if postgres is running |
113 | | -puts-step "checking if postgres is running" |
114 | | -docker exec $PG_JOB is_running |
| 74 | +check-postgres $PG_JOB |
115 | 75 |
|
116 | 76 | puts-step "tests PASSED!" |
117 | 77 | exit 0 |
0 commit comments