ctdb-tests: Avoid bulk output in $out, prefer $outfile
[gd/samba-autobuild/.git] / ctdb / 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 . "${TEST_SCRIPTS_DIR}/integration.bash"
27
28 ctdb_test_init
29
30 set -e
31
32 cluster_is_healthy
33
34 make_temp_db_filename ()
35 {
36     dd if=/dev/urandom count=1 bs=512 2>/dev/null |
37     md5sum |
38     awk '{printf "%s.tdb\n", $1}'
39 }
40
41 try_command_on_node -v 0 "$CTDB getdbmap"
42
43 db_map_pattern='^(Number of databases:[[:digit:]]+|dbid:0x[[:xdigit:]]+ name:[^[:space:]]+ path:[^[:space:]]+)$'
44
45 sanity_check_output $(($num_db_init + 1)) "$dbmap_pattern"
46
47 num_db_init=$(sed -n -e '1s/.*://p' "$outfile")
48
49 for i in $(seq 1 5) ; do
50     f=$(make_temp_db_filename)
51     echo "Creating test database: $f"
52     try_command_on_node 0 $CTDB attach "$f"
53     try_command_on_node 0 $CTDB getdbmap
54     sanity_check_output $(($num_db_init + 1)) "$dbmap_pattern"
55     num=$(sed -n -e '1s/^.*://p' "$outfile")
56     if [ $num = $(($num_db_init + $i)) ] ; then
57         echo "OK: correct number of additional databases"
58     else
59         echo "BAD: no additional database"
60         exit 1
61     fi
62     if awk '{print $2}' "$outfile" | grep -Fqx "name:$f" ; then
63         echo "OK: getdbmap knows about \"$f\""
64     else
65         echo "BAD: getdbmap does not know about \"$f\""
66         exit 1
67     fi
68 done