testprogs: Fix and improve demote-saveddb test
authorAndreas Schneider <asn@samba.org>
Tue, 20 Oct 2020 18:47:43 +0000 (20:47 +0200)
committerKarolin Seeger <kseeger@samba.org>
Tue, 27 Oct 2020 08:22:02 +0000 (08:22 +0000)
This fixes running `make test` in a release tarball!

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14542

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
(cherry picked from commit e58ccdaa1a1e5943aa02ecba88d1de0323777041)

testprogs/blackbox/demote-saveddb.sh

index 3d5fabd72e3659723551b40e42ccb252bb1a0b44..d8fccf32011d36a8907c85414319bba47b050cd0 100755 (executable)
@@ -10,58 +10,69 @@ fi
 PREFIX_ABS="$1"
 shift 1
 
-. `dirname $0`/subunit.sh
+failed=0
 
-tree_dir=`dirname $0`/../../source4/selftest/provisions/multi-dc-samba-master-c596ac6
+. `dirname $0`/subunit.sh
+. `dirname $0`/common_test_fns.inc
 
-undump() {
-       if test -x $BINDIR/tdbrestore;
-       then
-       `dirname $0`/../../source4/selftest/provisions/undump.sh $tree_dir $PREFIX_ABS $BINDIR/tdbrestore
-       else
-       `dirname $0`/../../source4/selftest/provisions/undump.sh $tree_dir $PREFIX_ABS
-       fi
-}
+samba_tree_dir="$SRCDIR_ABS/source4/selftest/provisions/multi-dc-samba-master-c596ac6"
 
-demote() {
-       $PYTHON $BINDIR/samba-tool domain demote -H tdb://$PREFIX_ABS/private/sam.ldb --remove-other-dead-server=$1
-}
+samba_tdbrestore="tdbrestore"
+if [ -x $BINDIR/tdbrestore ]; then
+    samba_tdbrestore="$BINDIR/tdbrestore"
+fi
 
+# The undump script and the provision data is not part of release tarballs,
+# skip the tests in this case!
+samba_undump="$SRCDIR_ABS/source4/selftest/provisions/undump.sh"
+if [ ! -x $samba_undump ] || [ ! -d $samba_tree_dir ]; then
+    subunit_start_test "undump"
+    subunit_skip_test "undump" <<EOF
+EOF
 
-if [ -d $tree_dir ]; then
-    testit "undump" undump
-    testit "demote-q-0-0" demote "q-0-0"
-    # The database was copied of q-0-1 so this will fail
-    # as we can't remove our own name
-    testit_expect_failure "demote-q-0-1" demote "q-0-1"
-    testit "demote-q-1-0" demote "q-1-0"
-    testit "demote-q-1-1" demote "q-1-1"
-else
     subunit_start_test "undump"
     subunit_skip_test "undump" <<EOF
-no test provision
+Skipping tests - no provision!
 EOF
 
     subunit_start_test "demote-q-0-0"
     subunit_skip_test "demote-q-0-0" <<EOF
-no test provision
+Skipping tests - no provision!
 EOF
     subunit_start_test "demote-q-0-1"
     subunit_skip_test "demote-q-0-1" <<EOF
-no test provision
+Skipping tests - no provision!
 EOF
-    subunit_start_test "demote-q-1-1"
-    subunit_skip_test "demote-q-0-1" <<EOF
-no test provision
+    subunit_start_test "demote-q-1-0"
+    subunit_skip_test "demote-q-1-0" <<EOF
+Skipping tests - no provision!
 EOF
     subunit_start_test "demote-q-1-1"
     subunit_skip_test "demote-q-1-1" <<EOF
-no test provision
+Skipping tests - no provision!
 EOF
-fi
 
-if [ -d $PREFIX_ABS ]; then
-    rm -fr $PREFIX_ABS
+    exit 0
 fi
 
+undump() {
+    $SRCDIR_ABS/source4/selftest/provisions/undump.sh $samba_tree_dir $PREFIX_ABS $samba_tdbrestore
+}
+
+demote() {
+       $PYTHON $BINDIR/samba-tool domain demote -H tdb://$PREFIX_ABS/private/sam.ldb --remove-other-dead-server=$1
+}
+
+remove_directory $PREFIX_ABS
+
+testit "undump" undump || failed=`expr $failed + 1`
+testit "demote-q-0-0" demote "q-0-0" || failed=`expr $failed + 1`
+# The database was copied of q-0-1 so this will fail
+# as we can't remove our own name
+testit_expect_failure "demote-q-0-1" demote "q-0-1" || failed=`expr $failed + 1`
+testit "demote-q-1-0" demote "q-1-0" || failed=`expr $failed + 1`
+testit "demote-q-1-1" demote "q-1-1" || failed=`expr $failed + 1`
+
+remove_directory $PREFIX_ABS
+
 exit $failed