eventscripts: Rewrite the smb.conf cache file handling
[ctdb.git] / tests / complex / 02_ctdb_samba_skip_share_check.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that the CTDB_SAMBA_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 testparm.  This effectively hooks the testparm 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_SAMBA_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 using mktemp, remember the name in
31     $mydir.
32 4.  Create an executable file /etc/ctdb/rc.local.d/fake-testparm that
33     contains a definiton for the function testparm, which prints a
34     share definition for a directory $mydir/foo (which does not
35     currently exist).
36 5.  Create an executable file
37     /etc/ctdb/rc.local.d/samba-skip-share-check that replaces the
38     loadconfig() function by one with equivalent functionality, but
39     which also sets CTDB_SAMBA_SKIP_SHARE_CHECK="no" if loading
40     "ctdb" configuration.
41 6.  Wait for a maximum of MonitorInterval seconds for the node to
42     become unhealthy.
43 7.  Create the directory $mydir/foo.
44 8.  Wait for a maximum of MonitorInterval seconds for the node to
45     become healthy.
46 9.  Modify /etc/ctdb/rc.local.d/samba-skip-share-check so that it sets
47     CTDB_SAMBA_SKIP_SHARE_CHECK="yes".
48 10. Remove the directory $mydir/foo.
49 11. Wait for  a monitor event and confirm that the the node is still
50     healthy.
51
52 Expected results:
53
54 * When an SAMBA share directory is missing CTDB should only mark a node
55   as unhealthy if CTDB_SAMBA_SKIP_SHARE_CHECK is set to "no".
56 EOF
57 }
58
59 . "${TEST_SCRIPTS_DIR}/integration.bash"
60
61 set -e
62
63 ctdb_test_init "$@"
64
65 ctdb_test_check_real_cluster
66
67 cluster_is_healthy
68
69 select_test_node_and_ips
70
71 # We need this for later, so we know how long to sleep.
72 # We need this for later, so we know how long to sleep.
73 try_command_on_node $test_node $CTDB getvar MonitorInterval
74 monitor_interval=${out#*= }
75 try_command_on_node $test_node $CTDB getvar EventScriptTimeout
76 event_script_timeout=${out#*= }
77
78 monitor_timeout=$(($monitor_interval + $event_script_timeout))
79
80 echo "Using timeout of ${monitor_timeout}s (MonitorInterval + EventScriptTimeout)..."
81
82 mydir=$(onnode -q $test_node mktemp -d)
83 rc_local_d="${CTDB_BASE:-/etc/ctdb}/rc.local.d"
84
85 my_exit_hook ()
86 {
87     ctdb_test_eventscript_uninstall
88     onnode -q $test_node "rm -f $mydir/*"
89     onnode -q $test_node "rmdir --ignore-fail-on-non-empty $mydir"
90     onnode -q $test_node "rm -f \"$rc_local_d/\"*"
91     onnode -q $test_node "rmdir --ignore-fail-on-non-empty \"$rc_local_d\""
92 }
93
94 ctdb_test_exit_hook_add my_exit_hook
95
96 ctdb_test_eventscript_install
97
98 foo_dir=$mydir/foo
99
100 try_command_on_node -v $test_node "mkdir -p \"$rc_local_d\""
101
102 f="$rc_local_d/fake-testparm"
103 echo "Installing \"$f\"..."
104 # Yes, the quoting is very tricky.  We want $foo_dir and $f expanded when
105 # we echo the function definition but we don't want any of the other
106 # items expanded until the function is run.
107 try_command_on_node $test_node "echo 'function testparm () { tp=\$(which testparm 2>/dev/null) ; if [ -n \"\$2\" ] ; then echo path = '\"$foo_dir\"' ; else \$tp \"\$@\" ; fi ; }' >\"$f\" ; chmod +x \"$f\""
108
109 n="$rc_local_d/samba-skip-share-check"
110 n_contents='loadconfig() {
111     _loadconfig "$@"
112
113     if [ "$1" = "ctdb" ] ; then
114         CTDB_SAMBA_SKIP_SHARE_CHECK=no
115     fi
116 }
117 '
118 echo "Installing \"$n\" with CTDB_SAMBA_SKIP_SHARE_CHECK=no..."
119 try_command_on_node $test_node "echo '$n_contents' >\"$n\" ; chmod +x \"$n\""
120
121 wait_until_node_has_status $test_node unhealthy $monitor_timeout
122
123 try_command_on_node -v $test_node "mkdir $foo_dir"
124
125 wait_until_node_has_status $test_node healthy $monitor_timeout
126
127 echo "Re-installing \"$n\" with CTDB_SAMBA_SKIP_SHARE_CHECK=yes..."
128 try_command_on_node $test_node "echo '${n_contents/=no/=yes}' >\"$n\" ; chmod +x \"$n\""
129
130 try_command_on_node -v $test_node "rmdir $foo_dir"
131
132 wait_for_monitor_event $test_node
133
134 wait_until_node_has_status $test_node healthy 1