ctdb-tests: Update integration tests to use ctdb -X
[Samba.git] / ctdb / tests / simple / 27_ctdb_detach.sh
blob4b7b3b5f22fdc43402bbd3776243235c6b00cc07
1 #!/bin/bash
3 test_info()
5 cat <<EOF
6 Verify the operation of 'ctdb detach' 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. Attach test databases
16 3. Detach test databases
17 4. Verify that the databases are not attached.
19 Expected results:
21 * Command 'ctdb detach' command successfully removes attached databases.
22 EOF
25 . "${TEST_SCRIPTS_DIR}/integration.bash"
27 ctdb_test_init "$@"
29 set -e
31 cluster_is_healthy
33 # Reset configuration
34 ctdb_restart_when_done
36 ######################################################################
38 try_command_on_node 0 "$CTDB listnodes -X"
39 listnodes_output="$out"
40 numnodes=$(wc -l <<<"$listnodes_output")
42 ######################################################################
44 # Confirm that the database is attached
45 check_db ()
47 db="$1"
48 try_command_on_node all $CTDB getdbmap
49 local num_db=$(grep -cF "$db" <<<"$out") || true
50 if [ $num_db -eq $numnodes ]; then
51 echo "GOOD: database $db is attached on all nodes"
52 else
53 echo "BAD: database $db is not attached on all nodes"
54 echo "$out"
55 exit 1
59 # Confirm that no nodes have databases attached
60 check_no_db ()
62 db="$1"
63 try_command_on_node all $CTDB getdbmap
64 local num_db=$(grep -cF "$db" <<<"$out") || true
65 if [ $num_db -eq 0 ]; then
66 echo "GOOD: database $db is not attached any more"
67 else
68 echo "BAD: database $db is still attached"
69 echo "$out"
70 exit 1
74 ######################################################################
76 testdb1="detach_test1.tdb"
77 testdb2="detach_test2.tdb"
78 testdb3="detach_test3.tdb"
79 testdb4="detach_test4.tdb"
81 echo "Create test databases"
82 for db in "$testdb1" "$testdb2" "$testdb3" "$testdb4" ; do
83 echo " $db"
84 try_command_on_node 0 $CTDB attach "$db"
85 done
87 for db in "$testdb1" "$testdb2" "$testdb3" "$testdb4" ; do
88 check_db "$db"
89 done
91 ######################################################################
93 echo
94 echo "Ensuring AllowClientDBAttach=1 on all nodes"
95 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
97 echo "Check failure detaching single test database $testdb1"
98 try_command_on_node 1 "! $CTDB detach $testdb1"
99 check_db "$testdb1"
101 echo
102 echo "Setting AllowClientDBAttach=0 on node 0"
103 try_command_on_node 0 $CTDB setvar AllowClientDBAttach 0
105 echo "Check failure detaching single test database $testdb1"
106 try_command_on_node 1 "! $CTDB detach $testdb1"
107 check_db "$testdb1"
109 echo
110 echo "Setting AllowClientDBAttach=0 on all nodes"
111 try_command_on_node all $CTDB setvar AllowClientDBAttach 0
113 echo "Check detaching single test database $testdb1"
114 try_command_on_node 1 "$CTDB detach $testdb1"
115 check_no_db "$testdb1"
117 ######################################################################
119 echo
120 echo "Detach multiple test databases"
121 echo " $testdb2, $testdb3, $testdb4"
122 try_command_on_node 0 $CTDB detach $testdb2 $testdb3 $testdb4
124 for db in "$testdb2" "$testdb3" "$testdb4" ; do
125 check_no_db "$db"
126 done
128 ######################################################################
130 echo
131 echo "Attach a single test database"
132 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
133 try_command_on_node 0 $CTDB attach $testdb1
134 check_db "$testdb1"
136 echo
137 echo "Write a key to database"
138 try_command_on_node 0 $CTDB writekey $testdb1 foo bar
139 try_command_on_node 0 $CTDB catdb $testdb1
140 num_keys=$(echo "$out" | sed -n -e 's/Dumped \([0-9]*\) records/\1/p') || true
141 if [ -n "$num_keys" -a $num_keys -eq 1 ]; then
142 echo "GOOD: Key added to database"
143 else
144 echo "BAD: Key did not get added to database"
145 echo "$out"
146 exit 1
149 echo
150 echo "Detach test database"
151 try_command_on_node all $CTDB setvar AllowClientDBAttach 0
152 try_command_on_node 0 $CTDB detach $testdb1
153 check_no_db "$testdb1"
155 echo
156 echo "Re-attach test database"
157 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
158 try_command_on_node 0 $CTDB attach $testdb1
159 check_db "$testdb1"