Revert "ctdb-tests: Update preamble for INTEGRATION tests"
[Samba.git] / ctdb / tests / INTEGRATION / database / basics.003.detach.sh
blob5d1e12328c66190eab2ef7464482bfd4da3ff621
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 ######################################################################
35 try_command_on_node 0 "$CTDB listnodes -X | wc -l"
36 numnodes="$out"
38 ######################################################################
40 # Confirm that the database is attached
41 check_db_once ()
43 local db="$1"
45 local num_db
47 try_command_on_node all "$CTDB getdbmap"
48 num_db=$(grep -cF "name:${db}" "$outfile") || true
49 if [ "$num_db" -eq "$numnodes" ]; then
50 return 0
51 else
52 return 1
56 check_db ()
58 local db="$1"
60 echo "Waiting until database ${db} is attached on all nodes"
61 wait_until 10 check_db_once "$db"
64 # Confirm that no nodes have databases attached
65 check_no_db_once ()
67 local db="$1"
69 local num_db
71 try_command_on_node all "$CTDB getdbmap"
72 num_db=$(grep -cF "name:${db}" "$outfile") || true
73 if [ "$num_db" -eq 0 ]; then
74 return 0
75 else
76 return 1
80 check_no_db ()
82 local db="$1"
84 echo "Waiting until database ${db} is detached on all nodes"
85 wait_until 10 check_no_db_once "$db"
88 ######################################################################
90 testdb1="detach_test1.tdb"
91 testdb2="detach_test2.tdb"
92 testdb3="detach_test3.tdb"
93 testdb4="detach_test4.tdb"
95 echo "Create test databases"
96 for db in "$testdb1" "$testdb2" "$testdb3" "$testdb4" ; do
97 echo " $db"
98 try_command_on_node 0 $CTDB attach "$db"
99 done
101 for db in "$testdb1" "$testdb2" "$testdb3" "$testdb4" ; do
102 check_db "$db"
103 done
105 ######################################################################
107 echo
108 echo "Ensuring AllowClientDBAttach=1 on all nodes"
109 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
111 echo "Check failure detaching single test database $testdb1"
112 try_command_on_node 1 "! $CTDB detach $testdb1"
113 check_db "$testdb1"
115 echo
116 echo "Setting AllowClientDBAttach=0 on node 0"
117 try_command_on_node 0 $CTDB setvar AllowClientDBAttach 0
119 echo "Check failure detaching single test database $testdb1"
120 try_command_on_node 1 "! $CTDB detach $testdb1"
121 check_db "$testdb1"
123 echo
124 echo "Setting AllowClientDBAttach=0 on all nodes"
125 try_command_on_node all $CTDB setvar AllowClientDBAttach 0
127 echo "Check detaching single test database $testdb1"
128 try_command_on_node 1 "$CTDB detach $testdb1"
129 check_no_db "$testdb1"
131 ######################################################################
133 echo
134 echo "Detach multiple test databases"
135 echo " $testdb2, $testdb3, $testdb4"
136 try_command_on_node 0 $CTDB detach $testdb2 $testdb3 $testdb4
138 for db in "$testdb2" "$testdb3" "$testdb4" ; do
139 check_no_db "$db"
140 done
142 ######################################################################
144 echo
145 echo "Attach a single test database"
146 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
147 try_command_on_node 0 $CTDB attach $testdb1
148 check_db "$testdb1"
150 echo
151 echo "Write a key to database"
152 try_command_on_node 0 $CTDB writekey $testdb1 foo bar
153 try_command_on_node 0 $CTDB catdb $testdb1
154 num_keys=$(sed -n -e 's/Dumped \([0-9]*\) records/\1/p' "$outfile") || true
155 if [ -n "$num_keys" -a $num_keys -eq 1 ]; then
156 echo "GOOD: Key added to database"
157 else
158 echo "BAD: Key did not get added to database"
159 cat "$outfile"
160 exit 1
163 echo
164 echo "Detach test database"
165 try_command_on_node all $CTDB setvar AllowClientDBAttach 0
166 try_command_on_node 0 $CTDB detach $testdb1
167 check_no_db "$testdb1"
169 echo
170 echo "Re-attach test database"
171 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
172 try_command_on_node 0 $CTDB attach $testdb1
173 check_db "$testdb1"
175 echo
176 echo "Check if the database is empty"
177 try_command_on_node 0 $CTDB catdb $testdb1
178 num_keys=$(sed -n -e 's/Dumped \([0-9]*\) records/\1/p' "$outfile") || true
179 if [ -n "$num_keys" -a $num_keys -eq 0 ]; then
180 echo "GOOD: Database $testdb1 is empty"
181 else
182 echo "BAD: Database $testdb1 is not empty"
183 cat "$outfile"
184 exit 1