3 # Verify that 'ctdb detach' works as expected:
4 # 1. Attach test databases
5 # 2. Detach test databases
6 # 3. Confirm test databases are not attached
8 . "${TEST_SCRIPTS_DIR}/integration.bash"
14 ######################################################################
16 try_command_on_node 0 "$CTDB listnodes -X | wc -l"
19 ######################################################################
21 # Confirm that the database is attached
28 try_command_on_node all "$CTDB getdbmap"
29 num_db=$(grep -cF "name:${db}" "$outfile") || true
30 if [ "$num_db" -eq "$numnodes" ]; then
41 echo "Waiting until database ${db} is attached on all nodes"
42 wait_until 10 check_db_once "$db"
45 # Confirm that no nodes have databases attached
52 try_command_on_node all "$CTDB getdbmap"
53 num_db=$(grep -cF "name:${db}" "$outfile") || true
54 if [ "$num_db" -eq 0 ]; then
65 echo "Waiting until database ${db} is detached on all nodes"
66 wait_until 10 check_no_db_once "$db"
69 ######################################################################
71 testdb1="detach_test1.tdb"
72 testdb2="detach_test2.tdb"
73 testdb3="detach_test3.tdb"
74 testdb4="detach_test4.tdb"
76 echo "Create test databases"
77 for db in "$testdb1" "$testdb2" "$testdb3" "$testdb4" ; do
79 try_command_on_node 0 $CTDB attach "$db"
82 for db in "$testdb1" "$testdb2" "$testdb3" "$testdb4" ; do
86 ######################################################################
89 echo "Ensuring AllowClientDBAttach=1 on all nodes"
90 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
92 echo "Check failure detaching single test database $testdb1"
93 try_command_on_node 1 "! $CTDB detach $testdb1"
97 echo "Setting AllowClientDBAttach=0 on node 0"
98 try_command_on_node 0 $CTDB setvar AllowClientDBAttach 0
100 echo "Check failure detaching single test database $testdb1"
101 try_command_on_node 1 "! $CTDB detach $testdb1"
105 echo "Setting AllowClientDBAttach=0 on all nodes"
106 try_command_on_node all $CTDB setvar AllowClientDBAttach 0
108 echo "Check detaching single test database $testdb1"
109 try_command_on_node 1 "$CTDB detach $testdb1"
110 check_no_db "$testdb1"
112 ######################################################################
115 echo "Detach multiple test databases"
116 echo " $testdb2, $testdb3, $testdb4"
117 try_command_on_node 0 $CTDB detach $testdb2 $testdb3 $testdb4
119 for db in "$testdb2" "$testdb3" "$testdb4" ; do
123 ######################################################################
126 echo "Attach a single test database"
127 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
128 try_command_on_node 0 $CTDB attach $testdb1
132 echo "Write a key to database"
133 try_command_on_node 0 $CTDB writekey $testdb1 foo bar
134 try_command_on_node 0 $CTDB catdb $testdb1
135 num_keys=$(sed -n -e 's/Dumped \([0-9]*\) records/\1/p' "$outfile") || true
136 if [ -n "$num_keys" -a $num_keys -eq 1 ]; then
137 echo "GOOD: Key added to database"
139 echo "BAD: Key did not get added to database"
145 echo "Detach test database"
146 try_command_on_node all $CTDB setvar AllowClientDBAttach 0
147 try_command_on_node 0 $CTDB detach $testdb1
148 check_no_db "$testdb1"
151 echo "Re-attach test database"
152 try_command_on_node all $CTDB setvar AllowClientDBAttach 1
153 try_command_on_node 0 $CTDB attach $testdb1
157 echo "Check if the database is empty"
158 try_command_on_node 0 $CTDB catdb $testdb1
159 num_keys=$(sed -n -e 's/Dumped \([0-9]*\) records/\1/p' "$outfile") || true
160 if [ -n "$num_keys" -a $num_keys -eq 0 ]; then
161 echo "GOOD: Database $testdb1 is empty"
163 echo "BAD: Database $testdb1 is not empty"