From: Martin Schwenke Date: Mon, 13 Apr 2026 04:18:28 +0000 (+1000) Subject: ctdb-tests: Implement altname property for ip link/addr X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65bb57ebf486692705efcf395f06be4c41261047;p=thirdparty%2Fsamba.git ctdb-tests: Implement altname property for ip link/addr Only implemented for these commands. I don't even want to think about doing this for ip route right now. Signed-off-by: Martin Schwenke Reviewed-by: John Mulligan --- diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ip b/ctdb/tests/UNIT/eventscripts/stubs/ip index 71feb3a7fd0..3b74e6e25f4 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ip +++ b/ctdb/tests/UNIT/eventscripts/stubs/ip @@ -37,10 +37,28 @@ ip_link() shift ip_link_delete "$@" ;; + prop*) + shift + ip_link_property "$@" + ;; *) not_implemented "$*" ;; esac } +# updates $dev +convert_altname_dev() +{ + for _t in "${FAKE_IP_STATE}/altname/"*"/${dev}"; do + if [ -e "$_t" ]; then + _t="${_t%/*}" # dirname + dev="${_t##*/}" # basename + return 0 + fi + done + + return 1 +} + ip_link_add() { _link="" @@ -87,6 +105,8 @@ ip_link_delete() mkdir -p "${FAKE_IP_STATE}/interfaces-deleted" touch "${FAKE_IP_STATE}/interfaces-deleted/$1" rm -f "${FAKE_IP_STATE}/interfaces-vlan/$1" + rm -rf "${FAKE_IP_STATE}/altname/$1" + } ip_link_set_up() @@ -114,6 +134,8 @@ ip_link_show() exit 255 fi + convert_altname_dev + if [ -r "${FAKE_IP_STATE}/interfaces-vlan/${dev}" ]; then read -r _link <"${FAKE_IP_STATE}/interfaces-vlan/${dev}" dev="${dev}@${_link}" @@ -149,7 +171,36 @@ ip_link_show() else echo "${n:-42}: ${dev}: ${_status} ${_opts}" echo " link/${_type} ${_mac} brd ${_brd}" + for _altname in "${FAKE_IP_STATE}/altname/${dev}/"*; do + if [ -e "$_altname" ]; then + echo " altname ${_altname##*/}" # basename + fi + done + fi +} + +ip_link_property() +{ + _t="ip link property" + if [ $# -ne 5 ]; then + not_implemented "${_t} without \"add\"" + fi + if [ "$1" != "add" ] || [ "$2" != "dev" ] || [ "$4" != "altname" ]; then + not_implemented \ + "${_t} without \"add dev altname \"" fi + + dev="$3" + _altname="$5" + + if convert_altname_dev; then + echo "RTNETLINK answers: File exists" >&2 + exit 2 + fi + + # Each device can multiple altname properties, each specified + # by a subdirectory + mkdir -p "${FAKE_IP_STATE}/altname/${dev}/${_altname}" } # This is incomplete because it doesn't actually look up table ids in @@ -247,6 +298,7 @@ ip_addr_show() ;; esac done + convert_altname_dev devices="$dev" if [ -z "$devices" ]; then # No device specified? Get all the primaries... @@ -403,6 +455,7 @@ ip_addr_add() if [ -z "$dev" ]; then not_implemented "addr add (without dev)" fi + convert_altname_dev mkdir -p "${FAKE_IP_STATE}/addresses" net_str=$(ipv4_host_addr_to_net "$local") net_str=$(echo "$net_str" | sed -e 's@/@_@') @@ -449,6 +502,7 @@ ip_addr_del() if [ -z "$dev" ]; then not_implemented "addr del (without dev)" fi + convert_altname_dev mkdir -p "${FAKE_IP_STATE}/addresses" net_str=$(ipv4_host_addr_to_net "$local") net_str=$(echo "$net_str" | sed -e 's@/@_@')