eventscripts: Simplify handling of $service name in "managed" functions
authorMartin Schwenke <martin@meltin.net>
Mon, 29 Apr 2013 17:32:29 +0000 (03:32 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 6 May 2013 05:45:10 +0000 (15:45 +1000)
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 <martin@meltin.net>
(This used to be ctdb commit 27aab8783898a50da8c4bc887b512d8f0c0d842c)

ctdb/config/events.d/13.per_ip_routing
ctdb/config/functions
ctdb/tests/eventscripts/13.per_ip_routing.016.sh
ctdb/tests/eventscripts/13.per_ip_routing.017.sh
ctdb/tests/eventscripts/13.per_ip_routing.018.sh
ctdb/tests/eventscripts/13.per_ip_routing.019.sh
ctdb/tests/eventscripts/scripts/local.sh

index fe97ffc586d2c26b01f9ffbb146ea2d2279d37bf..4b13546d2746b6e85982f83a1b0ecfbcca6da54e 100755 (executable)
@@ -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
 
index 245e47a1f74dc83f2d5d021f7181a69c434361b5..edc7653cbdf350bbe77ab034a71926f50d0717ab 100755 (executable)
@@ -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"
index 485353e1bc216f7bed290bc9cb24a8bac8f243d9..85320b65487fd29603b37dcc04d3f265c5b6e5dd 100755 (executable)
@@ -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
index dcb436ac66a6abc83d54df8d90773ea92f52b4f9..8870015501f2a829d0ad13da4a7fd0ec4b7fbac6 100755 (executable)
@@ -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
index 7a02b0c49854bedb1c29f42ec39f244a4e21d39b..ce919890c0b60bc7fd4657e371d5d23d357a91cf 100755 (executable)
@@ -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
index 2afee089a05105714b959126068e96cdcb5038a3..072c929d8b4f719bd9e4c315101de02a7bc490da 100755 (executable)
@@ -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
index 9e746b52d1b325c62f9b6440fa6919b3e42494f9..5ce6b7316114e385f681d3b2bfbce111b6dd368a 100644 (file)
@@ -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"