winbind: Implement forall_children()
[Samba.git] / ctdb / tests / simple / 21_ctdb_attach.sh
blob11b600800a4bb0caff0bf8b57f5408f5d0d82c31
1 #!/bin/bash
3 test_info()
5 cat <<EOF
6 Verify the operation of 'ctdb attach' command.
8 Prerequisites:
10 * An active CTDB cluster with at least 2 active nodes.
12 Steps:
14 1. Verify that the status on all of the ctdb nodes is 'OK'.
15 2. Shut down one of the nodes
16 3. Attach test databases
17 4. Start shutdown node
18 5. Verify that the databases are attached.
19 6. Restart one of the nodes
20 7. Verify that the databses are attached.
23 Expected results:
25 * Command 'ctdb attach' command successfully attaches databases.
26 EOF
29 . "${TEST_SCRIPTS_DIR}/integration.bash"
31 ctdb_test_init "$@"
33 set -e
35 cluster_is_healthy
37 # Reset configuration
38 ctdb_restart_when_done
40 ######################################################################
42 try_command_on_node 0 "$CTDB listnodes -X"
43 listnodes_output="$out"
44 numnodes=$(wc -l <<<"$listnodes_output")
45 lastnode=$(( numnodes - 1 ))
47 ######################################################################
49 # Confirm that the database is attached
50 check_db ()
52 pnn="$1"
53 db="$2"
54 flag="$3"
55 try_command_on_node $pnn "$CTDB getdbmap | grep $db"
56 if [ -z "$out" ] ; then
57 echo "BAD: database $db is not attached on node $node"
58 echo "$out"
59 exit 1
60 else
61 local flags=$(awk '{print $4}' <<<"$out") || true
62 if [ "$flags" = "$flag" ]; then
63 echo "GOOD: database $db is attached on node $node with flag $flag"
64 else
65 echo "BAD: database $db is attached on node $node with wrong flag"
66 echo "$out"
67 exit 1
72 ######################################################################
74 testdb1="test_volatile.tdb"
75 testdb2="test_persistent.tdb"
76 testdb3="test_replicated.tdb"
78 test_node="0"
80 echo "Shutting down node $test_node"
81 stop_ctdb_1 "$test_node"
82 sleep 1
83 wait_until_node_has_status 1 recovered
84 try_command_on_node -v 1 $CTDB status
86 echo "Create test databases"
87 try_command_on_node 1 $CTDB attach "$testdb1"
88 try_command_on_node 1 $CTDB attach "$testdb2" persistent
89 try_command_on_node 1 $CTDB attach "$testdb3" replicated
91 echo
92 echo "Checking if database is attached with correct flags"
93 for node in $(seq 0 $lastnode) ; do
94 if [ $node -ne $test_node ] ; then
95 check_db $node $testdb1 ""
96 check_db $node $testdb2 PERSISTENT
97 check_db $node $testdb3 REPLICATED
99 done
101 ######################################################################
103 echo
104 echo "Start node $test_node"
105 start_ctdb_1 "$test_node"
106 sleep 1
107 wait_until_ready
109 echo
110 echo "Checking if database is attached with correct flags"
111 check_db $test_node $testdb1 ""
112 check_db $test_node $testdb2 PERSISTENT
113 check_db $test_node $testdb3 REPLICATED
115 ######################################################################
117 echo
118 echo "Restarting node $test_node"
119 restart_ctdb_1 "$test_node"
120 sleep 1
121 wait_until_ready
123 echo
124 echo "Checking if database is attached with correct flags"
125 check_db $test_node $testdb1 ""
126 check_db $test_node $testdb2 PERSISTENT
127 check_db $test_node $testdb3 REPLICATED