summaryrefslogtreecommitdiff
path: root/ctdb/tests/INTEGRATION/database/basics.002.attach.sh
blob: b9ae9481d91bcbea1b0ac497504518102ad6267b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash

test_info()
{
    cat <<EOF
Verify the operation of 'ctdb attach' command.

Prerequisites:

* An active CTDB cluster with at least 2 active nodes.

Steps:

1. Verify that the status on all of the ctdb nodes is 'OK'.
2. Shut down one of the nodes
3. Attach test databases
4. Start shutdown node
5. Verify that the databases are attached.
6. Restart one of the nodes
7. Verify that the databses are attached.


Expected results:

* Command 'ctdb attach' command successfully attaches databases.
EOF
}

. "${TEST_SCRIPTS_DIR}/integration.bash"

ctdb_test_init

set -e

cluster_is_healthy

######################################################################

try_command_on_node 0 "$CTDB listnodes -X | wc -l"
numnodes="$out"
lastnode=$(( numnodes - 1 ))

######################################################################

# Confirm that the database is attached with appropriate flags
check_db_once ()
{
	local pnn="$1"
	local db="$2"

	try_command_on_node "$pnn" $CTDB getdbmap
	if grep -qF "name:${db}" "$outfile" >/dev/null ; then
		return 0
	else
		return 1
	fi
}

check_db ()
{
	local pnn="$1"
	local db="$2"
	local flag="$3"

	local flags

	echo "Waiting until database ${db} is attached on node ${pnn}"
	wait_until 10 check_db_once "$pnn" "$db"

	flags=$(awk -v db="$db" '$2 == "name:" db {print $4}' "$outfile")
	if [ "$flags" = "$flag" ]; then
		echo "GOOD: db ${db} attached on node ${pnn} with flag $flag"
	else
		echo "BAD: db ${db} attached on node ${pnn} with wrong flag"
		cat "$outfile"
		exit 1
	fi
}

######################################################################

testdb1="test_volatile.tdb"
testdb2="test_persistent.tdb"
testdb3="test_replicated.tdb"

test_node="0"

echo "Shutting down node $test_node"
stop_ctdb_1 "$test_node"
sleep 1
wait_until_node_has_status 1 recovered
try_command_on_node -v 1 $CTDB status

echo "Create test databases"
try_command_on_node 1 $CTDB attach "$testdb1"
try_command_on_node 1 $CTDB attach "$testdb2" persistent
try_command_on_node 1 $CTDB attach "$testdb3" replicated

echo
echo "Checking if database is attached with correct flags"
for node in $(seq 0 $lastnode) ; do
    if [ $node -ne $test_node ] ; then
	check_db $node $testdb1 ""
	check_db $node $testdb2 PERSISTENT
	check_db $node $testdb3 REPLICATED
    fi
done

######################################################################

echo
echo "Start node $test_node"
start_ctdb_1 "$test_node"
sleep 1
wait_until_ready

echo
echo "Checking if database is attached with correct flags"
check_db $test_node $testdb1 ""
check_db $test_node $testdb2 PERSISTENT
check_db $test_node $testdb3 REPLICATED

######################################################################

echo
echo "Restarting node $test_node"
restart_ctdb_1 "$test_node"
sleep 1
wait_until_ready

echo
echo "Checking if database is attached with correct flags"
check_db $test_node $testdb1 ""
check_db $test_node $testdb2 PERSISTENT
check_db $test_node $testdb3 REPLICATED