7 export FAKE_RPCINFO_SERVICES=""
9 export CTDB_NFS_SKIP_SHARE_CHECK="no"
13 # This doesn't even need to exist
14 export CTDB_NFS_EXPORTS_FILE="$EVENTSCRIPTS_TESTS_VAR_DIR/etc-exports"
16 # Reset the failcounts for nfs services.
17 eventscript_call eval rm -f '$ctdb_fail_dir/nfs_*'
19 if [ "$1" != "down" ] ; then
20 debug "Setting up NFS environment: all RPC services up, NFS managed by CTDB"
22 service "nfs" force-started
23 service "nfslock" force-started
25 export CTDB_MANAGES_NFS="yes"
28 "portmapper" "nfs" "mountd" "rquotad" "nlockmgr" "status"
30 nfs_setup_fake_threads "nfsd"
31 nfs_setup_fake_threads "rpc.foobar" # Just set the variable to empty
33 debug "Setting up NFS environment: all RPC services down, NFS not managed by CTDB"
35 service "nfs" force-stopped
36 service "nfslock" force-stopped
38 export CTDB_MANAGES_NFS=""
41 # This is really nasty. However, when we test NFS we don't
42 # actually test statd-callout. If we leave it there then left
43 # over, backgrounded instances of statd-callout will do
44 # horrible things with the "ctdb ip" stub and cause the actual
45 # statd-callout tests that follow to fail.
46 rm "${CTDB_BASE}/statd-callout"
52 debug "Marking RPC service \"${_i}\" as unavailable"
53 FAKE_RPCINFO_SERVICES=$(echo "$FAKE_RPCINFO_SERVICES" | sed -r -e "s@[[:space:]]*${_i}:[0-9]+:[0-9]+@@g")
60 debug "Marking RPC service \"${_i}\" as available"
62 portmapper) _t="2:4" ;;
68 *) die "Internal error - unsupported RPC service \"${_i}\"" ;;
71 FAKE_RPCINFO_SERVICES="${FAKE_RPCINFO_SERVICES}${FAKE_RPCINFO_SERVICES:+ }${_i}:${_t}"
75 nfs_setup_fake_threads ()
81 export PROCFS_PATH=$(mktemp -d --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
82 _threads="${PROCFS_PATH}/fs/nfsd/threads"
83 mkdir -p $(dirname "$_threads")
85 export FAKE_NFSD_THREAD_PIDS="$*"
88 export FAKE_RPC_THREAD_PIDS="$*"
93 program_stack_traces ()
99 for _pid in ${FAKE_NFSD_THREAD_PIDS:-$FAKE_RPC_THREAD_PIDS} ; do
100 [ $_count -le $_max ] || break
102 program_stack_trace "$_prog" "$_pid"
103 _count=$(($_count + 1))
110 $CTDB_NFS_CALLOUT\ start\ nlockmgr)
111 echo "&Starting nfslock: OK"
113 $CTDB_NFS_CALLOUT\ start\ nfs)
115 &Starting nfslock: OK
124 # Set the required result for a particular RPC program having failed
125 # for a certain number of iterations. This is probably still a work
126 # in progress. Note that we could hook aggressively
127 # nfs_check_rpc_service() to try to implement this but we're better
128 # off testing nfs_check_rpc_service() using independent code... even
129 # if it is incomplete and hacky. So, if the 60.nfs eventscript
130 # changes and the tests start to fail then it may be due to this
131 # function being incomplete.
132 rpc_set_service_failure_response ()
135 _numfails="${2:-1}" # default 1
139 if [ $_numfails -eq 0 ] ; then
145 # A handy newline. :-)
149 _dir="${CTDB_NFS_CHECKS_DIR:-${CTDB_BASE}/nfs-checks.d}"
151 _file=$(ls "$_dir"/[0-9][0-9]."${_rpc_service}.check")
152 [ -r "$_file" ] || die "RPC check file \"$_file\" does not exist or is not unique"
154 _out=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
155 _rc_file=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
158 # Subshell to restrict scope variables...
170 # Don't bother syntax checking, eventscript does that...
173 # Just use the first version, or use default. This is
174 # dumb but handles all the cases that we care about
176 if [ -n "$version" ] ; then
177 _ver="${version%% *}"
179 case "$_rpc_service" in
180 portmapper) _ver="" ;;
185 $_rpc_service failed RPC check:
186 rpcinfo: RPC: Program not registered
187 program $_rpc_service${_ver:+ version }${_ver} is not available"
189 if [ $unhealthy_after -gt 0 -a $_numfails -ge $unhealthy_after ] ; then
192 echo "ERROR: ${_rpc_check_out}" >>"$_out"
198 if [ $restart_every -gt 0 ] && \
199 [ $(($_numfails % $restart_every)) -eq 0 ] ; then
200 if ! $_unhealthy ; then
201 echo "WARNING: ${_rpc_check_out}" >>"$_out"
204 echo "Trying to restart service \"${_rpc_service}\"..." >>"$_out"
206 if [ -n "$service_debug_cmd" ] ; then
207 $service_debug_cmd 2>&1 >>"$_out"
210 guess_output "$service_start_cmd" >>"$_out"
214 read _rc <"$_rc_file"
215 required_result $_rc <"$_out"
217 rm -f "$_out" "$_rc_file"
220 # Run an NFS eventscript iteratively.
222 # - 1st argument is the number of iterations.
224 # - 2nd argument is the NFS/RPC service being tested
226 # rpcinfo (or $service_check_cmd) is used on each iteration to test
227 # the availability of the service
229 # If this is not set or null then no RPC service is checked and the
230 # required output is not reset on each iteration. This is useful in
231 # baseline tests to confirm that the eventscript and test
232 # infrastructure is working correctly.
234 # - Subsequent arguments come in pairs: an iteration number and
235 # something to eval before that iteration. Each time an iteration
236 # number is matched the associated argument is given to eval after
237 # the default setup is done. The iteration numbers need to be given
238 # in ascending order.
240 # These arguments can allow a service to be started or stopped
241 # before a particular iteration.
247 if [ -n "$2" ] ; then
253 echo "Running $_repeats iterations of \"$script $event\" $args"
256 for _iteration in $(seq 1 $_repeats) ; do
257 # This is not a numerical comparison because $1 will
259 if [ "$_iteration" = "$1" ] ; then
260 debug "##################################################"
262 debug "##################################################"
265 if [ -n "$_rpc_service" ] ; then
267 if [ -n "$service_check_cmd" ] ; then
268 if eval "$service_check_cmd" ; then
272 if rpcinfo -T tcp localhost "$_rpc_service" >/dev/null 2>&1 ; then
280 _iterate_failcount=$(($_iterate_failcount + 1))
282 rpc_set_service_failure_response "$_rpc_service" $_iterate_failcount
284 _out=$(simple_test 2>&1)
286 if "$TEST_VERBOSE" || [ $_ret -ne 0 ] ; then
287 echo "##################################################"
288 echo "Iteration ${_iteration}:"
291 if [ $_ret -ne 0 ] ; then