summaryrefslogtreecommitdiffstats
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2013-04-30 03:32:29 +1000
committerAmitay Isaacs <amitay@gmail.com>2013-05-06 15:45:10 +1000
commite9abc9c070368a81771a541701b03f75da1c5352 (patch)
treeef3bfdec6b20da2f05b5cd11d98be03492646b79 /ctdb
parentc56acf71277dc269f17c239acab7a46c982dea51 (diff)
downloadsamba-e9abc9c070368a81771a541701b03f75da1c5352.tar.gz
samba-e9abc9c070368a81771a541701b03f75da1c5352.tar.xz
samba-e9abc9c070368a81771a541701b03f75da1c5352.zip
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 <martin@meltin.net> (This used to be ctdb commit 27aab8783898a50da8c4bc887b512d8f0c0d842c)
Diffstat (limited to 'ctdb')
-rwxr-xr-xctdb/config/events.d/13.per_ip_routing2
-rwxr-xr-xctdb/config/functions10
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.016.sh2
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.017.sh2
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.018.sh2
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.019.sh2
-rw-r--r--ctdb/tests/eventscripts/scripts/local.sh32
7 files changed, 31 insertions, 21 deletions
diff --git a/ctdb/config/events.d/13.per_ip_routing b/ctdb/config/events.d/13.per_ip_routing
index fe97ffc586d..4b13546d274 100755
--- a/ctdb/config/events.d/13.per_ip_routing
+++ b/ctdb/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/ctdb/config/functions b/ctdb/config/functions
index 245e47a1f74..edc7653cbdf 100755
--- a/ctdb/config/functions
+++ b/ctdb/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/ctdb/tests/eventscripts/13.per_ip_routing.016.sh b/ctdb/tests/eventscripts/13.per_ip_routing.016.sh
index 485353e1bc2..85320b65487 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.016.sh
+++ b/ctdb/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/ctdb/tests/eventscripts/13.per_ip_routing.017.sh b/ctdb/tests/eventscripts/13.per_ip_routing.017.sh
index dcb436ac66a..8870015501f 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.017.sh
+++ b/ctdb/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/ctdb/tests/eventscripts/13.per_ip_routing.018.sh b/ctdb/tests/eventscripts/13.per_ip_routing.018.sh
index 7a02b0c4985..ce919890c0b 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.018.sh
+++ b/ctdb/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/ctdb/tests/eventscripts/13.per_ip_routing.019.sh b/ctdb/tests/eventscripts/13.per_ip_routing.019.sh
index 2afee089a05..072c929d8b4 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.019.sh
+++ b/ctdb/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/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh
index 9e746b52d1b..5ce6b731611 100644
--- a/ctdb/tests/eventscripts/scripts/local.sh
+++ b/ctdb/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"