1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

Merge remote branch 'martins/tests'

(This used to be ctdb commit 71080adfe0828e15bf2f4b0bee7d52e06fff3449)
This commit is contained in:
Ronnie Sahlberg 2011-09-01 08:55:23 +10:00
commit f7b74289fb
24 changed files with 587 additions and 51 deletions

View File

@ -1,5 +1,8 @@
# Hey Emacs, this is a -*- shell-script -*- !!! :-) # Hey Emacs, this is a -*- shell-script -*- !!! :-)
# Print a message and exit.
die () { echo "$@" >&2 ; exit 1 ; }
# Augment PATH with relevant stubs/ directories. We do this by actually # Augment PATH with relevant stubs/ directories. We do this by actually
# setting PATH, and also by setting $EVENTSCRIPTS_PATH and then # setting PATH, and also by setting $EVENTSCRIPTS_PATH and then
# prepending that to $PATH in rc.local to avoid the PATH reset in # prepending that to $PATH in rc.local to avoid the PATH reset in
@ -30,8 +33,7 @@ if [ -d "${EVENTSCRIPTS_TESTCASE_DIR}/etc" ] ; then
elif [ -d "${EVENTSCRIPTS_TESTS_DIR}/etc" ] ; then elif [ -d "${EVENTSCRIPTS_TESTS_DIR}/etc" ] ; then
CTDB_ETCDIR="${EVENTSCRIPTS_TESTS_DIR}/etc" CTDB_ETCDIR="${EVENTSCRIPTS_TESTS_DIR}/etc"
else else
echo "Unable to set \$CTDB_ETCDIR" >&2 die "Unable to set \$CTDB_ETCDIR"
exit 1
fi fi
export CTDB_ETCDIR export CTDB_ETCDIR
@ -42,8 +44,7 @@ elif [ -d "${EVENTSCRIPTS_TESTCASE_DIR}/etc/ctdb" ] ; then
elif [ -d "${EVENTSCRIPTS_TESTS_DIR}/etc-ctdb" ] ; then elif [ -d "${EVENTSCRIPTS_TESTS_DIR}/etc-ctdb" ] ; then
CTDB_BASE="${EVENTSCRIPTS_TESTS_DIR}/etc-ctdb" CTDB_BASE="${EVENTSCRIPTS_TESTS_DIR}/etc-ctdb"
else else
echo "Unable to set \$CTDB_BASE" >&2 die "Unable to set \$CTDB_BASE"
exit 1
fi fi
export CTDB_BASE export CTDB_BASE
@ -109,7 +110,7 @@ tcp_port_down ()
{ {
for _i ; do for _i ; do
debug "Marking TCP port \"${_i}\" as not listening" debug "Marking TCP port \"${_i}\" as not listening"
FAKE_NETSTAT_TCP_LISTEN=$(echo "$FAKE_NETSTAT_TCP_LISTEN" | sed -r -e "s@[[:space:]]*[\.0-9]+:${_i}@@g") FAKE_TCP_LISTEN=$(echo "$FAKE_TCP_LISTEN" | sed -r -e "s@[[:space:]]*[\.0-9]+:${_i}@@g")
done done
} }
@ -177,6 +178,11 @@ ethtool_interfaces_up ()
done done
} }
setup_nmap_output_filter ()
{
OUT_FILTER="-e 's@^(DEBUG: # Nmap 5.21 scan initiated) .+ (as:)@\1 DATE \2@' -e 's@^(DEBUG: # Nmap done at) .+ (--)@\1 DATE \2@'"
}
###################################################################### ######################################################################
# CTDB fakery # CTDB fakery
@ -232,6 +238,10 @@ setup_ctdb ()
export FAKE_CTDB_NODES_DOWN="$EVENTSCRIPTS_TESTS_VAR_DIR/nodes-down" export FAKE_CTDB_NODES_DOWN="$EVENTSCRIPTS_TESTS_VAR_DIR/nodes-down"
mkdir -p "$FAKE_CTDB_NODES_DOWN" mkdir -p "$FAKE_CTDB_NODES_DOWN"
rm -f "$FAKE_CTDB_NODES_DOWN"/* rm -f "$FAKE_CTDB_NODES_DOWN"/*
export FAKE_CTDB_SCRIPTSTATUS="$EVENTSCRIPTS_TESTS_VAR_DIR/scriptstatus"
mkdir -p "$FAKE_CTDB_SCRIPTSTATUS"
rm -f "$FAKE_CTDB_SCRIPTSTATUS"/*
} }
@ -280,6 +290,25 @@ ctdb_get_1_public_address ()
echo "${_addrs%% *}" | sed -r -e 's#(.*)/(.*)@(.*)#\3 \1 \2#g' echo "${_addrs%% *}" | sed -r -e 's#(.*)/(.*)@(.*)#\3 \1 \2#g'
} }
ctdb_not_implemented ()
{
export CTDB_NOT_IMPLEMENTED="$1"
ctdb_not_implemented="\
DEBUG: ctdb: command \"$1\" not implemented in stub"
}
ctdb_fake_scriptstatus ()
{
_code="$1"
_status="$2"
_err_out="$3"
_d1=$(date '+%s.%N')
_d2=$(date '+%s.%N')
echo "$_code $_status $_err_out" >"$FAKE_CTDB_SCRIPTSTATUS/$script"
}
###################################################################### ######################################################################
# Samba fakery # Samba fakery
@ -303,8 +332,13 @@ setup_samba ()
export CTDB_SAMBA_SKIP_SHARE_CHECK="no" export CTDB_SAMBA_SKIP_SHARE_CHECK="no"
export CTDB_MANAGED_SERVICES="foo samba winbind bar" export CTDB_MANAGED_SERVICES="foo samba winbind bar"
export FAKE_NETSTAT_TCP_LISTEN="0.0.0.0:445 0.0.0.0:139" export FAKE_TCP_LISTEN="0.0.0.0:445 0.0.0.0:139"
export FAKE_WBINFO_FAIL="no" export FAKE_WBINFO_FAIL="no"
# Some things in 50.samba are backgrounded and waited for. If
# we don't sleep at all then timeouts can happen. This avoids
# that... :-)
export FAKE_SLEEP_FORCE=0.1
else else
debug "Marking Samba services as down, not listening and not managed by CTDB" debug "Marking Samba services as down, not listening and not managed by CTDB"
# Get into known state. # Get into known state.
@ -321,7 +355,7 @@ setup_samba ()
unset CTDB_MANAGES_SAMBA unset CTDB_MANAGES_SAMBA
unset CTDB_MANAGES_WINBIND unset CTDB_MANAGES_WINBIND
export FAKE_NETSTAT_TCP_LISTEN="" export FAKE_TCP_LISTEN=""
export FAKE_WBINFO_FAIL="yes" export FAKE_WBINFO_FAIL="yes"
fi fi
@ -403,9 +437,7 @@ rpc_services_up ()
rquotad) _t="1:2" ;; rquotad) _t="1:2" ;;
nlockmgr) _t="3:4" ;; nlockmgr) _t="3:4" ;;
status) _t="1:1" ;; status) _t="1:1" ;;
*) *) die "Internal error - unsupported RPC service \"${_i}\"" ;;
echo "Internal error - unsupported RPC service \"${_i}\""
exit 1
esac esac
FAKE_RPCINFO_SERVICES="${FAKE_RPCINFO_SERVICES}${FAKE_RPCINFO_SERVICES:+ }${_i}:${_t}" FAKE_RPCINFO_SERVICES="${FAKE_RPCINFO_SERVICES}${FAKE_RPCINFO_SERVICES:+ }${_i}:${_t}"
@ -533,8 +565,7 @@ Starting nfslock: OK"
setup_vsftpd () setup_vsftpd ()
{ {
if [ "$1" != "down" ] ; then if [ "$1" != "down" ] ; then
echo "setup_vsftpd up not implemented!!!" die "setup_vsftpd up not implemented!!!"
exit 1
else else
debug "Setting up VSFTPD environment: service down, not managed by CTDB" debug "Setting up VSFTPD environment: service down, not managed by CTDB"
@ -553,8 +584,7 @@ setup_vsftpd ()
setup_httpd () setup_httpd ()
{ {
if [ "$1" != "down" ] ; then if [ "$1" != "down" ] ; then
echo "setup_httpd up not implemented!!!" die "setup_httpd up not implemented!!!"
exit 1
else else
debug "Setting up HTTPD environment: service down, not managed by CTDB" debug "Setting up HTTPD environment: service down, not managed by CTDB"
@ -578,16 +608,27 @@ define_test ()
desc="$1" desc="$1"
_f="$0" _f="$0"
_f="${_f#./}" # strip leading ./ _f="${_f#./}" # strip leading ./
_f="${_f#simple/}" # strip leading simple/ _f="${_f#simple/}" # strip leading simple/
_f="${_f%%/*}" # if subdir, strip off file _f="${_f#multievent/}" # strip leading multievent/
_f="${_f%.sh}" # strip off .sh suffix if any _f="${_f%%/*}" # if subdir, strip off file
_f="${_f%.sh}" # strip off .sh suffix if any
# Remaining format should be NN.service.event.NNN: # Remaining format should be NN.service.event.NNN or NN.service.NNN:
_num="${_f##*.}" _num="${_f##*.}"
_f="${_f%.*}" _f="${_f%.*}"
event="${_f##*.}" case "$_f" in
script="${_f%.*}" *.*.*)
script="${_f%.*}"
event="${_f##*.}"
;;
*.*)
script="$_f"
unset event
;;
*)
die "Internal error - unknown testcase filename format"
esac
printf "%-14s %-10s %-4s - %s\n\n" "$script" "$event" "$_num" "$desc" printf "%-14s %-10s %-4s - %s\n\n" "$script" "$event" "$_num" "$desc"
} }
@ -637,25 +678,24 @@ result_print ()
if [ -n "$_iteration" ] ; then if [ -n "$_iteration" ] ; then
cat <<EOF cat <<EOF
################################################## ==================================================
##################################################
Iteration $_iteration Iteration $_iteration
EOF EOF
fi fi
cat <<EOF cat <<EOF
################################################## --------------------------------------------------
Output (Exit status: ${_rc}): Output (Exit status: ${_rc}):
################################################## --------------------------------------------------
$_out $_out
EOF EOF
fi fi
if ! $_passed ; then if ! $_passed ; then
cat <<EOF cat <<EOF
################################################## --------------------------------------------------
Required output (Exit status: ${required_rc}): Required output (Exit status: ${required_rc}):
################################################## --------------------------------------------------
$required_output $required_output
EOF EOF
fi fi
@ -668,20 +708,19 @@ result_footer ()
if [ "$EVENTSCRIPT_TESTS_VERBOSE" = "yes" ] || ! $_passed ; then if [ "$EVENTSCRIPT_TESTS_VERBOSE" = "yes" ] || ! $_passed ; then
cat <<EOF cat <<EOF
################################################## --------------------------------------------------
CTDB_BASE="$CTDB_BASE" CTDB_BASE="$CTDB_BASE"
CTDB_ETCDIR="$CTDB_ETCDIR" CTDB_ETCDIR="$CTDB_ETCDIR"
ctdb client is "$(which ctdb)" ctdb client is "$(which ctdb)"
################################################## --------------------------------------------------
EOF EOF
fi fi
echo
if $_passed ; then if $_passed ; then
echo "PASSED" echo "PASSED"
return 0 return 0
else else
echo
echo "FAILED" echo "FAILED"
return 1 return 1
fi fi
@ -699,11 +738,19 @@ EOF
# useful for debugging. # useful for debugging.
simple_test () simple_test ()
{ {
echo "Running \"${CTDB_BASE}/events.d/$script $event\"" [ -n "$event" ] || die 'simple_test: $event not set'
echo "Running \"$script $event${1:+ }$*\""
_out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" "$@" 2>&1) _out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" "$@" 2>&1)
_rc=$? _rc=$?
if [ "$_out" = "$required_output" -a $_rc = $required_rc ] ; then if [ -n "$OUT_FILTER" ] ; then
_fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
else
_fout="$_out"
fi
if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
_passed=true _passed=true
else else
_passed=false _passed=false
@ -713,6 +760,17 @@ simple_test ()
result_footer "$_passed" result_footer "$_passed"
} }
simple_test_event ()
{
# If something has previously failed then don't continue.
: ${_passed:=true}
$_passed || return 1
event="$1" ; shift
echo "##################################################"
simple_test "$@"
}
# Run an eventscript iteratively. # Run an eventscript iteratively.
# - 1st argument is the number of iterations. # - 1st argument is the number of iterations.
# - 2nd argument is something to eval to do setup for every iteration. # - 2nd argument is something to eval to do setup for every iteration.
@ -733,6 +791,8 @@ simple_test ()
# iteration. # iteration.
iterate_test () iterate_test ()
{ {
[ -n "$event" ] || die 'simple_test: $event not set'
args="" args=""
if [ "$1" = "--" ] ; then if [ "$1" = "--" ] ; then
shift shift
@ -747,7 +807,7 @@ iterate_test ()
_setup_default="$2" _setup_default="$2"
shift 2 shift 2
echo "Running $_repeats iterations of \"${CTDB_BASE}/events.d/$script $event\" $args" echo "Running $_repeats iterations of \"$script $event\" $args"
_result=true _result=true
@ -765,7 +825,13 @@ iterate_test ()
_out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" $args 2>&1) _out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" $args 2>&1)
_rc=$? _rc=$?
if [ "$_out" = "$required_output" -a $_rc = $required_rc ] ; then if [ -n "$OUT_FILTER" ] ; then
_fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
else
_fout="$_out"
fi
if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
_passed=true _passed=true
else else
_passed=false _passed=false

View File

@ -0,0 +1 @@
../../../../config/ctdb.sysconfig

View File

@ -0,0 +1,14 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "takeip, removeip"
setup_ctdb
public_address=$(ctdb_get_1_public_address)
ok_null
simple_test_event "takeip" $public_address
simple_test_event "releaseip" $public_address

View File

@ -0,0 +1,21 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "takeip, ipreallocated -> reconfigure"
setup_nfs
public_address=$(ctdb_get_1_public_address)
ok_null
simple_test_event "takeip" $public_address
ok <<EOF
Reconfiguring service "nfs"...
Starting nfslock: OK
Starting nfs: OK
EOF
simple_test_event "ipreallocated"

View File

@ -0,0 +1,25 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "takeip, monitor -> reconfigure"
setup_nfs
public_address=$(ctdb_get_1_public_address)
ok_null
simple_test_event "takeip" $public_address
# This currently assumes that ctdb scriptstatus will always return a
# good status (when replaying). That should change and we will need
# to split this into 2 tests.
ok <<EOF
Reconfiguring service "nfs"...
Starting nfslock: OK
Starting nfs: OK
Replaying previous status for this script due to reconfigure...
EOF
simple_test_event "monitor"

View File

@ -0,0 +1,27 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "takeip, monitor -> reconfigure, replay error"
setup_nfs
public_address=$(ctdb_get_1_public_address)
err="foo: bar error occurred"
ok_null
simple_test_event "takeip" $public_address
ctdb_fake_scriptstatus 1 "ERROR" "$err"
required_result 1 <<EOF
Reconfiguring service "nfs"...
Starting nfslock: OK
Starting nfs: OK
Replaying previous status for this script due to reconfigure...
$err
EOF
simple_test_event "monitor"

View File

@ -0,0 +1,27 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "takeip, monitor -> reconfigure, replay timedout"
setup_nfs
public_address=$(ctdb_get_1_public_address)
err="waiting, waiting..."
ok_null
simple_test_event "takeip" $public_address
ctdb_fake_scriptstatus -62 "TIMEDOUT" "$err"
required_result 1 <<EOF
Reconfiguring service "nfs"...
Starting nfslock: OK
Starting nfs: OK
Replaying previous status for this script due to reconfigure...
[Replay of TIMEDOUT scriptstatus - note incorrect return code.] $err
EOF
simple_test_event "monitor"

View File

@ -0,0 +1,27 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "takeip, monitor -> reconfigure, replay disabled"
setup_nfs
public_address=$(ctdb_get_1_public_address)
err=""
ok_null
simple_test_event "takeip" $public_address
ctdb_fake_scriptstatus -8 "DISABLED" "$err"
ok <<EOF
Reconfiguring service "nfs"...
Starting nfslock: OK
Starting nfs: OK
Replaying previous status for this script due to reconfigure...
[Replay of DISABLED scriptstatus - note incorrect return code.] $err
EOF
simple_test_event "monitor"

View File

@ -0,0 +1,21 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "reconfigure (synthetic), twice"
# This checks that the lock is released...
setup_nfs
public_address=$(ctdb_get_1_public_address)
err=""
ok <<EOF
Reconfiguring service "nfs"...
Starting nfslock: OK
Starting nfs: OK
EOF
simple_test_event "reconfigure"
simple_test_event "reconfigure"

View File

@ -15,6 +15,12 @@ for i ; do
export EVENTSCRIPT_TESTS_VERBOSE="yes" export EVENTSCRIPT_TESTS_VERBOSE="yes"
shift shift
;; ;;
-T)
# This will cause tests to fail but is good for debugging
# individual tests when they fail.
export EVENTSCRIPTS_TESTS_TRACE="sh -x"
shift
;;
-*) -*)
opts="$opts $i" opts="$opts $i"
shift shift

View File

@ -8,4 +8,4 @@ setup_vsftpd "down"
ok_null ok_null
simple_test $cmd simple_test

View File

@ -8,4 +8,4 @@ setup_httpd "down"
ok_null ok_null
simple_test $cmd simple_test

View File

@ -0,0 +1,18 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "port 139 down, default tcp checker, debug"
# This has to go before the setup, otherwise it will write a dud file.
export CTDB_DEBUGLEVEL=4
setup_samba
tcp_port_down 139
required_result 1 <<EOF
ERROR: samba tcp port 139 is not responding
DEBUG: "ctdb checktcpport 139" was able to bind to port
EOF
simple_test

View File

@ -0,0 +1,15 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "port 139 down, ctdb checktcpport not implemented"
# TODO: create nmap stub
export CTDB_NOT_IMPLEMENTED="checktcpport"
setup_samba
tcp_port_down 139
required_result 1 "ERROR: samba tcp port 139 is not responding"
simple_test

View File

@ -0,0 +1,30 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "port 139 down, ctdb checktcpport not implemented, debug"
ctdb_not_implemented "checktcpport"
# This has to go before the setup, otherwise it will write a dud file.
export CTDB_DEBUGLEVEL=4
setup_nmap_output_filter
setup_samba
tcp_port_down 139
required_result 1 <<EOF
DEBUG: ctdb_check_ports - checker ctdb not implemented
DEBUG: output from checker was:
DEBUG: ctdb checktcpport 445 (exited with 1) with output:
$ctdb_not_implemented
ERROR: samba tcp port 139 is not responding
DEBUG: nmap -n -oG - -PS 127.0.0.1 -p 445,139 shows this output:
DEBUG: # Nmap 5.21 scan initiated DATE as: nmap -n -oG - -PS 127.0.0.1 -p 445,139
DEBUG: Host: 127.0.0.1 () Status: Up
DEBUG: Host: 127.0.0.1 () Ports: 445/open/tcp//microsoft-ds///, 139/closed/tcp//netbios-ssn///
DEBUG: # Nmap done at DATE -- 1 IP address (1 host up) scanned in 0.04 seconds
EOF
simple_test

View File

@ -0,0 +1,33 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "port 139 down, ctdb checktcpport/nmap not implemented, debug"
ctdb_not_implemented "checktcpport"
export FAKE_NMAP_NOT_FOUND="yes"
# This has to go before the setup, otherwise it will write a dud file.
export CTDB_DEBUGLEVEL=4
setup_nmap_output_filter
setup_samba
tcp_port_down 139
required_result 1 <<EOF
DEBUG: ctdb_check_ports - checker ctdb not implemented
DEBUG: output from checker was:
DEBUG: ctdb checktcpport 445 (exited with 1) with output:
$ctdb_not_implemented
DEBUG: ctdb_check_ports - checker nmap not implemented
DEBUG: output from checker was:
DEBUG: sh: nmap: command not found
ERROR: samba tcp port 139 is not responding
DEBUG: netstat -l -t -n shows this output:
DEBUG: Active Internet connections (servers only)
DEBUG: Proto Recv-Q Send-Q Local Address Foreign Address State
DEBUG: tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN
EOF
simple_test

View File

@ -0,0 +1,20 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "port 139 down, ctdb checktcpport/nmap/netstat not implemented"
ctdb_not_implemented "checktcpport"
export FAKE_NMAP_NOT_FOUND="yes"
export FAKE_NETSTAT_NOT_FOUND="yes"
setup_nmap_output_filter
setup_samba
tcp_port_down 139
required_result 127 <<EOF
INTERNAL ERROR: ctdb_check_ports - no working checkers in CTDB_TCP_PORT_CHECKERS="ctdb nmap netstat"
EOF
simple_test

View File

@ -0,0 +1,13 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "2nd share missing"
setup_nfs
shares_missing "ERROR: nfs directory \"%s\" not available" 2
required_result 1 "$MISSING_SHARES_TEXT"
simple_test

View File

@ -0,0 +1,14 @@
#!/bin/sh
. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
define_test "2nd share missing, skipping share checks"
setup_nfs
export CTDB_NFS_SKIP_SHARE_CHECK="yes"
shares_missing "ERROR: nfs directory \"%s\" not available" 2
ok_null
simple_test

View File

@ -2,6 +2,8 @@
prog="ctdb" prog="ctdb"
not_implemented_exit_code=1
usage () usage ()
{ {
cat >&2 <<EOF cat >&2 <<EOF
@ -9,26 +11,28 @@ Usage: $prog [-Y] cmd
A fake CTDB stub that prints items depending on the variables A fake CTDB stub that prints items depending on the variables
FAKE_CTDB_PNN (default 0) depending on command-line options. FAKE_CTDB_PNN (default 0) depending on command-line options.
Note that -Y is ignored.
EOF EOF
exit 1 exit 1
} }
# $POSIXLY_CORRECT means that the command passed to onnode can take not_implemented ()
# options and getopt won't reorder things to make them options to this {
# script. echo "${prog}: command \"$1\" not implemented in stub" >&2
exit $not_implemented_exit_code
}
# Don't set $POSIXLY_CORRECT here.
_temp=$(getopt -n "$prog" -o "Yvh" -l help -- "$@") || \ _temp=$(getopt -n "$prog" -o "Yvh" -l help -- "$@") || \
usage usage
eval set -- "$_temp" eval set -- "$_temp"
verbose=false verbose=false
machine_readable=false
while true ; do while true ; do
case "$1" in case "$1" in
-Y) shift ;; -Y) machine_readable=true ; shift ;;
-v) verbose=true ; shift ;; -v) verbose=true ; shift ;;
--) shift ; break ;; --) shift ; break ;;
-h|--help|*) usage ;; # * shouldn't happen, so this is reasonable. -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
@ -51,6 +55,13 @@ setup_pstore ()
mkdir -p "$pstore_dir" mkdir -p "$pstore_dir"
} }
# For testing backward compatibility...
for i in $CTDB_NOT_IMPLEMENTED ; do
if [ "$i" = "$1" ] ; then
not_implemented "$i"
fi
done
case "$1" in case "$1" in
ip) ip)
# NOTE: all nodes share the same public addresses file. # NOTE: all nodes share the same public addresses file.
@ -159,8 +170,58 @@ case "$1" in
exit 1 exit 1
esac esac
;; ;;
*) getdebug)
echo "${prog}: command \"$1\" not implemented in stub" case "${CTDB_DEBUGLEVEL:-0}" in
exit 1 -3) _t="EMERG" ;;
esac -2) _t="ALERT" ;;
-1) _t="CRIT" ;;
0) _t="ERR" ;;
1) _t="WARNING" ;;
2) _t="NOTICE" ;;
3) _t="INFO" ;;
4) _t="DEBUG" ;;
*) _t="ERR" ;;
esac
cat<<EOF
:Name:Level:
:${_t}:${CTDB_DEBUGLEVEL}:
EOF
;;
checktcpport)
for _i in $FAKE_TCP_LISTEN ; do
if [ "$2" = "${_i##*:}" ] ; then
exit 98
fi
done
exit 0
;;
scriptstatus)
$machine_readable || not_implemented "$1, without -Y"
[ "$2" != "all" ] || not_implemented "scriptstatus all"
# For now just assume everything is good.
echo ":Type:Name:Code:Status:Start:End:Error Output...:"
for _i in "$CTDB_BASE/events.d/"*.* ; do
_d1=$(date '+%s.%N')
_b="${_i##*/}" # basename
_f="$FAKE_CTDB_SCRIPTSTATUS/$_b"
if [ -r "$_f" ] ; then
read _code _status _err_out <"$_f"
else
_code="0"
_status="OK"
if [ ! -x "$_i" ] ; then
_status="DISABLED"
_code="-8"
fi
_err_out=""
fi
_d2=$(date '+%s.%N')
echo ":${2:-monitor}:${_b}:${_code}:${_status}:${_d1}:${_d2}:${_err_out}:"
done
;;
*)
not_implemented "$1"
esac

