ctdb-tests: Add a simple test for "ctdb detach"
[vlendec/samba-autobuild/.git] / ctdb / tests / simple / 27_ctdb_detach.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify the operation of 'ctdb detach' command.
7
8 Prerequisites:
9
10 * An active CTDB cluster with at least 2 active nodes.
11
12 Steps:
13
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.
18
19 Expected results:
20
21 * Command 'ctdb detach' command successfully removes attached databases.
22 EOF
23 }
24
25 . "${TEST_SCRIPTS_DIR}/integration.bash"
26
27 ctdb_test_init "$@"
28
29 set -e
30
31 cluster_is_healthy
32
33 # Reset configuration
34 ctdb_restart_when_done
35
36 ######################################################################
37
38 # Confirm that no nodes have databases attached
39 check_no_db ()
40 {
41     db="$1"
42     try_command_on_node all $CTDB getdbmap
43     local num_db=$(grep -c "$db" <<<"$out") || true
44     if [ $num_db -eq 0 ]; then
45         echo "GOOD: database $db is not attached any more"
46     else
47         echo "BAD: database $db is still attached"
48         echo "$out"
49         exit 1
50     fi
51 }
52
53 ######################################################################
54
55 testdb1="detach_test1.tdb"
56 testdb2="detach_test2.tdb"
57 testdb3="detach_test3.tdb"
58 testdb4="detach_test4.tdb"
59
60 echo "Create test databases"
61 echo "    $testdb1"
62 try_command_on_node 0 $CTDB attach $testdb1
63 echo "    $testdb2"
64 try_command_on_node 0 $CTDB attach $testdb2
65 echo "    $testdb3"
66 try_command_on_node 0 $CTDB attach $testdb3
67 echo "    $testdb4"
68 try_command_on_node 0 $CTDB attach $testdb4
69
70 ######################################################################
71
72 echo "Detach single test database $testdb1"
73 try_command_on_node 1 $CTDB detach $testdb1
74
75 check_no_db $testdb1
76
77 ######################################################################
78
79 echo "Detach multiple test databases"
80 echo "    $testdb2, $testdb3, $testdb4"
81 try_command_on_node 0 $CTDB detach $testdb2 $testdb3 $testdb4
82
83 check_no_db $testdb2
84 check_no_db $testdb3
85 check_no_db $testdb4