Skip to content

Commit bad5362

Browse files
author
Keerthan Reddy Mala
committed
refactor the functional test
1 parent e8a5907 commit bad5362

5 files changed

Lines changed: 139 additions & 160 deletions

File tree

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ branches:
55
sudo: required
66
services:
77
- docker
8+
before_install:
9+
- sudo apt-get -qq update
10+
- sudo apt-get install -y python-swiftclient
811
env:
912
# HACK(bacongobbler): make travis tests work
1013
- DEIS_REGISTRY=travis-ci/

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ test-style:
3333
test-unit:
3434
@echo "Implement functional tests in _tests directory"
3535

36-
test-functional:
37-
contrib/ci/test.sh ${IMAGE}
36+
test-functional: test-functional-swift test-functional-minio
37+
38+
test-functional-minio:
39+
contrib/ci/test-minio.sh ${IMAGE}
3840

3941
test-functional-swift:
4042
contrib/ci/test-swift.sh ${IMAGE}

contrib/ci/test-minio.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
set -eof pipefail
4+
5+
TEST_ROOT=$(dirname "${BASH_SOURCE}")/
6+
source "${TEST_ROOT}/test.sh"
7+
8+
# make sure we are in this dir
9+
CURRENT_DIR=$(cd $(dirname $0); pwd)
10+
11+
create-postgres-creds
12+
13+
puts-step "creating fake minio credentials"
14+
15+
# create fake AWS credentials for minio admin credentials
16+
mkdir -p $CURRENT_DIR/tmp/aws-admin
17+
# needs to be 20 characters long
18+
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-key-id
19+
# needs to be 40 characters long
20+
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-secret-key
21+
22+
# create fake AWS credentials for minio user credentials
23+
mkdir -p $CURRENT_DIR/tmp/aws-user
24+
# needs to be 20 characters long
25+
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/accesskey
26+
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-key-id
27+
# needs to be 40 characters long
28+
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/secretkey
29+
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-secret-key
30+
31+
puts-step "creating fake kubernetes service account token"
32+
33+
# create fake k8s serviceaccount token for minio to "discover" itself
34+
mkdir -p $CURRENT_DIR/tmp/k8s
35+
echo "token" > $CURRENT_DIR/tmp/k8s/token
36+
echo "cert" > $CURRENT_DIR/tmp/k8s/ca.crt
37+
38+
# kill containers when this script exits or errors out
39+
trap 'kill-container $MINIO_JOB' INT TERM
40+
# boot minio
41+
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/)
42+
43+
# boot postgres, linking the minio container and setting DEIS_MINIO_SERVICE_HOST and DEIS_MINIO_SERVICE_PORT
44+
PG_CMD="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"
45+
46+
# kill containers when this script exits or errors out
47+
trap 'kill-container $PG_JOB' INT TERM
48+
start-postgres "$PG_CMD"
49+
50+
# display logs for debugging purposes
51+
puts-step "displaying minio logs"
52+
docker logs $MINIO_JOB
53+
54+
check-postgres $PG_JOB
55+
56+
# check if minio has the 5 backups
57+
puts-step "checking if minio has 5 backups"
58+
BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep json)"
59+
NUM_BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/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)"
64+
puts-error "$BACKUPS"
65+
exit 1
66+
fi
67+
68+
# kill off postgres, then reboot and see if it's running after recovering from backups
69+
puts-step "shutting off postgres, then rebooting to test data recovery"
70+
kill-container $PG_JOB
71+
72+
start-postgres "$PG_CMD"
73+
74+
check-postgres $PG_JOB

contrib/ci/test-swift.sh

Lines changed: 34 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,116 +2,76 @@
22

33
set -eof pipefail
44

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"
327

338
# make sure we are in this dir
349
CURRENT_DIR=$(cd $(dirname $0); pwd)
3510

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
4212

4313
puts-step "fetching openstack credentials"
4414

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-
5115
# turn creds into something that we can use.
5216
mkdir -p $CURRENT_DIR/tmp/swift
5317

5418
# guess which value to use for tenant:
55-
TENANT=${OS_TENANT_NAME:-$OS_PROJECT_NAME}
56-
TENANT=${TENANT:-$OS_USERNAME}
19+
TENANT=""
5720

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
6023
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
6226
echo "deis-swift-test" > $CURRENT_DIR/tmp/swift/database-container
6327

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+
6438
# 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 \
6640
-e DATABASE_STORAGE=swift \
6741
-v $CURRENT_DIR/tmp/creds:/var/run/secrets/deis/database/creds \
6842
-v $CURRENT_DIR/tmp/swift:/var/run/secrets/deis/objectstore/creds \
6943
$1"
7044

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"
7748

7849
# 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
8152

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
8554

8655
# check if swift has some backups ... 3 ?
8756
puts-step "checking if swift has at least 3 backups"
8857

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)"
9364
puts-error "$BACKUPS"
94-
exit-script
9565
exit 1
9666
fi
9767

