diff options
author | Amitay Isaacs <amitay@gmail.com> | 2017-08-18 14:27:10 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-08-25 09:41:25 +0200 |
commit | 9a92d712705356d18f70dfb779c18256794966b9 (patch) | |
tree | f8922aae2f6f9366c12b5a6bbe9a0404393186f2 | |
parent | 9691b72a8785c2bc2561bd6c897fea3c0cc2cbeb (diff) | |
download | samba-9a92d712705356d18f70dfb779c18256794966b9.tar.gz |
ctdb-tests: Add a test to check databases are attached with correct flags
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-x | ctdb/tests/simple/21_ctdb_attach.sh | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/ctdb/tests/simple/21_ctdb_attach.sh b/ctdb/tests/simple/21_ctdb_attach.sh new file mode 100755 index 00000000000..11b600800a4 --- /dev/null +++ b/ctdb/tests/simple/21_ctdb_attach.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +test_info() +{ + cat <<EOF +Verify the operation of 'ctdb attach' command. + +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. Shut down one of the nodes +3. Attach test databases +4. Start shutdown node +5. Verify that the databases are attached. +6. Restart one of the nodes +7. Verify that the databses are attached. + + +Expected results: + +* Command 'ctdb attach' command successfully attaches databases. +EOF +} + +. "${TEST_SCRIPTS_DIR}/integration.bash" + +ctdb_test_init "$@" + +set -e + +cluster_is_healthy + +# Reset configuration +ctdb_restart_when_done + +###################################################################### + +try_command_on_node 0 "$CTDB listnodes -X" +listnodes_output="$out" +numnodes=$(wc -l <<<"$listnodes_output") +lastnode=$(( numnodes - 1 )) + +###################################################################### + +# Confirm that the database is attached +check_db () +{ + pnn="$1" + db="$2" + flag="$3" + try_command_on_node $pnn "$CTDB getdbmap | grep $db" + if [ -z "$out" ] ; then + echo "BAD: database $db is not attached on node $node" + echo "$out" + exit 1 + else + local flags=$(awk '{print $4}' <<<"$out") || true + if [ "$flags" = "$flag" ]; then + echo "GOOD: database $db is attached on node $node with flag $flag" + else + echo "BAD: database $db is attached on node $node with wrong flag" + echo "$out" + exit 1 + fi + fi +} + +###################################################################### + +testdb1="test_volatile.tdb" +testdb2="test_persistent.tdb" +testdb3="test_replicated.tdb" + +test_node="0" + +echo "Shutting down node $test_node" +stop_ctdb_1 "$test_node" +sleep 1 +wait_until_node_has_status 1 recovered +try_command_on_node -v 1 $CTDB status + +echo "Create test databases" +try_command_on_node 1 $CTDB attach "$testdb1" +try_command_on_node 1 $CTDB attach "$testdb2" persistent +try_command_on_node 1 $CTDB attach "$testdb3" replicated + +echo +echo "Checking if database is attached with correct flags" +for node in $(seq 0 $lastnode) ; do + if [ $node -ne $test_node ] ; then + check_db $node $testdb1 "" + check_db $node $testdb2 PERSISTENT + check_db $node $testdb3 REPLICATED + fi +done + +###################################################################### + +echo +echo "Start node $test_node" +start_ctdb_1 "$test_node" +sleep 1 +wait_until_ready + +echo +echo "Checking if database is attached with correct flags" +check_db $test_node $testdb1 "" +check_db $test_node $testdb2 PERSISTENT +check_db $test_node $testdb3 REPLICATED + +###################################################################### + +echo +echo "Restarting node $test_node" +restart_ctdb_1 "$test_node" +sleep 1 +wait_until_ready + +echo +echo "Checking if database is attached with correct flags" +check_db $test_node $testdb1 "" +check_db $test_node $testdb2 PERSISTENT +check_db $test_node $testdb3 REPLICATED |