6 # shellcheck disable=SC2034
7 # Used in expected output
10 if [ -z "$CTDB_NFS_DISTRO_STYLE" ]; then
11 # Currently supported: sysvinit-redhat, systemd-redhat
12 CTDB_NFS_DISTRO_STYLE
="systemd-redhat"
15 export FAKE_RPCINFO_SERVICES
=""
17 setup_script_options
<<EOF
18 CTDB_NFS_SKIP_SHARE_CHECK="no"
19 # This doesn't even need to exist
20 CTDB_NFS_EXPORTS_FILE="${CTDB_TEST_TMP_DIR}/etc-exports"
25 if [ "$1" != "down" ]; then
27 Setting up NFS environment: all RPC services up, NFS managed by CTDB
30 case "$CTDB_NFS_DISTRO_STYLE" in
32 service
"nfs" force-started
33 service
"nfslock" force-started
36 service
"nfs-service" force-started
37 service
"nfs-mountd" force-started
38 service
"rpc-rquotad" force-started
39 service
"rpc-statd" force-started
44 "portmapper" "nfs" "mountd" "rquotad" \
47 nfs_setup_fake_threads
"nfsd"
48 nfs_setup_fake_threads
"rpc.foobar" # Set the variable to empty
51 Setting up NFS environment: all RPC services down, NFS not managed by CTDB
54 case "$CTDB_NFS_DISTRO_STYLE" in
56 service
"nfs" force-stopped
57 service
"nfslock" force-stopped
58 service
"nfs-kernel-server" force-stopped
61 service
"nfs-server" force-stopped
62 service
"nfs-mountd" force-stopped
63 service
"rpc-quotad" force-stopped
64 service
"rpc-statd" force-stopped
69 # This is really nasty. However, when we test NFS we don't
70 # actually test statd-callout. If we leave it there then left
71 # over, backgrounded instances of statd-callout will do
72 # horrible things with the "ctdb ip" stub and cause the actual
73 # statd-callout tests that follow to fail.
74 rm "${CTDB_BASE}/statd-callout"
80 for _s
in $FAKE_RPCINFO_SERVICES; do
82 if [ "$_i" = "${_s%%:*}" ]; then
83 debug
"Marking RPC service \"${_i}\" as UNAVAILABLE"
87 _out
="${_out}${_out:+ }${_s}"
89 FAKE_RPCINFO_SERVICES
="$_out"
94 _out
="$FAKE_RPCINFO_SERVICES"
96 debug
"Marking RPC service \"${_i}\" as available"
98 portmapper
) _t
="2:4" ;;
102 nlockmgr
) _t
="3:4" ;;
104 *) die
"Internal error - unsupported RPC service \"${_i}\"" ;;
107 _out
="${_out}${_out:+ }${_i}:${_t}"
109 export FAKE_RPCINFO_SERVICES
="$_out"
112 nfs_setup_fake_threads
()
119 export PROCFS_PATH
="${CTDB_TEST_TMP_DIR}/proc"
120 _threads
="${PROCFS_PATH}/fs/nfsd/threads"
121 mkdir
-p "$(dirname "$_threads")"
123 export FAKE_NFSD_THREAD_PIDS
="$*"
126 export FAKE_RPC_THREAD_PIDS
="$*"
134 "${CTDB_NFS_CALLOUT} start nlockmgr")
135 case "$CTDB_NFS_DISTRO_STYLE" in
137 echo "&Starting nfslock: OK"
141 &Starting nfs-kernel-server: OK
145 echo "&Starting rpc-statd: OK"
149 "${CTDB_NFS_CALLOUT} start nfs")
150 case "$CTDB_NFS_DISTRO_STYLE" in
153 &Starting nfslock: OK
159 &Starting nfs-kernel-server: OK
164 &Starting rpc-statd: OK
165 &Starting nfs-server: OK
166 &Starting rpc-rquotad: OK
171 &Starting rpc-statd: OK
172 &Starting nfs-server: OK
173 &Starting quotarpc: OK
178 "${CTDB_NFS_CALLOUT} stop mountd")
179 case "$CTDB_NFS_DISTRO_STYLE" in
181 echo "Stopping nfs-mountd: OK"
185 "${CTDB_NFS_CALLOUT} stop rquotad")
186 case "$CTDB_NFS_DISTRO_STYLE" in
188 echo "Stopping rpc-rquotad: OK"
191 if service
"quotarpc" status
>/dev
/null
; then
192 echo "Stopping quotarpc: OK"
194 echo "service: can't stop quotarpc - not running"
199 "${CTDB_NFS_CALLOUT} stop status")
200 case "$CTDB_NFS_DISTRO_STYLE" in
202 echo "Stopping rpc-statd: OK"
206 "${CTDB_NFS_CALLOUT} start mountd")
207 case "$CTDB_NFS_DISTRO_STYLE" in
209 echo "&Starting nfs-mountd: OK"
213 "${CTDB_NFS_CALLOUT} start rquotad")
214 case "$CTDB_NFS_DISTRO_STYLE" in
216 echo "&Starting rpc-rquotad: OK"
219 echo "&Starting quotarpc: OK"
223 "${CTDB_NFS_CALLOUT} start status")
224 case "$CTDB_NFS_DISTRO_STYLE" in
226 echo "&Starting rpc-statd: OK"
236 # Set the required result for a particular RPC program having failed
237 # for a certain number of iterations. This is probably still a work
238 # in progress. Note that we could hook aggressively
239 # nfs_check_rpc_service() to try to implement this but we're better
240 # off testing nfs_check_rpc_service() using independent code... even
241 # if it is incomplete and hacky. So, if the 60.nfs eventscript
242 # changes and the tests start to fail then it may be due to this
243 # function being incomplete.
244 rpc_set_service_failure_response
()
247 _numfails
="${2:-1}" # default 1
251 if [ "$_numfails" -eq 0 ]; then
257 # A handy newline. :-)
261 _dir
="${CTDB_NFS_CHECKS_DIR:-${CTDB_BASE}/nfs-checks.d}"
263 _file
=$
(ls "$_dir"/[0-9][0-9].
"${_rpc_service}.check")
265 die
"RPC check file \"$_file\" does not exist or is not unique"
267 _out
="${CTDB_TEST_TMP_DIR}/rpc_failure_output"
269 _rc_file
="${CTDB_TEST_TMP_DIR}/rpc_result"
272 # Subshell to restrict scope variables...
275 # shellcheck disable=SC2034
276 # Unused, but for completeness, possible future use
283 # shellcheck disable=SC2034
284 # Unused, but for completeness, possible future use
288 # Don't bother syntax checking, eventscript does that...
291 # Just use the first version, or use default. This is
292 # dumb but handles all the cases that we care about
294 if [ -n "$version" ]; then
295 _ver
="${version%% *}"
297 case "$_rpc_service" in
298 portmapper
) _ver
="" ;;
303 $_rpc_service failed RPC check:
304 rpcinfo: RPC: Program not registered
305 program $_rpc_service${_ver:+ version }${_ver} is not available"
307 if [ $unhealthy_after -gt 0 ] &&
308 [ "$_numfails" -ge $unhealthy_after ]; then
311 echo "ERROR: ${_rpc_check_out}" >>"$_out"
317 if [ $restart_every -gt 0 ] &&
318 [ $
((_numfails
% restart_every
)) -eq 0 ]; then
319 if ! $_unhealthy; then
320 echo "WARNING: ${_rpc_check_out}" >>"$_out"
323 echo "Trying to restart service \"${_rpc_service}\"..." \
326 guess_output
"$service_stop_cmd" >>"$_out"
328 if [ -n "$service_debug_cmd" ]; then
329 $service_debug_cmd >>"$_out" 2>&1
332 guess_output
"$service_start_cmd" >>"$_out"
336 read -r _rc
<"$_rc_file"
337 required_result
"$_rc" <"$_out"
339 rm -f "$_out" "$_rc_file"
342 program_stack_traces
()
348 if [ "$_prog" = "nfsd" ]; then
349 _pids
="$FAKE_NFSD_THREAD_PIDS"
351 _pids
="$FAKE_RPC_THREAD_PIDS"
353 for _pid
in $_pids; do
354 [ $_count -le "$_max" ] ||
break
356 program_stack_trace
"$_prog" "$_pid"
357 _count
=$
((_count
+ 1))
361 # Run an NFS eventscript iteratively.
363 # - 1st argument is the number of iterations.
365 # - 2nd argument is the NFS/RPC service being tested
367 # rpcinfo is used on each iteration to test the availability of the
370 # If this is not set or null then no RPC service is checked and the
371 # required output is not reset on each iteration. This is useful in
372 # baseline tests to confirm that the eventscript and test
373 # infrastructure is working correctly.
375 # - Subsequent arguments come in pairs: an iteration number and
376 # something to eval before that iteration. Each time an iteration
377 # number is matched the associated argument is given to eval after
378 # the default setup is done. The iteration numbers need to be given
379 # in ascending order.
381 # These arguments can allow a service to be started or stopped
382 # before a particular iteration.
394 # shellcheck disable=SC2154
395 # Variables defined in define_test()
396 echo "Running $_repeats iterations of \"$script $event\" $args"
399 for _iteration
in $
(seq 1 "$_repeats"); do
400 # This is not a numerical comparison because $1 will
402 if [ "$_iteration" = "$1" ]; then
404 ##################################################
408 ##################################################
412 if [ -n "$_rpc_service" ]; then
413 if rpcinfo
-T tcp localhost
"$_rpc_service" \
414 >/dev
/null
2>&1 ; then
417 _iterate_failcount
=$
((_iterate_failcount
+ 1))
419 rpc_set_service_failure_response \
420 "$_rpc_service" $_iterate_failcount
422 _out
=$
(simple_test
2>&1)
424 if "$CTDB_TEST_VERBOSE" ||
[ $_ret -ne 0 ]; then
426 ##################################################
427 Iteration ${_iteration}:
431 if [ $_ret -ne 0 ]; then