summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README32
-rw-r--r--lib.sh21
-rw-r--r--lib_pgsql.sh60
-rwxr-xr-xrun151
-rw-r--r--tasks/initdb/config.sh4
-rwxr-xr-xtasks/initdb/runtest.sh5
-rw-r--r--tasks/initdb_old/config.sh4
-rwxr-xr-xtasks/initdb_old/runtest.sh5
8 files changed, 282 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..68b53a9
--- /dev/null
+++ b/README
@@ -0,0 +1,32 @@
+GENERAL INFO
+============
+
+System checking (dummy) testsuite fw. The tests are *expected* to be
+destructive and always performed under root account; test writer should only
+make sure that no test conflicts with others (so that all tests are able to run
+on one machine successfully in any order).
+
+OVERVIEW
+========
+
+
+Each file should consist of config.sh and runtest.sh. Both are supposed to be
+"sourced" into another scripts (so no need to have execute permissions). Each
+test case should have its own directory.
+
+USAGE
+=====
+
+The most simple usage is like `./run`. Script is able to search for available
+test-cases and then run them. For more info, run `./run --help`. TODO: The
+testsuite is root-only.
+
+API for config.sh file
+======================
+
+Variables which should/may be defined in config.sh file.
+
+$DTF_TEST_ID - unique ID of task. Without spaces.
+
+$DTF_TEST_DESCRIPTION - descriptive info about test, will be used for
+generating html or otherwise formated result output.
diff --git a/lib.sh b/lib.sh
new file mode 100644
index 0000000..f86255b
--- /dev/null
+++ b/lib.sh
@@ -0,0 +1,21 @@
+# package-agnostic function library. The "dtf_" prefix stands for
+# "destructive test framework".
+
+. `dirname $BASH_SOURCE`/lib_pgsql.sh
+
+dtf_generate_results_tarball()
+{
+ local dir=$(dirname $1)
+ local name=$(basename $1)
+
+ local tarball=$dir/$name.tar.gz
+
+ pushd $dir >/dev/null
+
+ local oumask=`umask`
+ umask 0077
+ tar -czf $tarball $name
+ umask $oumask
+
+ export DTF_RESULT_TARBALL=$tarball
+}
diff --git a/lib_pgsql.sh b/lib_pgsql.sh
new file mode 100644
index 0000000..6997827
--- /dev/null
+++ b/lib_pgsql.sh
@@ -0,0 +1,60 @@
+# 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 -r /var/lib/pgsql/data"
+ rlPhaseEnd
+}
+
+dtf_postgresql_checkphase()
+{
+ rlPhaseStart FAIL "Check"
+ rlAssertRpm postgresql-server
+
+ dtf_postgresql_check_stopped
+
+ rlAssertNotExists "/var/lib/pgsql/data"
+
+ 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
+}
diff --git a/run b/run
new file mode 100755
index 0000000..ae97a5b
--- /dev/null
+++ b/run
@@ -0,0 +1,151 @@
+#!/bin/bash
+
+## CONFIG ##
+
+export dtf_resultdir=${dtf_resultdir_override-/var/tmp/dtf}
+export dtf_srcdir=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+export dtf_testdir=${dtf_testdir-$dtf_srcdir}
+
+export dtf_option_verbose=0
+export dtf_option_force=0
+export dtf_option_testids=""
+export dtf_option_listonly=0
+
+## F.DEFS ##
+
+info()
+{
+ echo " * $@"
+}
+
+die()
+{
+ echo "$@" >&2
+ exit 1
+}
+
+# run TESTDIR
+# -----------
+# source the $TESTDIR/runtest.sh
+run()
+{
+ export dtf_workdir=$1
+ export dtf_test_id=`basename $dtf_workdir`
+
+ ( cd $dtf_workdir
+
+ outlog="$dtf_resultdir/$dtf_test_id.log"
+ output_wrapper="cat > $outlog"
+
+ test $dtf_option_verbose = 1 \
+ && output_wrapper="tee $outlog"
+
+ test ! -e ./config.sh -o ! -e ./config.sh \
+ && echo "can not find one of {config,runtest}.sh"
+
+ . ./config.sh
+
+ if test "$dtf_option_listonly" -eq 1; then
+ echo $DTF_TEST_ID
+ exit 0
+ fi
+
+ if test -n "$dtf_option_testids"; then
+ [[ "$dtf_option_testids" = *\ $DTF_TEST_ID\ * ]] || exit 0
+ fi
+
+ printf "%-40s" "RUN $DTF_TEST_ID ..."
+
+ set -o pipefail
+
+ ( . $dtf_srcdir/lib.sh || exit 1
+
+ . ./config.sh
+ . ./runtest.sh
+ rv=$?
+
+ test -n "$DTF_RESULT_TARBALL" \
+ && cp "$DTF_RESULT_TARBALL" $dtf_resultdir/$dtf_test_id.tar.gz
+
+ exit $rv
+ ) 2>&1 | eval $output_wrapper
+ rv=$?
+
+ test $rv -eq 0 && echo "[ OK ]" || echo "[ FAIL ]"
+ exit $rv
+ )
+}
+
+prepare_resultdir()
+{
+ if test -e "$dtf_resultdir"; then
+ test $dtf_option_force -eq 0 && die "result dir $dtf_resultdir exits"
+
+ rm -rf $dtf_resultdir || die "can not remove $dtf_resultdir"
+ fi
+
+ mkdir -p "$dtf_resultdir" || die "can not create $dtf_resultdir"
+}
+
+show_help()
+{
+cat <<EOHELP >&2
+Usage: $0 [OPTIONS]
+
+Script is aimed to perform set of tests in subdirectories.
+
+Options:
+ --force Overwrite result dir if exists
+ --listonly List the available test ids
+ --testid=TESTID Perform this test only
+ --verbose Show complete output from each test
+ --help Show this help
+EOHELP
+test -n "$1" && exit $1
+}
+
+longopts="verbose,help,force,testid:,listonly"
+ARGS=`getopt -o "v" -l "$longopts" -n "getopt" -- "$@"`
+if [ $? -ne 0 ]; then
+ echo "getopt error"
+ exit 1
+fi
+eval set -- "$ARGS"
+
+while true; do
+ case "$1" in
+ --verbose)
+ dtf_option_verbose=1
+ shift
+ ;;
+ --force)
+ dtf_option_force=1
+ shift
+ ;;
+ --listonly)
+ dtf_option_listonly=1
+ shift
+ ;;
+ --testid)
+ dtf_option_testids="$dtf_option_testids $2 "
+ shift 2
+ ;;
+ --help)
+ show_help 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ esac
+done
+
+test $dtf_option_listonly -ne 1 && prepare_resultdir
+
+result=0
+for i in `find $dtf_testdir -name runtest.sh`; do
+ testdir=`dirname $i`
+ run $testdir || result=1
+done
+
+exit $result
diff --git a/tasks/initdb/config.sh b/tasks/initdb/config.sh
new file mode 100644
index 0000000..c7f6619
--- /dev/null
+++ b/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/tasks/initdb/runtest.sh b/tasks/initdb/runtest.sh
new file mode 100755
index 0000000..5a942ef
--- /dev/null
+++ b/tasks/initdb/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/tasks/initdb_old/config.sh b/tasks/initdb_old/config.sh
new file mode 100644
index 0000000..f04f7ba
--- /dev/null
+++ b/tasks/initdb_old/config.sh
@@ -0,0 +1,4 @@
+DTF_TEST_ID="initdb-old-syntax"
+DESCRIPTION="\
+Check that the old syntax 'postgresql-setup initdb' works together with
+following 'service start postgresql'."
diff --git a/tasks/initdb_old/runtest.sh b/tasks/initdb_old/runtest.sh
new file mode 100755
index 0000000..6a8d63c
--- /dev/null
+++ b/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