Test suite: New tests for validating SKIP_SHARE_CHECK options.
[tridge/ctdb.git] / tests / complex / 01_ctdb_nfs_skip_share_check.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that the CTDB_NFS_SKIP_SHARE_CHECK configuration option is respected.
7
8 We create a file in /etc/ctdb/rc.local.d/ that creates a function
9 called exportfs.  This effectively hooks the exportfs command,
10 allowing us to provide a fake list of shares to check or not check.
11
12 We create another file in the same directory to set and unset the
13 CTDB_NFS_SKIP_SHARE_CHECK option, utilising the shell's "readonly"
14 built-in to ensure that our value for the option is used.
15
16 Prerequisites:
17
18 * An active CTDB cluster with at least 2 nodes with public addresses.
19
20 * Test must be run on a real or virtual cluster rather than against
21   local daemons.  There is nothing intrinsic to this test that forces
22   this - it is because tests run against local daemons don't use the
23   regular eventscripts.
24
25 Steps:
26
27 1.  Verify that the cluster is healthy.
28 2.  Determine the CTDB MonitorInterval setting and remember it.
29 3.  Create a temporary directory using mktemp, remember the name in
30     $mydir.
31 4.  Create an executable file /etc/ctdb/rc.local.d/fake-exportfs that
32     contains a definiton for the function exportfs, which prints a
33     share definition for a directory $mydir/foo (which does not
34     currently exist).
35 5.  Create an executable file
36     /etc/ctdb/rc.local.d/nfs-skip-share-check that replaces the
37     loadconfig() function by one with equivalent functionality, but
38     which also sets CTDB_NFS_SKIP_SHARE_CHECK="no" if loading
39     "ctdb" configuration.
40 6.  Wait for a maximum of MonitorInterval seconds for the node to
41     become unhealthy.
42 7.  Create the directory $mydir/foo.
43 8.  Wait for a maximum of MonitorInterval seconds for the node to
44     become healthy.
45 9.  Modify /etc/ctdb/rc.local.d/nfs-skip-share-check so that it sets
46     CTDB_NFS_SKIP_SHARE_CHECK to "yes".
47 10. Remove the directory $mydir/foo.
48 11. Wait for MonitorInterval and confirm that the the node is still
49     healthy.
50
51 Expected results:
52
53 * When an NFS share directory is missing CTDB should only mark a node
54   as unhealthy if CTDB_NFS_SKIP_SHARE_CHECK is set to "no".
55 EOF
56 }
57
58 . ctdb_test_functions.bash
59
60 set -e
61
62 ctdb_test_init "$@"
63
64 ctdb_test_check_real_cluster
65
66 cluster_is_healthy
67
68 select_test_node_and_ips
69
70 # We need this for later, so we know how long to sleep.
71 try_command_on_node $test_node $CTDB getvar MonitorInterval
72 monitor_interval="${out#*= }"
73
74 mydir=$(onnode -q $test_node mktemp -d)
75 rc_local_d="${CTDB_BASE:-/etc/ctdb}/rc.local.d"
76 mkdir -p "$rc_local_d"
77
78 my_exit_hook ()
79 {
80     onnode -q $test_node "rm -f $mydir/*"
81     onnode -q $test_node "rmdir --ignore-fail-on-non-empty $mydir"
82     onnode -q $test_node "rm -f \"$rc_local_d/\"*"
83     onnode -q $test_node "rmdir --ignore-fail-on-non-empty \"$rc_local_d\""
84 }
85
86 ctdb_test_exit_hook_add my_exit_hook
87
88 foo_dir=$mydir/foo
89
90 try_command_on_node -v $test_node "mkdir -p \"$rc_local_d\""
91
92 f="$rc_local_d/fake-exportfs"
93 echo "Installing \"$f\"..."
94 try_command_on_node $test_node "echo \"function exportfs () { echo $foo_dir 127.0.0.1/32 ; }\" >\"$f\" ; chmod +x \"$f\""
95
96 n="$rc_local_d/nfs-skip-share-check"
97 n_contents='loadconfig() {
98     name="$1"
99     if [ -f /etc/sysconfig/$name ]; then
100         . /etc/sysconfig/$name
101     elif [ -f /etc/default/$name ]; then
102         . /etc/default/$name
103     elif [ -f $CTDB_BASE/sysconfig/$name ]; then
104         . $CTDB_BASE/sysconfig/$name
105     fi
106     if [ "$name" = "ctdb" ] ; then
107         CTDB_NFS_SKIP_SHARE_CHECK=no
108     fi
109 }
110 '
111 echo "Installing \"$n\" with CTDB_NSF_SKIP_SHARE_CHECK=no..."
112 try_command_on_node $test_node "echo '$n_contents' >\"$n\" ; chmod +x \"$n\""
113
114 wait_until_node_has_status $test_node unhealthy $monitor_interval
115
116 try_command_on_node -v $test_node "mkdir $foo_dir"
117
118 wait_until_node_has_status $test_node healthy $monitor_interval
119
120 echo "Re-installing \"$n\" with CTDB_NFS_SKIP_SHARE_CHECK=yes..."
121 try_command_on_node $test_node "echo '${n_contents/=no/=yes}' >\"$n\" ; chmod +x \"$n\""
122
123 try_command_on_node -v $test_node "rmdir $foo_dir"
124
125 echo "Waiting for MonitorInterval to ensure that node $test_node stays healthy..."
126 sleep_for $monitor_interval
127
128 wait_until_node_has_status $test_node healthy 1