View File

@ -3,5 +3,11 @@
opts="10.0.0.0/16(rw,async,insecure,no_root_squash,no_subtree_check)" opts="10.0.0.0/16(rw,async,insecure,no_root_squash,no_subtree_check)"
for i in $FAKE_SHARES ; do for i in $FAKE_SHARES ; do
echo "${i} ${opts}" # Directories longer than 15 characters are printed on their own
# line.
if [ ${#i} -ge 15 ] ; then
printf '%s\n\t\t%s\n' "$i" "$opts"
else
printf '%s\t%s\n' "$i" "$opts"
fi
done done

View File

@ -2,13 +2,20 @@
prog="netstat" prog="netstat"
# Pretty that we're the shell and that this command could not be
# found.
if [ "$FAKE_NETSTAT_NOT_FOUND" = "yes" ] ; then
echo "sh: ${prog}: command not found" >&2
exit 127
fi
usage () usage ()
{ {
cat >&2 <<EOF cat >&2 <<EOF
Usage: $prog [ -t | --unix ] [ -n ] [ -a ] [ -l ] Usage: $prog [ -t | --unix ] [ -n ] [ -a ] [ -l ]
A fake netstat stub that prints items depending on the variables A fake netstat stub that prints items depending on the variables
FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_NETSTAT_TCP_LISTEN, FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_TCP_LISTEN,
FAKE_NETSTAT_UNIX_LISTEN, depending on command-line options. FAKE_NETSTAT_UNIX_LISTEN, depending on command-line options.
Note that -n is ignored. Note that -n is ignored.
@ -73,7 +80,7 @@ if $tcp ; then
done done
if $all || $listen ; then if $all || $listen ; then
for i in $FAKE_NETSTAT_TCP_LISTEN ; do for i in $FAKE_TCP_LISTEN ; do
printf "$tcp_fmt" $i "0.0.0.0:*" "LISTEN" printf "$tcp_fmt" $i "0.0.0.0:*" "LISTEN"
done done
fi fi

View File

@ -0,0 +1,75 @@
#!/bin/bash
prog="nmap"
# Pretty that we're the shell and that this command could not be
# found.
if [ "$FAKE_NMAP_NOT_FOUND" = "yes" ] ; then
echo "sh: ${prog}: command not found" >&2
exit 127
fi
usage ()
{
cat >&2 <<EOF
Usage: $prog -n -oG - -PS 127.0.0.1 -p <port>[,<port> ...]
A fake nmap stub that prints items depending on the variable
FAKE_TCP_LISTEN and the ports specified.
Note that all options apart from -p are ignored.
EOF
exit 1
}
ports=""
parse_options ()
{
_temp=$(getopt -n "$prog" -a -o "np:" -l help -l PS: -l oG: -- "$@")
[ $? != 0 ] && usage
eval set -- "$_temp"
while true ; do
case "$1" in
-n) shift ;;
--oG|--PS) shift 2 ;;
-p) ports="${ports}${ports:+ }${2//,/ }" ; shift 2 ;;
--) shift ; break ;;
-h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
esac
done
[ $# -gt 0 ] && usage
[ -n "$ports" ] || usage
}
# For printing out...
args="$*"
parse_options "$@"
port_states=""
for p in $ports ; do
pn=$(getent services "$p" | sed -e 's@[[:space:]].*@@')
for i in $FAKE_TCP_LISTEN ; do
lp="${i##*:}"
if [ "$p" = "$lp" ] ; then
port_states="${port_states}${port_states:+, }${p}/open/tcp//${pn}///"
continue 2
fi
done
port_states="${port_states}${port_states:+, }${p}/closed/tcp//${pn}///"
done
cat <<EOF
# Nmap 5.21 scan initiated $(date) as: nmap $args
Host: 127.0.0.1 () Status: Up
Host: 127.0.0.1 () Ports: $port_states
# Nmap done at $(date) -- 1 IP address (1 host up) scanned in 0.04 seconds
EOF

View File

@ -0,0 +1,9 @@
#!/bin/sh
if [ "$FAKE_SLEEP_REALLY" = "yes" ] ; then
/bin/sleep "$@"
elif [ -n "$FAKE_SLEEP_FORCE" ] ; then
/bin/sleep "$FAKE_SLEEP_FORCE"
else
:
fi