ctdb-tests: Check that ctdb wipedb cleans the database
[Samba.git] / ctdb / tests / simple / 71_ctdb_wipedb.sh
blob1919ea70a961b2f157249f7154b725a35960a31c
1 #!/bin/bash
3 test_info()
5 cat <<EOF
6 The command 'ctdb wipedb' is used to clear a database across the whole
7 cluster.
9 Prerequisites:
11 * An active CTDB cluster with at least 2 active nodes.
13 Steps:
15 1. Verify that the status on all of the ctdb nodes is 'OK'.
16 2. Create a persistent test database
17 3. Add some records to node #0 and node #1
18 4. Perform wipedb on node #0 and verify the database is empty on both node 0 and 1
20 Expected results:
22 * An empty database will result
24 EOF
27 . "${TEST_SCRIPTS_DIR}/integration.bash"
29 ctdb_test_init "$@"
31 set -e
33 cluster_is_healthy
35 try_command_on_node 0 "$CTDB listnodes"
36 num_nodes=$(echo "$out" | wc -l)
38 # 2.
39 test_db="persistent_test.tdb"
40 echo "Create persistent test database \"$test_db\""
41 try_command_on_node 0 $CTDB attach "$test_db" persistent
43 # 3.
44 # add one record to node 0 key==ABC data==ABC
45 echo "Store key(ABC) data(ABC) on node 0"
46 db_ctdb_tstore 0 "$test_db" "ABC" "ABC"
48 # add one record to node 1 key==DEF data==DEF
49 echo "Store key(DEF) data(DEF) on node 1"
50 db_ctdb_tstore 1 "$test_db" "DEF" "DEF"
52 # 4.
53 echo "Wipe database"
54 try_command_on_node 0 $CTDB wipedb "$test_db"
56 # check that the database is wiped
57 num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
58 if [ $num_records = "0" ] ; then
59 echo "OK: Database was wiped"
60 else
61 echo "BAD: We did not end up with an empty database"
62 exit 1
65 echo "Force a recovery"
66 try_command_on_node 0 $CTDB recover
68 # check that the database is wiped
69 num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
70 if [ $num_records = "0" ] ; then
71 echo "OK: Database was wiped"
72 else
73 echo "BAD: We did not end up with an empty database"
74 exit 1