|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +#set -eof pipefail |
| 4 | + |
| 5 | +cleanup() { |
| 6 | + kill-containers "${SWIFT_DATA}" "${SWIFT_JOB}" "${PG_JOB}" |
| 7 | +} |
| 8 | +trap cleanup EXIT |
| 9 | + |
| 10 | +waitting-install-apk() { |
| 11 | + sleep 30s |
| 12 | + apk_running="apk" |
| 13 | + puts-step "Installing apk, coffee" |
| 14 | + while true |
| 15 | + do |
| 16 | + apk_running=$(docker exec "${PG_JOB}" "ps -ef|grep apk|grep -v grep") |
| 17 | + if [ -z "$apk_running" ] ; then |
| 18 | + break |
| 19 | + fi |
| 20 | + puts-step "..." |
| 21 | + sleep 10s |
| 22 | + done |
| 23 | + echo "Install apk process is complete" |
| 24 | +} |
| 25 | + |
| 26 | +TEST_ROOT=$(dirname "${BASH_SOURCE[0]}")/ |
| 27 | +# shellcheck source=/dev/null |
| 28 | +source "${TEST_ROOT}/test.sh" |
| 29 | + |
| 30 | +# make sure we are in this dir |
| 31 | +CURRENT_DIR=$(cd "$(dirname "$0")"|| exit; pwd) |
| 32 | + |
| 33 | +create-postgres-creds |
| 34 | + |
| 35 | +puts-step "fetching openstack credentials" |
| 36 | + |
| 37 | +# turn creds into something that we can use. |
| 38 | +mkdir -p "${CURRENT_DIR}"/tmp/swift |
| 39 | + |
| 40 | +# guess which value to use for tenant: |
| 41 | +TENANT="" |
| 42 | + |
| 43 | +echo "test:tester" > "${CURRENT_DIR}"/tmp/swift/username |
| 44 | +echo "testing" > "${CURRENT_DIR}"/tmp/swift/password |
| 45 | +echo "${TENANT}" > "${CURRENT_DIR}"/tmp/swift/tenant |
| 46 | +echo "http://swift:8080/auth/v1.0" > "${CURRENT_DIR}"/tmp/swift/authurl |
| 47 | +echo "1" > "${CURRENT_DIR}"/tmp/swift/authversion |
| 48 | +echo "deis-swift-test" > "${CURRENT_DIR}"/tmp/swift/database-container |
| 49 | + |
| 50 | +# boot swift |
| 51 | +SWIFT_DATA=$(docker run -d -v /srv --name SWIFT_DATA busybox) |
| 52 | + |
| 53 | +SWIFT_JOB=$(docker run -d --name onlyone --hostname onlyone --volumes-from SWIFT_DATA -t deis/swift-onlyone:git-8516d23) |
| 54 | + |
| 55 | +test-upgrade-from(){ |
| 56 | + PGDATA_DIR=${CURRENT_DIR}/tmp/postgres/tmp_$(date +%s) |
| 57 | + mkdir -p "$PGDATA_DIR" |
| 58 | + |
| 59 | + docker run --rm \ |
| 60 | + -v "${PGDATA_DIR}:/var/lib/postgres/pg_data" \ |
| 61 | + -e PGDATA=/var/lib/postgres/pg_data \ |
| 62 | + "$1" \ |
| 63 | + bash -c "chown -R postgres /var/lib/postgres/pg_data && su-exec postgres initdb" |
| 64 | + |
| 65 | + PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \ |
| 66 | + -e DATABASE_STORAGE=swift \ |
| 67 | + -e PGCTLTIMEOUT=1200 \ |
| 68 | + -e PGDATA=/var/lib/postgres/pg_data \ |
| 69 | + -v ${PGDATA_DIR}:/var/lib/postgres/pg_data \ |
| 70 | + -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \ |
| 71 | + -v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \ |
| 72 | + $IMAGE" |
| 73 | + PG_JOB=$($PG_CMD) |
| 74 | + sleep 90s |
| 75 | + puts-step "sleeping for 90s while postgres is restore..." |
| 76 | + |
| 77 | + check-postgres "${PG_JOB}" |
| 78 | + puts-step "postgres upgrade from $1" |
| 79 | +} |
| 80 | + |
| 81 | +test-upgrade-from-wal() { |
| 82 | + PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \ |
| 83 | + -e DATABASE_STORAGE=swift \ |
| 84 | + -e PGCTLTIMEOUT=1200 \ |
| 85 | + -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \ |
| 86 | + -v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \ |
| 87 | + $1" |
| 88 | + |
| 89 | + start-postgres "$PG_CMD" |
| 90 | + # display logs for debugging purposes |
| 91 | + puts-step "displaying swift logs" |
| 92 | + docker logs "${SWIFT_JOB}" |
| 93 | + check-postgres "${PG_JOB}" |
| 94 | + puts-step "shutting off postgres, then rebooting to test data recovery" |
| 95 | + kill-containers "${PG_JOB}" |
| 96 | + |
| 97 | + PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \ |
| 98 | + -e DATABASE_STORAGE=swift \ |
| 99 | + -e PGCTLTIMEOUT=1200 \ |
| 100 | + -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \ |
| 101 | + -v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \ |
| 102 | + $IMAGE" |
| 103 | + |
| 104 | + start-postgres "${PG_CMD}" |
| 105 | + |
| 106 | + check-postgres "${PG_JOB}" |
| 107 | +} |
| 108 | + |
| 109 | +IMAGE="$1" |
| 110 | + |
| 111 | +test-upgrade-from postgres:9.4-alpine |
| 112 | +kill-containers "${PG_JOB}" |
| 113 | + |
| 114 | +test-upgrade-from postgres:9.5-alpine |
| 115 | +kill-containers "${PG_JOB}" |
| 116 | + |
| 117 | +test-upgrade-from postgres:9.6-alpine |
| 118 | +kill-containers "${PG_JOB}" |
| 119 | + |
| 120 | +test-upgrade-from postgres:10-alpine |
| 121 | +kill-containers "${PG_JOB}" |
| 122 | + |
| 123 | +test-upgrade-from postgres:11-alpine |
| 124 | +kill-containers "${PG_JOB}" |
| 125 | + |
| 126 | +test-upgrade-from-wal hephy/postgres:v2.7.1 |
| 127 | + |
| 128 | +puts-step "tests PASSED!" |
| 129 | +exit 0 |
0 commit comments