summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2016-04-06 21:19:37 +1000
committerAmitay Isaacs <amitay@samba.org>2016-04-15 05:57:17 +0200
commite2ecdd2401585cdb7251791004c107ab5fa74bda (patch)
treed75d19885e48a142c37f9d47a99daae8612d46c6 /ctdb/tests
parent47a68ff440ceb3affb2dcca5bea79938a154f5be (diff)
downloadsamba-e2ecdd2401585cdb7251791004c107ab5fa74bda.tar.gz
ctdb-tests: Add ipvsadm test stub
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tests')
-rwxr-xr-xctdb/tests/eventscripts/stubs/ipvsadm126
1 files changed, 126 insertions, 0 deletions
diff --git a/ctdb/tests/eventscripts/stubs/ipvsadm b/ctdb/tests/eventscripts/stubs/ipvsadm
new file mode 100755
index 00000000000..0567f881e54
--- /dev/null
+++ b/ctdb/tests/eventscripts/stubs/ipvsadm
@@ -0,0 +1,126 @@
+#!/bin/sh
+
+die ()
+{
+ echo "$1" >&2
+ exit ${2:-1}
+}
+
+
+[ -n "$FAKE_LVS_STATE_DIR" ] || die "FAKE_LVS_STATE_DIR not set"
+
+
+service_address=""
+scheduling_method="wlc"
+persistent_timeout=""
+real_server=""
+forwarding_method="Route"
+
+set_service_address ()
+{
+ [ -z "$service_address" ] ||
+ die "multiple 'service-address' options specified" 2
+ case "$2" in
+ *:*) service_address="${1} ${2}" ;;
+ *) service_address="${1} ${2}:0" ;;
+ esac
+}
+
+set_real_server ()
+{
+ [ -z "$real_server" ] ||
+ die "multiple 'real-server' options specified" 2
+ case "$1" in
+ *\]:*) real_server="${1}" ;;
+ *\]) real_server="${1}:0" ;;
+ *:*) real_server="${1}" ;;
+ *) real_server="${1}:0" ;;
+ esac
+
+ case "$real_server" in
+ 127.0.0.1:*|\[::1\]:*) forwarding_method="Local" ;;
+ esac
+}
+
+case "$1" in
+-A)
+ shift
+ while [ -n "$1" ] ; do
+ case "$1" in
+ -t) set_service_address "TCP" "$2" ; shift 2 ;;
+ -u) set_service_address "UDP" "$2" ; shift 2 ;;
+ -s) scheduling_method="$2" ; shift 2 ;;
+ -p) persistent_timeout="persistent $2" ; shift 2 ;;
+ *) die "Unsupported -A option $1" ;;
+ esac
+ done
+ [ -n "$service_address" ] ||
+ die "You need to supply the 'service-address' option for the 'add-service' command" 2
+ d="${FAKE_LVS_STATE_DIR}/${service_address}"
+ mkdir "$d" 2>/dev/null || die "Service already exists" 255
+ t="${scheduling_method}${persistent_timeout:+ }${persistent_timeout}"
+ echo "$t" >"${d}/.info"
+ ;;
+-D)
+ shift
+ while [ -n "$1" ] ; do
+ case "$1" in
+ -t) set_service_address "TCP" "$2" ; shift 2 ;;
+ -u) set_service_address "UDP" "$2" ; shift 2 ;;
+ *) die "Unsupported -D option $1" ;;
+ esac
+ done
+ [ -n "$service_address" ] ||
+ die "You need to supply the 'service-address' option for the 'delete-service' command" 2
+ d="${FAKE_LVS_STATE_DIR}/${service_address}"
+ rm -f "${d}/"*
+ rm -f "${d}/.info"
+ rmdir "$d" 2>/dev/null || die "No such service" 255
+ ;;
+-a)
+ shift
+ while [ -n "$1" ] ; do
+ case "$1" in
+ -t) set_service_address "TCP" "$2" ; shift 2 ;;
+ -u) set_service_address "UDP" "$2" ; shift 2 ;;
+ -r) set_real_server "$2" ; shift 2 ;;
+ -g) forwarding_method="Route" ; shift 1 ;;
+ *) die "Unsupported -A option $1" ;;
+ esac
+ done
+ [ -n "$service_address" ] ||
+ die "You need to supply the 'service-address' option for the 'delete-service' command" 2
+ d="${FAKE_LVS_STATE_DIR}/${service_address}"
+ [ -d "$d" ] || die "Service not defined" 255
+ [ -n "$real_server" ] ||
+ die "You need to supply the 'real-server' option for the 'add-server' command" 2
+ f="${d}/${real_server}"
+ echo "$forwarding_method" >"$f"
+ ;;
+-l)
+ cat <<EOF
+IP Virtual Server version 1.2.1 (size=4096)
+Prot LocalAddress:Port Scheduler Flags
+ -> RemoteAddress:Port Forward Weight ActiveConn InActConn
+EOF
+ [ -d "$FAKE_LVS_STATE_DIR" ] || exit 0
+ (
+ cd "$FAKE_LVS_STATE_DIR"
+ for d in *; do
+ [ -d "$d" ] || continue
+ echo -n "$d "
+ cat "${d}/.info"
+ for f in "${d}/"* ; do
+ [ -f "$f" ] || continue
+ read forwarding_method <"$f"
+ printf " -> %-28s %-7s %-6s %-10s %-10s\n" \
+ "${f##*/}" "$forwarding_method" 1 0 0
+ done
+ done
+ )
+ ;;
+*)
+ die "Unknown option $1"
+esac
+
+exit 0