Delete some unstructured tests ({fetch,peristent,transaction}.sh) and
[metze/ctdb/wip.git] / tests / simple / 24_ctdb_getdbmap.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that  'ctdb getdbmap' operates as expected.
7
8 This test creates some test databases using 'ctdb attach'.
9
10 Prerequisites:
11
12 * An active CTDB cluster with at least 2 active nodes.
13
14 Steps:
15
16 1. Verify that the status on all of the ctdb nodes is 'OK'.
17 2. Get the database on using 'ctdb getdbmap'.
18 3. Verify that the output is valid.
19
20 Expected results:
21
22 * 'ctdb getdbmap' shows a valid listing of databases.
23 EOF
24 }
25
26 . ctdb_test_functions.bash
27
28 ctdb_test_init "$@"
29
30 set -e
31
32 onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy
33
34 # Restart when done since things are likely to be broken.
35 ctdb_test_exit_hook="restart_ctdb"
36
37 make_temp_db_filename ()
38 {
39     dd if=/dev/urandom count=1 bs=512 2>/dev/null |
40     md5sum |
41     awk '{printf "%s.tdb\n", $1}'
42 }
43
44 try_command_on_node -v 0 "$CTDB getdbmap"
45
46 db_map_pattern='^(Number of databases:[[:digit:]]+|dbid:0x[[:xdigit:]]+ name:[^[:space:]]+ path:[^[:space:]]+)$'
47
48 sanity_check_output $(($num_db_init + 1)) "$dbmap_pattern" "$out"
49
50 num_db_init=$(echo "$out" | sed -n -e '1s/.*://p')
51
52 for i in $(seq 1 5) ; do
53     f=$(make_temp_db_filename)
54     echo "Creating test database: $f"
55     try_command_on_node 0 $CTDB attach "$f"
56     try_command_on_node 0 $CTDB getdbmap
57     sanity_check_output $(($num_db_init + 1)) "$dbmap_pattern" "$out"
58     num=$(echo "$out" | sed -n -e '1s/^.*://p')
59     if [ $num = $(($num_db_init + $i)) ] ; then
60         echo "OK: correct number of additional databases"
61     else
62         echo "BAD: no additional database"
63         exit 1
64     fi
65     if [ "${out/name:${f} /}" != "$out" ] ; then
66         echo "OK: getdbmap knows about \"$f\""
67     else
68         echo "BAD: getdbmap does not know about \"$f\""
69         exit 1
70     fi
71 done
72
73 echo "OK, that worked... expect a restart..."
74
75 ctdb_test_exit