ctdb-tests: Update "ctdb detach" test
[Samba.git] / ctdb / tests / simple / 27_ctdb_detach.sh
blobf86d10af60bd673056fd2cbfa7291a92c6001c3f
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 -Y"
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