diff options
| author | Martin Schwenke <martin@meltin.net> | 2013-07-16 19:57:18 +1000 |
|---|---|---|
| committer | Martin Schwenke <martin@meltin.net> | 2013-07-19 15:37:14 +1000 |
| commit | 363315aca5447f92faeddb4da459d583ba03369a (patch) | |
| tree | 61e9a825f81d347687803c9b9d94dd90c0f7de9e /ctdb/tests/eventscripts | |
| parent | 1da757d91ae17ac37ba6c98a3ba6e63b69a287d5 (diff) | |
| download | samba-363315aca5447f92faeddb4da459d583ba03369a.tar.gz samba-363315aca5447f92faeddb4da459d583ba03369a.tar.xz samba-363315aca5447f92faeddb4da459d583ba03369a.zip | |
tests/eventscripts: Add tests for monitoring of missing interfaces
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 53e4eca74429f76adc81d98e3d11d1bd61194d71)
Diffstat (limited to 'ctdb/tests/eventscripts')
| -rwxr-xr-x | ctdb/tests/eventscripts/10.interface.monitor.015.sh | 16 | ||||
| -rwxr-xr-x | ctdb/tests/eventscripts/10.interface.monitor.016.sh | 18 | ||||
| -rw-r--r-- | ctdb/tests/eventscripts/scripts/local.sh | 2 | ||||
| -rwxr-xr-x | ctdb/tests/eventscripts/stubs/ip | 126 |
4 files changed, 108 insertions, 54 deletions
diff --git a/ctdb/tests/eventscripts/10.interface.monitor.015.sh b/ctdb/tests/eventscripts/10.interface.monitor.015.sh new file mode 100755 index 0000000000..1090cb9a55 --- /dev/null +++ b/ctdb/tests/eventscripts/10.interface.monitor.015.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Missing interface, fail" + +setup_ctdb + +iface=$(ctdb_get_1_interface) +ip link delete "$iface" + +required_result 1 <<EOF +ERROR: Interface dev123 does not exist but it is used by public addresses. +EOF + +simple_test diff --git a/ctdb/tests/eventscripts/10.interface.monitor.016.sh b/ctdb/tests/eventscripts/10.interface.monitor.016.sh new file mode 100755 index 0000000000..6fd698a198 --- /dev/null +++ b/ctdb/tests/eventscripts/10.interface.monitor.016.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "Missing interface, CTDB_PARTIALLY_ONLINE_INTERFACES=yes, warn" + +setup_ctdb + +CTDB_PARTIALLY_ONLINE_INTERFACES="yes" + +iface=$(ctdb_get_1_interface) +ip link delete "$iface" + +ok <<EOF +ERROR: Interface dev123 does not exist but it is used by public addresses. +EOF + +simple_test diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh index 6d1d52763a..e7892a0a71 100644 --- a/ctdb/tests/eventscripts/scripts/local.sh +++ b/ctdb/tests/eventscripts/scripts/local.sh @@ -304,6 +304,8 @@ setup_ctdb () export FAKE_CTDB_SCRIPTSTATUS="$FAKE_CTDB_STATE/scriptstatus" mkdir -p "$FAKE_CTDB_SCRIPTSTATUS" rm -f "$FAKE_CTDB_SCRIPTSTATUS"/* + + export CTDB_PARTIALLY_ONLINE_INTERFACES } ctdb_get_interfaces () diff --git a/ctdb/tests/eventscripts/stubs/ip b/ctdb/tests/eventscripts/stubs/ip index fb7e8b6c6d..053da750b9 100755 --- a/ctdb/tests/eventscripts/stubs/ip +++ b/ctdb/tests/eventscripts/stubs/ip @@ -10,28 +10,64 @@ not_implemented () ip_link () { - case "$2" in + case "$1" in set) - # iface="$3" - case "$4" in - up) ip_link_set_up "$@" ;; - down) ip_link_down_up "$@" ;; - *) not_implemented "$*" ;; + shift + # iface="$1" + case "$2" in + up) ip_link_set_up "$1" ;; + down) ip_link_down_up "$1" ;; + *) not_implemented "\"$2\" in \"$orig_args\"" ;; esac ;; + show) shift ; ip_link_show "$@" ;; + del*) shift ; ip_link_delete "$@" ;; *) not_implemented "$*" ;; esac } +ip_link_delete () +{ + mkdir -p "${FAKE_IP_STATE}/interfaces-deleted" + touch "${FAKE_IP_STATE}/interfaces-deleted/$1" +} + ip_link_set_up () { - rm -f "${FAKE_IP_STATE}/interfaces-down/$3" + rm -f "${FAKE_IP_STATE}/interfaces-down/$1" + rm -f "${FAKE_IP_STATE}/interfaces-deleted/$1" } ip_link_set_down () { + rm -f "${FAKE_IP_STATE}/interfaces-deleted/$1" mkdir -p "${FAKE_IP_STATE}/interfaces-down" - touch "${FAKE_IP_STATE}/interfaces-down/$3" + touch "${FAKE_IP_STATE}/interfaces-down/$1" +} + +ip_link_show () +{ + dev="$1" + if [ "$dev" = "dev" -a -n "$2" ] ; then + dev="$2" + fi + + if [ -e "${FAKE_IP_STATE}/interfaces-deleted/$dev" ] ; then + echo "Device \"${dev}\" does not exist." >&2 + exit 255 + fi + + mac=$(echo $dev | md5sum | sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@') + _state="UP" + _flags=",UP,LOWER_UP" + if [ -e "${FAKE_IP_STATE}/interfaces-down/$dev" ] ; then + _state="DOWN" + _flags="" + fi + cat <<EOF +${n}: ${dev}: <BROADCAST,MULTICAST${_flags}> mtu 1500 qdisc pfifo_fast state ${_state} qlen 1000 + link/ether ${mac} brd ff:ff:ff:ff:ff:ff +EOF } # This is incomplete because it doesn't actually look up table ids in @@ -63,7 +99,7 @@ ip_check_table () exit 255 fi ;; - *) not_implemented "table=${_table} in ${_args}" ;; + *) not_implemented "table=${_table} ${orig_args}" ;; esac } @@ -71,19 +107,16 @@ ip_check_table () ip_addr () { - case "$2" in - show|list|"") ip_addr_show "$@" ;; - add*) ip_addr_add "$@" ;; - del*) ip_addr_del "$@" ;; - *) not_implemented "$*" ;; + case "$1" in + show|list|"") shift ; ip_addr_show "$@" ;; + add*) shift ; ip_addr_add "$@" ;; + del*) shift ; ip_addr_del "$@" ;; + *) not_implemented "\"$1\" in \"$orig_args\"" ;; esac } ip_addr_show () { - _args="$*" - - shift 2 dev="" primary=true secondary=true @@ -128,11 +161,7 @@ ip_addr_show () { pf="${FAKE_IP_STATE}/addresses/${dev}-primary" sf="${FAKE_IP_STATE}/addresses/${dev}-secondary" - mac=$(echo $dev | md5sum | sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@') - cat <<EOF -${n}: ${dev}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 - link/ether ${mac} brd ff:ff:ff:ff:ff:ff -EOF + ip_link_show "$dev" if $primary && [ -r "$pf" ] ; then read local <"$pf" if [ -z "$_to" -o "${_to%/*}" = "${local%/*}" ] ; then @@ -170,9 +199,6 @@ EOF ip_addr_add () { - _args="$*" - - shift 2 local="" dev="" brd="" @@ -221,7 +247,6 @@ ip_addr_add () ip_addr_del () { - shift 2 local="" dev="" while [ -n "$1" ] ; do @@ -266,11 +291,11 @@ ip_addr_del () ip_rule () { - case "$2" in - show|list|"") ip_rule_show "$@" ;; - add*) ip_rule_add "$@" ;; - del*) ip_rule_del "$@" ;; - *) not_implemented "$2 in \"$*\"" ;; + case "$1" in + show|list|"") shift ; ip_rule_show "$@" ;; + add) shift ; ip_rule_add "$@" ;; + del*) shift ; ip_rule_del "$@" ;; + *) not_implemented "$1 in \"$orig_args\"" ;; esac } @@ -318,9 +343,6 @@ ip_rule_show () ip_rule_common () { - _args="$*" - - shift 2 _from="" _pre="" _table="" @@ -329,7 +351,7 @@ ip_rule_common () from) _from="$2" ; shift 2 ;; pref) _pre="$2" ; shift 2 ;; table) _table="$2" ; shift 2 ;; - *) not_implemented "$1 in \"$_args\"" ;; + *) not_implemented "$1 in \"$orig_args\"" ;; esac done @@ -387,19 +409,17 @@ ip_rule_del () ip_route () { - case "$2" in - show|list) ip_route_show "$@" ;; - flush) ip_route_flush "$@" ;; - add) ip_route_add "$@" ;; - *) not_implemented "$2 in \"$*\"" ;; + case "$1" in + show|list) shift ; ip_route_show "$@" ;; + flush) shift ; ip_route_flush "$@" ;; + add) shift ; ip_route_add "$@" ;; + *) not_implemented "$1 in \"ip route\"" ;; esac } ip_route_common () { - _args="$*" - shift 2 - [ "$1" = table ] || not_implemented "$1 in \"$_args\"" + [ "$1" = table ] || not_implemented "$1 in \"$orig_args\"" _table="$2" ip_check_table "route" @@ -427,10 +447,6 @@ ip_route_flush () ip_route_add () { - _args="$*" - - shift 2 - _prefix="" _dev="" _gw="" @@ -443,13 +459,13 @@ ip_route_add () dev) _dev="$2" ; shift 2 ;; via) _gw="$2" ; shift 2 ;; table) _table="$2" ; shift 2 ;; - *) not_implemented "$1 in \"$_args\"" ;; + *) not_implemented "$1 in \"$orig_args\"" ;; esac done ip_check_table "route" - [ -n "$_prefix" ] || not_implemented "ip route without inet prefix in \"$_args\"" - [ -n "$_dev" ] || not_implemented "ip route without \"dev\" in \"$_args\"" + [ -n "$_prefix" ] || not_implemented "ip route without inet prefix in \"$orig_args\"" + [ -n "$_dev" ] || not_implemented "ip route without \"dev\" in \"$orig_args\"" # Alias or add missing bits case "$_prefix" in @@ -476,11 +492,13 @@ ip_route_add () ###################################################################### +orig_args="$*" + case "$1" in - link) ip_link "$@" ;; - addr*) ip_addr "$@" ;; - rule) ip_rule "$@" ;; - route) ip_route "$@" ;; + link) shift ; ip_link "$@" ;; + addr*) shift ; ip_addr "$@" ;; + rule) shift ; ip_rule "$@" ;; + route) shift ; ip_route "$@" ;; *) not_implemented "$1" ;; esac |
