Tests - eventscripts - ctdb stub - implement scriptstatus, tweaks
authorMartin Schwenke <martin@meltin.net>
Tue, 30 Aug 2011 06:27:04 +0000 (16:27 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 30 Aug 2011 06:51:55 +0000 (16:51 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/eventscripts/stubs/ctdb

index 8d6409363e08e2c1d7d4005de24e4d9194644f6b..5b18473ec1ddd1bba61149f7a1fd6eb6f27eee6a 100755 (executable)
@@ -11,10 +11,13 @@ Usage: $prog [-Y] cmd
 
 A fake CTDB stub that prints items depending on the variables
 FAKE_CTDB_PNN (default 0) depending on command-line options.
-
-Note that -Y is ignored.
-
 EOF
+    exit 1
+}
+
+not_implemented ()
+{
+    echo "${prog}: command \"$1\" not implemented in stub" >&2
     exit $not_implemented_exit_code
 }
 
@@ -25,10 +28,11 @@ _temp=$(getopt -n "$prog" -o "Yvh" -l help -- "$@") || \
 eval set -- "$_temp"
 
 verbose=false
+machine_readable=false
 
 while true ; do
     case "$1" in
-       -Y) shift ;;
+       -Y) machine_readable=true ; shift ;;
        -v) verbose=true ; shift ;;
        --) shift ; break ;;
        -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
@@ -54,8 +58,7 @@ setup_pstore ()
 # For testing backward compatibility...
 for i in $CTDB_NOT_IMPLEMENTED ; do
     if [ "$i" = "$1" ] ; then
-       echo "${prog}: command \"$i\" not implemented" >&2
-       usage
+       not_implemented "$i"
     fi
 done
 
@@ -194,8 +197,24 @@ EOF
 
        exit 0
        ;;
+    scriptstatus)
+       $machine_readable || not_implemented "$1, without -Y"
+       [ "$2" != "all" ] || not_implemented "scriptstatus all"
+       # For now just assume everything is good.
+       _d1=$(date '+%s.%N')
+       _d2=$(date '+%s.%N')
+       echo ":Type:Name:Code:Status:Start:End:Error Output...:"
+       for _i in "$CTDB_BASE/events.d/"*.* ; do
+           _b="${_i##*/}" # basename
+           _status="OK"
+           _code="0"
+           if [ ! -x "$_i" ] ; then
+               _status="DISABLED"
+               _code="-8"
+           fi
+           echo ":${2:-monitor}:${_b}:${_code}:${_status}:${_d1}:${_d2}::"
+       done
+       ;;
     *)
-       echo "${prog}: command \"$1\" not implemented in stub"
-       usage
+       not_implemented "$1"
 esac
-