summaryrefslogtreecommitdiffstats
path: root/postgresql-tests
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2014-10-22 08:54:05 +0200
committerPavel Raiskup <praiskup@redhat.com>2014-10-22 08:54:05 +0200
commit2422a081a5be0d5ac5afb122361bc283da67341f (patch)
treecb255582060af6547dd9318c56ba0e8c761846a1 /postgresql-tests
parent922089746e1029de9be986672fcdeb6bc82e18d7 (diff)
downloadpostgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.tar.gz
postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.tar.xz
postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.zip
big reorg: prepare for generalization
Try to split into three separate components -> controller, tester, and 'tasks' (postgresql-tasks in our case). The controller component is the main part which is able to run the task remotely. Tester is more-like library for 'tasks' component (should be reusable on the raw git level). * controller: Almost separated component. * postgresql-tasks: Likewise. * tester: Likewise.
Diffstat (limited to 'postgresql-tests')
-rw-r--r--postgresql-tests/config.sh10
-rw-r--r--postgresql-tests/dist.include6
-rw-r--r--postgresql-tests/gen-data/databases/pagila.sh39
-rwxr-xr-xpostgresql-tests/gen-data/dist/dist4
-rw-r--r--postgresql-tests/gen-data/dist/dist.exclude1
-rw-r--r--postgresql-tests/gen-data/dist/dist.list5
-rwxr-xr-xpostgresql-tests/gen-data/generate129
-rwxr-xr-xpostgresql-tests/gen-data/prep5
-rwxr-xr-xpostgresql-tests/gen-data/remote_generate18
-rw-r--r--postgresql-tests/gen-data/tasks/basic/run.sh6
-rw-r--r--postgresql-tests/gen-data/tasks/locale-cz/run.sh5
-rw-r--r--postgresql-tests/gen-data/tasks/locale-utf-typo/run.sh5
-rw-r--r--postgresql-tests/gen-data/tasks/templates/locale-change.sh16
-rw-r--r--postgresql-tests/lib_pgsql.sh157
l---------postgresql-tests/libdtf1
l---------postgresql-tests/run1
-rw-r--r--postgresql-tests/tasks/initdb/config.sh4
-rwxr-xr-xpostgresql-tests/tasks/initdb/runtest.sh11
-rw-r--r--postgresql-tests/tasks/initdb_old/config.sh4
-rwxr-xr-xpostgresql-tests/tasks/initdb_old/runtest.sh5
-rw-r--r--postgresql-tests/tasks/upgrade-basic/config.sh2
-rw-r--r--postgresql-tests/tasks/upgrade-basic/runtest.sh6
-rw-r--r--postgresql-tests/tasks/upgrade-utf8-syntax/config.sh3
-rw-r--r--postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh15
24 files changed, 458 insertions, 0 deletions
diff --git a/postgresql-tests/config.sh b/postgresql-tests/config.sh
new file mode 100644
index 0000000..c5bd47a
--- /dev/null
+++ b/postgresql-tests/config.sh
@@ -0,0 +1,10 @@
+# include PostgreSQL specific test-library
+. "$srcdir/lib_pgsql.sh" || exit 1
+
+# this is needed for some tests
+export dtf_dataurl=http://pensioner.lab.eng.brq.redhat.com/root-tests/data/postgresql/
+
+dtf_cb_dist_tasks()
+{
+ tar -ch "$dir" --exclude gen-data
+}
diff --git a/postgresql-tests/dist.include b/postgresql-tests/dist.include
new file mode 100644
index 0000000..ed7c787
--- /dev/null
+++ b/postgresql-tests/dist.include
@@ -0,0 +1,6 @@
+config.sh
+dist.include
+libdtf
+lib_pgsql.sh
+run
+tasks
diff --git a/postgresql-tests/gen-data/databases/pagila.sh b/postgresql-tests/gen-data/databases/pagila.sh
new file mode 100644
index 0000000..a01d818
--- /dev/null
+++ b/postgresql-tests/gen-data/databases/pagila.sh
@@ -0,0 +1,39 @@
+create_pagila()
+(
+ testit()
+ {
+ debug "testing database"
+
+ local cmd="psql -tA -d pagila -c \"select city from city where city = 'Banjul';\""
+
+ out="$(admin_cmd "$cmd")"
+ test "$out" = Banjul || return 1
+ test "$(wc -l < pagila_init.log)" -gt 335 || return 1
+
+ test "$({ grep ERROR | wc -l ; } < pagila_init.log)" -lt 2
+ }
+
+ debug "creating DB pagilla"
+ INDENT="$INDENT "
+
+ pagila="pagila-0.10.1"
+ pagila_tarball="$pagila.zip"
+ pagila_link="http://pgfoundry.org/frs/download.php/1719/$pagila_tarball"
+
+ cached_download $pagila_link
+
+ debug "unzipping tarball"
+ unzip $pagila_tarball &>/dev/null || die "can not unzip pagila"
+
+ pushd $pagila >/dev/null || die "can not switch directory"
+ admin_cmd "createdb pagila --owner postgres" || die "can't create db"
+ { su - postgres -c 'psql -d pagila' < pagila-schema.sql \
+ && su - postgres -c 'psql -d pagila' < pagila-data.sql
+ } &>pagila_init.log || die "can not initialize pagila"
+
+ cp pagila_init.log /tmp
+
+ testit || die "can not test"
+
+ popd >/dev/null || die "can't go back"
+)
diff --git a/postgresql-tests/gen-data/dist/dist b/postgresql-tests/gen-data/dist/dist
new file mode 100755
index 0000000..c9aea1b
--- /dev/null
+++ b/postgresql-tests/gen-data/dist/dist
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+# !!!! creating tar-BOMB !!!!
+tar -cf dist/dist.tar.gz -T dist/dist.list -X dist/dist.exclude
diff --git a/postgresql-tests/gen-data/dist/dist.exclude b/postgresql-tests/gen-data/dist/dist.exclude
new file mode 100644
index 0000000..484ab7e
--- /dev/null
+++ b/postgresql-tests/gen-data/dist/dist.exclude
@@ -0,0 +1 @@
+results/*
diff --git a/postgresql-tests/gen-data/dist/dist.list b/postgresql-tests/gen-data/dist/dist.list
new file mode 100644
index 0000000..832aca4
--- /dev/null
+++ b/postgresql-tests/gen-data/dist/dist.list
@@ -0,0 +1,5 @@
+prep
+generate
+databases
+tasks
+results
diff --git a/postgresql-tests/gen-data/generate b/postgresql-tests/gen-data/generate
new file mode 100755
index 0000000..d8ead6b
--- /dev/null
+++ b/postgresql-tests/gen-data/generate
@@ -0,0 +1,129 @@
+#!/bin/bash
+
+GEN_DATADIR=/var/lib/pgsql/data
+CACHEDIR=/var/cache/dbt
+OUTPUTDIR="$(pwd)/results"
+SRCDIR="$(pwd)"
+DEBUG=1
+CHECK_LOCALE=1
+
+printline() { echo "$INDENT$@" ; }
+
+die() { printline " ERROR $@" ; exit 1 ; }
+
+info() { printline " * $@"; }
+
+debug() { test $DEBUG -eq 1 && printline " ~ $@"; }
+
+admin_cmd()
+{
+ su - postgres -c "$@" || die "can not execute '$@'"
+}
+
+cached_download()
+{
+ local link=$1
+ local bn="$(basename "$1")"
+ local file="$CACHEDIR/$bn"
+
+ if test ! -d "$CACHEDIR"; then
+ mkdir -p "$CACHEDIR" || die "can't create cachedir"
+ fi
+
+ test -e "$file" && cp "$file" ./ && return
+
+ { wget "$link" && cp "$bn" "$CACHEDIR" ; } \
+ || die "can't download"
+}
+
+is_defined_f()
+{
+ declare -f "$1" >/dev/null
+}
+
+run_if_defined()
+{
+ is_defined_f "$1" || return 0
+ "$1"
+}
+
+locale_prereq()
+{
+ local default_locale="LANG=en_US.UTF-8"
+ local current_locale="$(cat /etc/locale.conf)"
+ test "$current_locale" = "$default_locale" \
+ || die "bad locale '$current_locale', should be '$default_locale'"
+}
+
+single_task()
+{
+ local task="$1"
+
+ info "running task $task"
+
+ (
+ INDENT=" "
+ . "$SRCDIR/databases/pagila.sh" || die "pagila incl fail"
+ . "$SRCDIR/$task" || die "include fail"
+
+ run_if_defined "hook_start"
+
+ test "$CHECK_LOCALE" -eq 1 && locale_prereq
+
+ debug "initializing database"
+ postgresql-setup initdb &>/dev/null || die "can not initdb"
+
+ debug "starting server"
+ service postgresql start &>/dev/null || die "can't start postgresql"
+
+ tmpdir=$(mktemp -d /tmp/dbt-XXXXXX) || die "can not create temp directory"
+
+ debug "working in $tmpdir"
+ pushd "$tmpdir" >/dev/null || die "can switch to $tmpdir"
+
+ run || die "fail"
+
+ popd >/dev/null || die "can not switch back"
+
+ debug "stopping server"
+ service postgresql stop &>/dev/null || die "can't stop postgresql"
+
+ tarball="$OUTPUTDIR/$task_name.tar.gz"
+ tar -czf "$tarball" -C /var/lib/pgsql/ data
+ info "result tarball $tarball"
+ rm -rf "$tmpdir"
+
+
+ debug "data removal"
+ rm -rf "$GEN_DATADIR"
+
+ run_if_defined "hook_end"
+ )
+}
+
+generate_tasks()
+{
+ find ./tasks -name run.sh | while read line; do
+ single_task "$line"
+ done
+}
+
+main()
+{
+ test "$UID" -ne 0 && die "run under 'root' user"
+
+ test -d "$OUTPUTDIR" || die "$OUTPUTDIR does not seem to be directory"
+
+ service postgresql status &>/dev/null
+ test $? -ne 3 && die "stop the postgresql server"
+
+ local dbdir="$GEN_DATADIR"
+ test -e "$dbdir" && die "the '$dbdir' should not exist"
+
+ { rpm -qa postgresql && rpm -qa postgresql-server ; } &>/dev/null \
+ || die "PostgreSQL not installed"
+
+ generate_tasks
+}
+
+main
diff --git a/postgresql-tests/gen-data/prep b/postgresql-tests/gen-data/prep
new file mode 100755
index 0000000..b5b19b5
--- /dev/null
+++ b/postgresql-tests/gen-data/prep
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+yum install -y wget postgresql-server unzip
+echo "LANG=en_US.UTF-8" > /etc/locale.conf
+rm -rf /var/lib/pgsql/data
diff --git a/postgresql-tests/gen-data/remote_generate b/postgresql-tests/gen-data/remote_generate
new file mode 100755
index 0000000..eee11f6
--- /dev/null
+++ b/postgresql-tests/gen-data/remote_generate
@@ -0,0 +1,18 @@
+#!/bin/bash -x
+
+where="root@$1"
+
+./dist/dist
+tar tf dist/dist.tar.gz
+
+ssh_opts="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
+ssh="ssh $ssh_opts"
+scp="scp $ssh_opts"
+
+$scp dist/dist.tar.gz "$where:/root"
+
+$ssh "$where" "cd /root ; tar -xf dist.tar.gz ; ./prep && ./generate"
+
+rm -rf remote_results
+mkdir remote_results
+$scp -r "$where:/root/results" ./remote_results
diff --git a/postgresql-tests/gen-data/tasks/basic/run.sh b/postgresql-tests/gen-data/tasks/basic/run.sh
new file mode 100644
index 0000000..0118ad3
--- /dev/null
+++ b/postgresql-tests/gen-data/tasks/basic/run.sh
@@ -0,0 +1,6 @@
+export task_name="basic"
+
+run()
+{
+ create_pagila
+}
diff --git a/postgresql-tests/gen-data/tasks/locale-cz/run.sh b/postgresql-tests/gen-data/tasks/locale-cz/run.sh
new file mode 100644
index 0000000..1788557
--- /dev/null
+++ b/postgresql-tests/gen-data/tasks/locale-cz/run.sh
@@ -0,0 +1,5 @@
+export task_name="locale-cz"
+
+export ___new_locale="LANG=cs_CZ.utf8"
+
+. ./tasks/templates/locale-change.sh
diff --git a/postgresql-tests/gen-data/tasks/locale-utf-typo/run.sh b/postgresql-tests/gen-data/tasks/locale-utf-typo/run.sh
new file mode 100644
index 0000000..9004a88
--- /dev/null
+++ b/postgresql-tests/gen-data/tasks/locale-utf-typo/run.sh
@@ -0,0 +1,5 @@
+export task_name="locale-utf-typo"
+
+export ___new_locale="LANG=en_US.utf8"
+
+. ./tasks/templates/locale-change.sh
diff --git a/postgresql-tests/gen-data/tasks/templates/locale-change.sh b/postgresql-tests/gen-data/tasks/templates/locale-change.sh
new file mode 100644
index 0000000..8f7964f
--- /dev/null
+++ b/postgresql-tests/gen-data/tasks/templates/locale-change.sh
@@ -0,0 +1,16 @@
+hook_start()
+{
+ export CHECK_LOCALE=0
+ ___old_locale="$(cat /etc/locale.conf)"
+ echo "$___new_locale" > /etc/locale.conf
+}
+
+hook_end()
+{
+ echo "$___old_locale" > /etc/locale.conf
+}
+
+run()
+{
+ create_pagila
+}
diff --git a/postgresql-tests/lib_pgsql.sh b/postgresql-tests/lib_pgsql.sh
new file mode 100644
index 0000000..13bfc82
--- /dev/null
+++ b/postgresql-tests/lib_pgsql.sh
@@ -0,0 +1,157 @@
+# PostgreSQL related helper functions.
+
+# PostgreSQL tests require beakerlib:
+# https://fedorahosted.org/beakerlib/
+
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+dtf_postgresql_check_started()
+{
+ service postgresql status &>/dev/null
+ rlAssertEquals "service postgresql should be started" $? 0
+}
+
+dtf_postgresql_check_stopped()
+{
+ service postgresql status &>/dev/null
+ rlAssertEquals "service postgresql should be stopped" $? 3
+}
+
+dtf_postgresql_phase_cleanup()
+{
+ rlPhaseStartCleanup
+ rlServiceStop postgresql
+ dtf_postgresql_check_stopped
+ rlRun "rm -rf /var/lib/pgsql/data"
+ rlPhaseEnd
+}
+
+dtf_postgresql_checkphase()
+{
+ rlPhaseStart FAIL "Check"
+ rlAssertRpm postgresql-server
+
+ dtf_postgresql_check_stopped
+
+ rlAssertNotExists "/var/lib/pgsql/data/PG_VERSION"
+
+ rlAssert0 "run under root user" "$(id -u)"
+
+ rlGetPhaseState
+ test $? -gt 0 \
+ && echo >&2 "Check phase failed." && exit 1
+ rlPhaseEnd
+}
+
+dtf_postgresql_test_init()
+{
+ rlJournalStart
+ dtf_postgresql_checkphase
+ rlPhaseStartTest
+}
+
+dtf_postgresql_test_finish()
+{
+ rlPhaseEnd
+ dtf_generate_results_tarball "$BEAKERLIB_DIR"
+ dtf_postgresql_phase_cleanup
+ rlJournalEnd
+ rlGetTestState || return 1
+}
+
+dtf_postgresql_unpack_remote_data()
+(
+ local tarball="$1"
+ cd /var/lib/pgsql || return 1
+ set -o pipefail
+ echo "downloading '$tarball'"
+ curl "$tarball" | tar -xzf -
+)
+
+# Detect current distribution and print set of "distro version action" lines
+# where DISTRO may be rhel/fedora, VERSION may be e.g. 6.6 for rhel or 20 for
+# Fedora. ACTION is either run or upgrade and it means whether currently
+# installed PostgreSQL server is able to RUN the older data from DISTRO-VERSION
+# or it should be first UPGRADEd.
+#
+# What versions are currently in Fedoras:
+# f17(9.1.9); f18(9.2.5); f19(9.2.9); f20(9.3.5); f21(9.3.5);
+# rawhide(9.3.5)
+
+dtf_postgresql_upgrade_matrix()
+{
+ if rlIsFedora 19; then
+ # echo fedora 17 upgrade
+ # echo fedora 18 run
+ echo fedora 19 run
+ elif rlIsFedora 20; then
+ # echo fedora 18 upgrade
+ echo fedora 19 upgrade
+ echo fedora 20 run
+ elif rlIsFedora 21; then
+ echo fedora 19 upgrade
+ echo fedora 20 run
+ echo fedora 21 run
+ elif rlIsFedora 22; then
+ echo fedora 19 upgrade
+ echo fedora 20 run
+ echo fedora 21 run
+ echo fedora 22 run
+ fi
+}
+
+dtf_postgresql_cb_upgrade()
+{
+ local dashdash=""
+ if rlIsFedora 22; then
+ dashdash="--"
+ fi
+ rlRun "postgresql-setup $dashdash""upgrade"
+}
+
+dtf_postgresql_cb_upgrade_select()
+{
+ cat
+}
+
+dtf_postgresql_upgrade_tour()
+{
+ local arch=$(uname -i)
+ local rv=0
+
+ items="$(dtf_postgresql_upgrade_matrix | dtf_postgresql_cb_upgrade_select)"
+ test "$items" = "$(:)" && return 0
+
+ while read distro version action; do
+ echo "--> Performing upgrade: $distro-$version - $action"
+
+ url="$1/$distro/$version/$arch/$2"
+
+ dtf_postgresql_unpack_remote_data "$url" || return 1
+
+ case "$action" in
+ upgrade)
+ dtf_postgresql_cb_upgrade
+ if test $? -ne 0; then
+ rv=1
+ find /var/lib/pgsql -maxdepth 1 -name '*.log' | \
+ while read line; do
+ echo "====== reading log $line ======"
+ cat "$line"
+ done
+ fi
+ ;;
+ *)
+ ;;
+ esac
+
+ rlServiceStart postgresql
+ dtf_postgresql_check_started
+ rlServiceStop postgresql
+ dtf_postgresql_check_stopped
+
+ rm -rf /var/lib/pgsql/data
+ done <<<"$items"
+
+ return $rv
+}
diff --git a/postgresql-tests/libdtf b/postgresql-tests/libdtf
new file mode 120000
index 0000000..2aca4c4
--- /dev/null
+++ b/postgresql-tests/libdtf
@@ -0,0 +1 @@
+../tester/libdtf \ No newline at end of file
diff --git a/postgresql-tests/run b/postgresql-tests/run
new file mode 120000
index 0000000..adeed00
--- /dev/null
+++ b/postgresql-tests/run
@@ -0,0 +1 @@
+../tester/run \ No newline at end of file
diff --git a/postgresql-tests/tasks/initdb/config.sh b/postgresql-tests/tasks/initdb/config.sh
new file mode 100644
index 0000000..c7f6619
--- /dev/null
+++ b/postgresql-tests/tasks/initdb/config.sh
@@ -0,0 +1,4 @@
+DTF_TEST_ID="initdb-basic"
+DTF_TEST_DESCRIPTION="\
+Check that the syntax 'postgresql-setup --initdb' works together with following
+'service start postgresql'."
diff --git a/postgresql-tests/tasks/initdb/runtest.sh b/postgresql-tests/tasks/initdb/runtest.sh
new file mode 100755
index 0000000..ee520d6
--- /dev/null
+++ b/postgresql-tests/tasks/initdb/runtest.sh
@@ -0,0 +1,11 @@
+dtf_postgresql_test_init
+if rlIsFedora 18 19 20 21 || rlIsRHEL 5 6 7; then
+ # This syntaxe is not supported on oler systems.
+ :
+else
+ rlRun "postgresql-setup --initdb"
+ rlServiceStart postgresql
+ dtf_postgresql_check_started
+fi
+
+dtf_postgresql_test_finish
diff --git a/postgresql-tests/tasks/initdb_old/config.sh b/postgresql-tests/tasks/initdb_old/config.sh
new file mode 100644
index 0000000..2386677
--- /dev/null
+++ b/postgresql-tests/tasks/initdb_old/config.sh
@@ -0,0 +1,4 @@
+DTF_TEST_ID="initdb-old-syntax"
+DTF_TEST_DESCRIPTION="\
+Check that the old syntax 'postgresql-setup initdb' works together with
+following 'service start postgresql'."
diff --git a/postgresql-tests/tasks/initdb_old/runtest.sh b/postgresql-tests/tasks/initdb_old/runtest.sh
new file mode 100755
index 0000000..6a8d63c
--- /dev/null
+++ b/postgresql-tests/tasks/initdb_old/runtest.sh
@@ -0,0 +1,5 @@
+dtf_postgresql_test_init
+rlRun "postgresql-setup initdb"
+rlServiceStart postgresql
+dtf_postgresql_check_started
+dtf_postgresql_test_finish
diff --git a/postgresql-tests/tasks/upgrade-basic/config.sh b/postgresql-tests/tasks/upgrade-basic/config.sh
new file mode 100644
index 0000000..a1d4a2f
--- /dev/null
+++ b/postgresql-tests/tasks/upgrade-basic/config.sh
@@ -0,0 +1,2 @@
+export DTF_TEST_ID="basic-upgrade"
+export DTF_TEST_DESCRIPTION="Check postgresql-setup [--]upgrade"
diff --git a/postgresql-tests/tasks/upgrade-basic/runtest.sh b/postgresql-tests/tasks/upgrade-basic/runtest.sh
new file mode 100644
index 0000000..5dd85bb
--- /dev/null
+++ b/postgresql-tests/tasks/upgrade-basic/runtest.sh
@@ -0,0 +1,6 @@
+dtf_postgresql_test_init
+
+dtf_postgresql_upgrade_tour "$dtf_dataurl" basic.tar.gz
+rlAssert0 "test wrapper should finish successfully" $?
+
+dtf_postgresql_test_finish
diff --git a/postgresql-tests/tasks/upgrade-utf8-syntax/config.sh b/postgresql-tests/tasks/upgrade-utf8-syntax/config.sh
new file mode 100644
index 0000000..bed95ad
--- /dev/null
+++ b/postgresql-tests/tasks/upgrade-utf8-syntax/config.sh
@@ -0,0 +1,3 @@
+export DTF_TEST_ID="basic-locale-utf8-syntax"
+export DTF_TEST_DESCRIPTION="Check postgresql-setup --upgrade works even when \
+the system locale changed from xx_XX.utf8 to xx_XX.UTF-8"
diff --git a/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh b/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh
new file mode 100644
index 0000000..9e7d9cf
--- /dev/null
+++ b/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh
@@ -0,0 +1,15 @@
+dtf_postgresql_test_init
+
+dtf_postgresql_cb_upgrade_select()
+{
+ if rlIsFedora 20 21 22; then
+ cat
+ else
+ cat >/dev/null
+ fi
+}
+
+dtf_postgresql_upgrade_tour "$dtf_dataurl" locale-utf-typo.tar.gz
+rlAssert0 "test wrapper should finish successfully" $?
+
+dtf_postgresql_test_finish