98-
puts-step "found $NUM_BACKUPS"
99-
10068
# kill off postgres, then reboot and see if it's running after recovering from backups
10169
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
10871

109-
puts-step "displaying postgres logs"
110-
docker logs $PG_JOB
72+
start-postgres "$PG_CMD"
11173

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
11575

11676
puts-step "tests PASSED!"
11777
exit 0

contrib/ci/test.sh

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -10,93 +10,33 @@ puts-error() {
1010
echo "!!! $@"
1111
}
1212

13-
kill-containers() {
14-
puts-step "destroying containers"
15-
docker rm -f "$MINIO_JOB" "$PG_JOB"
13+
kill-container() {
14+
puts-step "destroying container $1"
15+
docker rm -f "$1"
1616
}
1717

18-
# make sure we are in this dir
19-
CURRENT_DIR=$(cd $(dirname $0); pwd)
18+
create-postgres-creds() {
19+
puts-step "creating fake postgres credentials"
2020

21-
puts-step "creating fake postgres credentials"
22-
23-
# create fake postgres credentials
24-
mkdir -p $CURRENT_DIR/tmp/creds
25-
echo "testuser" > $CURRENT_DIR/tmp/creds/user
26-
echo "icanttellyou" > $CURRENT_DIR/tmp/creds/password
27-
28-
puts-step "creating fake minio credentials"
29-
30-
# create fake AWS credentials for minio admin credentials
31-
mkdir -p $CURRENT_DIR/tmp/aws-admin
32-
# needs to be 20 characters long
33-
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-key-id
34-
# needs to be 40 characters long
35-
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-secret-key
36-
37-
# create fake AWS credentials for minio user credentials
38-
mkdir -p $CURRENT_DIR/tmp/aws-user
39-
# needs to be 20 characters long
40-
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/accesskey
41-
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-key-id
42-
# needs to be 40 characters long
43-
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/secretkey
44-
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-secret-key
45-
46-
puts-step "creating fake kubernetes service account token"
47-
48-
# create fake k8s serviceaccount token for minio to "discover" itself
49-
mkdir -p $CURRENT_DIR/tmp/k8s
50-
echo "token" > $CURRENT_DIR/tmp/k8s/token
51-
echo "cert" > $CURRENT_DIR/tmp/k8s/ca.crt
52-
53-
# boot minio
54-
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/)
55-
56-
# boot postgres, linking the minio container and setting DEIS_MINIO_SERVICE_HOST and DEIS_MINIO_SERVICE_PORT
57-
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)
58-
59-
# kill containers when this script exits or errors out
60-
trap kill-containers INT TERM
61-
62-
# wait for postgres to boot
63-
puts-step "sleeping for 90s while postgres is booting..."
64-
sleep 90s
65-
66-
# display logs for debugging purposes
67-
puts-step "displaying minio logs"
68-
docker logs $MINIO_JOB
69-
puts-step "displaying postgres logs"
70-
docker logs $PG_JOB
71-
72-
# check if postgres is running
73-
puts-step "checking if postgres is running"
74-
docker exec $PG_JOB is_running
75-
76-
# check if minio has the 5 backups
77-
puts-step "checking if minio has 5 backups"
78-
BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep json)"
79-
NUM_BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep -c json)"
80-
# NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking
81-
# in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case
82-
if [[ ! "$NUM_BACKUPS" -eq "5" && ! "$NUM_BACKUPS" -eq "6" ]]; then
83-
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)"
84-
puts-error "$BACKUPS"
85-
exit 1
86-
fi
87-
88-
# kill off postgres, then reboot and see if it's running after recovering from backups
89-
puts-step "shutting off postgres, then rebooting to test data recovery"
90-
docker rm -f $PG_JOB
91-
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)
21+
# create fake postgres credentials
22+
mkdir -p $CURRENT_DIR/tmp/creds
23+
echo "testuser" > $CURRENT_DIR/tmp/creds/user
24+
echo "icanttellyou" > $CURRENT_DIR/tmp/creds/password
25+
}
9226

93-
# wait for postgres to boot
94-
puts-step "sleeping for 90s while postgres is recovering from backup..."
95-
sleep 90s
27+
start-postgres() {
28+
PG_JOB=$($1)
29+
# wait for postgres to boot
30+
puts-step "sleeping for 90s while postgres is booting..."
31+
sleep 90s
32+
}
9633

97-
puts-step "displaying postgres logs"
98-
docker logs $PG_JOB
34+
check-postgres() {
35+
# display logs for debugging purposes
36+
puts-step "displaying postgres logs"
37+
docker logs $1
9938

100-
# check if postgres is running
101-
puts-step "checking if postgres is running"
102-
docker exec $PG_JOB is_running
39+
# check if postgres is running
40+
puts-step "checking if postgres is running"
41+
docker exec $1 is_running
42+
}

0 commit comments

Comments
 (0)