diff options
Diffstat (limited to 'postgresql-tests/gen-data')
-rw-r--r-- | postgresql-tests/gen-data/databases/pagila.sh | 39 | ||||
-rwxr-xr-x | postgresql-tests/gen-data/dist/dist | 4 | ||||
-rw-r--r-- | postgresql-tests/gen-data/dist/dist.exclude | 1 | ||||
-rw-r--r-- | postgresql-tests/gen-data/dist/dist.list | 5 | ||||
-rwxr-xr-x | postgresql-tests/gen-data/generate | 129 | ||||
-rwxr-xr-x | postgresql-tests/gen-data/prep | 5 | ||||
-rwxr-xr-x | postgresql-tests/gen-data/remote_generate | 18 | ||||
-rw-r--r-- | postgresql-tests/gen-data/tasks/basic/run.sh | 6 | ||||
-rw-r--r-- | postgresql-tests/gen-data/tasks/locale-cz/run.sh | 5 | ||||
-rw-r--r-- | postgresql-tests/gen-data/tasks/locale-utf-typo/run.sh | 5 | ||||
-rw-r--r-- | postgresql-tests/gen-data/tasks/templates/locale-change.sh | 16 |
11 files changed, 233 insertions, 0 deletions
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 +} |