scripts: Use $CTDB_SCRIPT_DEBUGLEVEL instead of something more complex
authorMartin Schwenke <martin@meltin.net>
Wed, 17 Apr 2013 03:12:32 +0000 (13:12 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 19 Apr 2013 03:13:36 +0000 (13:13 +1000)
The current logic is horrible and creates an unnecessary file.  Let's
make the script debug level independent of ctddb's debug level.

* Have debug() use $CTDB_SCRIPT_DEBUGLEVEL directly

* Remove ctdb_set_current_debuglevel()

* Remove the "getdebug" command from ctdb stub in eventscript unit
  tests

* Update relevant eventscript unit tests to use
  $CTDB_SCRIPT_DEBUGLEVEL

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/events.d/00.ctdb
config/functions
tests/eventscripts/50.samba.monitor.107.sh
tests/eventscripts/50.samba.monitor.109.sh
tests/eventscripts/50.samba.monitor.110.sh
tests/eventscripts/stubs/ctdb

index 02613536f37254b1afce4ca43c3c08f98245cf31..c1ac11a9236d4219d407bba17fa9bcfc04cbc6d2 100755 (executable)
@@ -88,11 +88,6 @@ case "$1" in
        update_config_from_tdb &
        ;;
     monitor)
-       # Inherit the debug level from ctdbd on each monitor run.  If
-       # there's a more urgent need then override CTDB_CURRENT_DEBUGLEVEL
-       # using a file in $CTDB_BASE/rc.local.d/.
-        ctdb_set_current_debuglevel create
-
        # We should never enter swap, so SwapTotal == SwapFree.
        [ "$CTDB_CHECK_SWAP_IS_NOT_USED" = "yes" ] && {
            if [ -n "`grep '^Swap\(Total\|Free\)' /proc/meminfo | uniq -s 10 -u`" ]; then
index 8d186a0e41dce58d535c4b98138715bcad040926..a622fd374efe35b19dbba3997a520995eb070315 100755 (executable)
@@ -42,39 +42,12 @@ loadconfig () {
 }
 
 ##############################################################
-# make sure CTDB_CURRENT_DEBUGLEVEL is set to the desired debug level
-# (integer)
-#
-# If it is already set then do nothing, since it might have been set
-# via a file in rc.local.d/.  If it is not set then set it by sourcing
-# /var/ctdb/eventscript_debuglevel. If this file does not exist then
-# create it using output from "ctdb getdebug".  If the option 1st arg
-# is "create" then don't source an existing file but create a new one
-# instead - this is useful for creating the file just once in each
-# event run in 00.ctdb.  If there's a problem getting the debug level
-# from ctdb then it is silently set to 0 - no use spamming logs if our
-# debug code is broken...
-ctdb_set_current_debuglevel ()
-{
-    [ -z "$CTDB_CURRENT_DEBUGLEVEL" ] || return 0
-
-    _f="$CTDB_VARDIR/eventscript_debuglevel"
-
-    if [ "$1" = "create" -o ! -r "$_f" ] ; then
-       _t=$(ctdb getdebug -Y 2>/dev/null)
-       # get last field of output
-       _t="${_t%:}"
-       _t="${_t##*:}"
-       # Defaults to 0
-       echo "export CTDB_CURRENT_DEBUGLEVEL=\"${_t:-0}\"" >"$_f"
-    fi
-
-    . "$_f"
-}
 
+# CTDB_SCRIPT_DEBUGLEVEL can be overwritten by setting it in a
+# configuration file.
 debug ()
 {
-    if [ $CTDB_CURRENT_DEBUGLEVEL -ge 4 ] ; then
+    if [ ${CTDB_SCRIPT_DEBUGLEVEL:-2} -ge 4 ] ; then
        # If there are arguments then echo them.  Otherwise expect to
        # use stdin, which allows us to pass lots of debug using a
        # here document.
@@ -1513,11 +1486,6 @@ update_tickles ()
        done
 }
 
-# We'll call this here to ensure $CTDB_CURRENT_DEBUGLEVEL is set.
-# This gives us a chance to override the debug level using a file in
-# $CTDB_BASE/rc.local.d/.
-ctdb_set_current_debuglevel
-
 script_name="${0##*/}"       # basename
 service_name="$script_name"  # default is just the script name
 service_fail_limit=1
index 4c776ac8aa66f00ce05b4993e7bea84b94d74d40..573ff80e4fc0119035a46ada7f8c5a9879bc32a8 100755 (executable)
@@ -4,8 +4,7 @@
 
 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
+export CTDB_SCRIPT_DEBUGLEVEL=4
 
 setup_samba
 tcp_port_down 139
index f90ba629dbe7242914518461c3740b66f5bfde89..0104fd941d4d07e21a9ddd504e3dcaf30174b812 100755 (executable)
@@ -6,8 +6,7 @@ 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
+export CTDB_SCRIPT_DEBUGLEVEL=4
 
 setup_nmap_output_filter
 
index 639cc515fe49025fe57149f2254f2c0b9c98d91e..4697e54925fd7edc8af27d87d61d2cb3b57c131a 100755 (executable)
@@ -7,8 +7,7 @@ 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
+export CTDB_SCRIPT_DEBUGLEVEL=4
 
 setup_nmap_output_filter
 
index 3abdd164b98b324015d9e7bad18b5ec1d7faf496..34ac47eb581e2c2b561d747ebd8bda6e034d92e6 100755 (executable)
@@ -274,24 +274,6 @@ case "$1" in
                exit 1
        esac
        ;;
-    getdebug)
-       case "${CTDB_DEBUGLEVEL:-0}" in
-           -3) _t="EMERG"  ;;
-           -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