summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2014-05-06 17:44:24 +1000
committerMartin Schwenke <martins@samba.org>2014-07-07 16:06:39 +0200
commiteccce073d084eceb4bfb5c25001b5873e2c0f2b2 (patch)
tree1d4280e6f04e3656a8ff52fd5fd2068df246bc9d
parent9c8c8a7b0bfd4c1cafa3deaa012049b7f0851617 (diff)
downloadsamba-eccce073d084eceb4bfb5c25001b5873e2c0f2b2.tar.gz
samba-eccce073d084eceb4bfb5c25001b5873e2c0f2b2.tar.xz
samba-eccce073d084eceb4bfb5c25001b5873e2c0f2b2.zip
ctdb-tests: Add a test for ctdb restoredb
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net> Autobuild-User(master): Martin Schwenke <martins@samba.org> Autobuild-Date(master): Mon Jul 7 16:06:39 CEST 2014 on sn-devel-104
-rwxr-xr-xctdb/tests/simple/58_ctdb_restoredb.sh118
1 files changed, 118 insertions, 0 deletions
diff --git a/ctdb/tests/simple/58_ctdb_restoredb.sh b/ctdb/tests/simple/58_ctdb_restoredb.sh
new file mode 100755
index 0000000000..31b81a6dcb
--- /dev/null
+++ b/ctdb/tests/simple/58_ctdb_restoredb.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+
+test_info()
+{
+ cat <<EOF
+The command 'ctdb restoredb' is used to restore a database across the
+whole cluster.
+
+Prerequisites:
+
+* An active CTDB cluster with at least 2 active nodes.
+
+Steps:
+
+1. Verify that the status on all of the ctdb nodes is 'OK'.
+2. Create a persistent test database
+3. Add some records to test database
+4. Backup database
+5. Wipe database and verify the database is empty on all nodes
+6. Restore database and make sure all the records are restored
+7. Make sure no recovery has been triggered
+
+Expected results:
+
+* Database operations should not cause a recovery
+
+EOF
+}
+
+. "${TEST_SCRIPTS_DIR}/integration.bash"
+
+ctdb_test_init "$@"
+
+set -e
+
+cluster_is_healthy
+
+try_command_on_node 0 $CTDB status
+generation=$(echo "$out" | sed -n -e 's/^Generation:\([0-9]*\)/\1/p')
+
+try_command_on_node 0 "$CTDB listnodes"
+num_nodes=$(echo "$out" | wc -l)
+
+# 2.
+test_db="restoredb_test.tdb"
+test_dump=$(mktemp)
+echo $test_dump
+echo "Create persistent test database \"$test_db\""
+try_command_on_node 0 $CTDB attach "$test_db" persistent
+try_command_on_node 0 $CTDB wipedb "$test_db"
+
+# 3.
+# add 10,000 records to database
+echo "Adding 10000 records to database"
+(
+for i in $(seq 1 10000) ; do
+ echo "\"key$i\" \"value$i\""
+done
+) | try_command_on_node -i 0 $CTDB ptrans "$test_db"
+
+num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
+if [ $num_records = "10000" ] ; then
+ echo "OK: Records added"
+else
+ echo "BAD: We did not end up with 10000 records"
+ echo "num records = $num_records"
+ exit 1
+fi
+
+ctdb_test_exit_hook_add "rm -f $test_dump"
+
+# 4.
+echo "Backup database"
+try_command_on_node 0 $CTDB backupdb "$test_db" "$test_dump"
+
+# 5.
+echo "Wipe database"
+try_command_on_node 0 $CTDB wipedb "$test_db"
+
+# check that the database is restored
+num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
+if [ $num_records = "0" ] ; then
+ echo "OK: Database was wiped"
+else
+ echo "BAD: We did not end up with an empty database"
+ echo "num records = $num_records"
+ exit 1
+fi
+
+# 6.
+echo "Restore database"
+try_command_on_node 0 $CTDB restoredb "$test_dump" "$test_db"
+
+# check that the database is restored
+num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
+if [ $num_records = "10000" ] ; then
+ echo "OK: Database was restored"
+else
+ echo "BAD: We did not end up with 10000 records"
+ echo "num records = $num_records"
+ exit 1
+fi
+
+# 7.
+wait_until_ready
+
+try_command_on_node 0 $CTDB status
+new_generation=$(echo "$out" | sed -n -e 's/^Generation:\([0-9]*\)/\1/p')
+
+echo "Old generation = $generation"
+echo "New generation = $new_generation"
+
+if [ "$generation" = "$new_generation" ]; then
+ echo "OK: Database recovery not triggered."
+else
+ echo "BAD: Database recovery triggered."
+ exit 1
+fi