From: Martin Schwenke Date: Mon, 29 Apr 2013 17:32:29 +0000 (+1000) Subject: eventscripts: Simplify handling of $service name in "managed" functions X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=27aab8783898a50da8c4bc887b512d8f0c0d842c;p=obnox%2Fctdb.git eventscripts: Simplify handling of $service name in "managed" functions Complicated argument handling was introduced to deal with multiple services per eventscript. This was a failure and we split 50.samba. This simplifies several functions to use global $service_name unconditionally instead of having an optional argument. $service_name is no automatically longer set in the functions file. This means it needs to be explicitly set in 13.per_ip_routing because this script uses ctdb_service_check_reconfigure(). Eventscript unit test infrastructure needs to set $service_name during fake service setup, and policy routing tests need to be updated accordingly. Signed-off-by: Martin Schwenke --- diff --git a/config/events.d/13.per_ip_routing b/config/events.d/13.per_ip_routing index fe97ffc5..4b13546d 100755 --- a/config/events.d/13.per_ip_routing +++ b/config/events.d/13.per_ip_routing @@ -6,6 +6,8 @@ . $CTDB_BASE/functions loadconfig +service_name=per_ip_routing + # Do nothing if unconfigured [ -n "$CTDB_PER_IP_ROUTING_CONF" ] || exit 0 diff --git a/config/functions b/config/functions index 245e47a1..edc7653c 100755 --- a/config/functions +++ b/config/functions @@ -1024,26 +1024,25 @@ ctdb_managed_dir="$CTDB_VARDIR/managed_history" _ctdb_managed_common () { - _service_name="${1:-${service_name}}" - _ctdb_managed_file="$ctdb_managed_dir/$_service_name" + _ctdb_managed_file="$ctdb_managed_dir/$service_name" } ctdb_service_managed () { - _ctdb_managed_common "$@" + _ctdb_managed_common mkdir -p "$ctdb_managed_dir" touch "$_ctdb_managed_file" } ctdb_service_unmanaged () { - _ctdb_managed_common "$@" + _ctdb_managed_common rm -f "$_ctdb_managed_file" } is_ctdb_previously_managed_service () { - _ctdb_managed_common "$@" + _ctdb_managed_common [ -f "$_ctdb_managed_file" ] } @@ -1469,6 +1468,5 @@ update_tickles () } script_name="${0##*/}" # basename -service_name="$script_name" # default is just the script name service_fail_limit=1 event_name="$1" diff --git a/tests/eventscripts/13.per_ip_routing.016.sh b/tests/eventscripts/13.per_ip_routing.016.sh index 485353e1..85320b65 100755 --- a/tests/eventscripts/13.per_ip_routing.016.sh +++ b/tests/eventscripts/13.per_ip_routing.016.sh @@ -9,7 +9,7 @@ setup_ctdb_policy_routing create_policy_routing_config 0 -ok 'Reconfiguring service "13.per_ip_routing"...' +ok "Reconfiguring service \"${service_name}\"..." simple_test_event "reconfigure" check_routes 0 diff --git a/tests/eventscripts/13.per_ip_routing.017.sh b/tests/eventscripts/13.per_ip_routing.017.sh index dcb436ac..88700155 100755 --- a/tests/eventscripts/13.per_ip_routing.017.sh +++ b/tests/eventscripts/13.per_ip_routing.017.sh @@ -10,7 +10,7 @@ setup_ctdb_policy_routing create_policy_routing_config 1 default # no takeip, but reconfigure should add any missing routes -ok 'Reconfiguring service "13.per_ip_routing"...' +ok "Reconfiguring service \"${service_name}\"..." simple_test_event "reconfigure" check_routes 1 default diff --git a/tests/eventscripts/13.per_ip_routing.018.sh b/tests/eventscripts/13.per_ip_routing.018.sh index 7a02b0c4..ce919890 100755 --- a/tests/eventscripts/13.per_ip_routing.018.sh +++ b/tests/eventscripts/13.per_ip_routing.018.sh @@ -16,7 +16,7 @@ simple_test_event "ipreallocated" create_policy_routing_config 1 default # reconfigure should update routes even though rules are unchanged -ok 'Reconfiguring service "13.per_ip_routing"...' +ok "Reconfiguring service \"${service_name}\"..." simple_test_event "reconfigure" check_routes 1 default diff --git a/tests/eventscripts/13.per_ip_routing.019.sh b/tests/eventscripts/13.per_ip_routing.019.sh index 2afee089..072c929d 100755 --- a/tests/eventscripts/13.per_ip_routing.019.sh +++ b/tests/eventscripts/13.per_ip_routing.019.sh @@ -18,7 +18,7 @@ simple_test_event "ipreallocated" create_policy_routing_config 1 # reconfigure should update routes even though rules are unchanged -ok 'Reconfiguring service "13.per_ip_routing"...' +ok "Reconfiguring service \""${service_name}\""..." simple_test_event "reconfigure" check_routes 1 diff --git a/tests/eventscripts/scripts/local.sh b/tests/eventscripts/scripts/local.sh index 9e746b52..5ce6b731 100644 --- a/tests/eventscripts/scripts/local.sh +++ b/tests/eventscripts/scripts/local.sh @@ -368,6 +368,8 @@ ctdb_fake_scriptstatus () setup_ctdb_policy_routing () { + service_name="per_ip_routing" + export CTDB_PER_IP_ROUTING_CONF="$CTDB_BASE/policy_routing" export CTDB_PER_IP_ROUTING_RULE_PREF=100 export CTDB_PER_IP_ROUTING_TABLE_ID_LOW=1000 @@ -455,11 +457,13 @@ setup_samba () { setup_ctdb + service_name="samba" + if [ "$1" != "down" ] ; then debug "Marking Samba services as up, listening and managed by CTDB" # Get into known state. - eventscript_call ctdb_service_managed "samba" + eventscript_call ctdb_service_managed # All possible service names for all known distros. for i in "smb" "nmb" "samba" ; do @@ -479,7 +483,7 @@ setup_samba () else debug "Marking Samba services as down, not listening and not managed by CTDB" # Get into known state. - eventscript_call ctdb_service_unmanaged "samba" + eventscript_call ctdb_service_unmanaged # All possible service names for all known distros. for i in "smb" "nmb" "samba" ; do @@ -503,11 +507,13 @@ setup_winbind () { setup_ctdb + service_name="winbind" + if [ "$1" != "down" ] ; then debug "Marking Winbind service as up and managed by CTDB" # Get into known state. - eventscript_call ctdb_service_managed "winbind" + eventscript_call ctdb_service_managed service "winbind" force-started @@ -518,7 +524,7 @@ setup_winbind () else debug "Marking Winbind service as down and not managed by CTDB" # Get into known state. - eventscript_call ctdb_service_unmanaged "winbind" + eventscript_call ctdb_service_unmanaged service "winbind" force-stopped @@ -543,6 +549,8 @@ setup_nfs () { setup_ctdb + service_name="nfs" + export FAKE_RPCINFO_SERVICES="" export CTDB_NFS_SKIP_SHARE_CHECK="no" @@ -556,7 +564,7 @@ setup_nfs () # Force this file to exist so tests can be individually run. if [ ! -f "$rpc_fail_limits_file" ] ; then # This is gross... but is needed to fake through the nfs monitor event. - eventscript_call ctdb_service_managed "nfs" + eventscript_call ctdb_service_managed service "nfs" force-started # might not be enough CTDB_RC_LOCAL="$CTDB_BASE/rc.local.nfs.monitor.get-limits" \ CTDB_MANAGES_NFS="yes" \ @@ -566,7 +574,7 @@ setup_nfs () if [ "$1" != "down" ] ; then debug "Setting up NFS environment: all RPC services up, NFS managed by CTDB" - eventscript_call ctdb_service_managed "nfs" + eventscript_call ctdb_service_managed service "nfs" force-started # might not be enough export CTDB_MANAGED_SERVICES="foo nfs bar" @@ -575,7 +583,7 @@ setup_nfs () else debug "Setting up NFS environment: all RPC services down, NFS not managed by CTDB" - eventscript_call ctdb_service_unmanaged "nfs" + eventscript_call ctdb_service_unmanaged service "nfs" force-stopped # might not be enough eventscript_call startstop_nfs stop @@ -732,12 +740,14 @@ Starting nfslock: OK" setup_vsftpd () { + service_name="vsftpd" + if [ "$1" != "down" ] ; then die "setup_vsftpd up not implemented!!!" else debug "Setting up VSFTPD environment: service down, not managed by CTDB" - eventscript_call ctdb_service_unmanaged vsftpd + eventscript_call ctdb_service_unmanaged service vsftpd force-stopped export CTDB_MANAGED_SERVICES="foo" @@ -756,9 +766,9 @@ setup_httpd () else debug "Setting up HTTPD environment: service down, not managed by CTDB" - for i in "apache2" "httpd" ; do - eventscript_call ctdb_service_unmanaged "$i" - service "$i" force-stopped + for service_name in "apache2" "httpd" ; do + eventscript_call ctdb_service_unmanaged + service "$service_name" force-stopped done export CTDB_MANAGED_SERVICES="foo"