a7ad938fec4ec4612d79cbd351a60948d48098ce
[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 a timeout for state changes by adding MonitorInterval
29     and EventScriptTimeout.
30 3.  Create a temporary directory on the test node using mktemp,
31     remember the name in $mydir.
32 4.  On the test node create an executable file
33     /etc/ctdb/rc.local.d/fake-exportfs that contains a definiton for
34     the function exportfs, which prints a share definition for a
35     directory $mydir/foo (which does not currently exist).
36 5.  On the test node create an executable file
37     /etc/ctdb/rc.local.d/nfs-skip-share-check that replaces the
38     loadconfig() function by one with equivalent functionality, but
39     which also sets CTDB_NFS_SKIP_SHARE_CHECK="no" if loading
40     "ctdb" configuration.
41 6.  Wait for the test node to become unhealthy.
42 7.  Create the directory $mydir/foo.
43 8.  Wait for the test node to become healthy.
44 9.  Modify /etc/ctdb/rc.local.d/nfs-skip-share-check so that it sets
45     CTDB_NFS_SKIP_SHARE_CHECK to "yes".
46 10. Remove the directory $mydir/foo.
47 11. Wait for  a monitor event and confirm that the the node is still
48     healthy.
49
50 Expected results:
51
52 * When an NFS share directory is missing CTDB should only mark a node
53   as unhealthy if CTDB_NFS_SKIP_SHARE_CHECK is set to "no".
54 EOF
55 }
56
57 . "${TEST_SCRIPTS_DIR}/integration.bash"
58
59 set -e
60
61 ctdb_test_init "$@"
62
63 ctdb_test_check_real_cluster
64
65 cluster_is_healthy
66
67 select_test_node_and_ips
68
69 # We need this for later, so we know how long to sleep.
70 try_command_on_node $test_node $CTDB getvar MonitorInterval
71 monitor_interval=${out#*= }
72 try_command_on_node $test_node $CTDB getvar EventScriptTimeout
73 event_script_timeout=${out#*= }
74
75 monitor_timeout=$(($monitor_interval + $event_script_timeout))
76
77 echo "Using timeout of ${monitor_timeout}s (MonitorInterval + EventScriptTimeout)..."
78
79
80 mydir=$(onnode -q $test_node mktemp -d)
81 rc_local_d="${CTDB_BASE:-/etc/ctdb}/rc.local.d"
82
83 my_exit_hook ()
84 {
85     ctdb_test_eventscript_uninstall
86     onnode -q $test_node "rm -f $mydir/*"
87     onnode -q $test_node "rmdir --ignore-fail-on-non-empty $mydir"
88     onnode -q $test_node "rm -f \"$rc_local_d/\"*"
89     onnode -q $test_node "rmdir --ignore-fail-on-non-empty \"$rc_local_d\""
90 }
91
92 ctdb_test_exit_hook_add my_exit_hook
93
94 ctdb_test_eventscript_install
95
96 foo_dir=$mydir/foo
97
98 try_command_on_node -v $test_node "mkdir -p \"$rc_local_d\""
99
100 f="$rc_local_d/fake-exportfs"
101 echo "Installing \"$f\"..."
102 try_command_on_node $test_node "echo \"function exportfs () { echo \\\"$foo_dir 127.0.0.1/32(rw)\\\" ; }\" >\"$f\" ; chmod +x \"$f\""
103
104 n="$rc_local_d/nfs-skip-share-check"
105 n_contents='loadconfig() {
106     _loadconfig "$@"
107
108     if [ "$1" = "ctdb" -o "$1" = "nfs" ] ; then
109         CTDB_NFS_SKIP_SHARE_CHECK=no
110     fi
111 }
112 '
113 echo "Installing \"$n\" with CTDB_NSF_SKIP_SHARE_CHECK=no..."
114 try_command_on_node $test_node "echo '$n_contents' >\"$n\" ; chmod +x \"$n\""
115
116 wait_until_node_has_status $test_node unhealthy $monitor_timeout
117
118 try_command_on_node -v $test_node "mkdir $foo_dir"
119
120 wait_until_node_has_status $test_node healthy $monitor_timeout
121
122 echo "Re-installing \"$n\" with CTDB_NFS_SKIP_SHARE_CHECK=yes..."
123 try_command_on_node $test_node "echo '${n_contents/=no/=yes}' >\"$n\" ; chmod +x \"$n\""
124
125 try_command_on_node -v $test_node "rmdir $foo_dir"
126
127 wait_for_monitor_event $test_node
128
129 wait_until_node_has_status $test_node healthy 1