From 2ada317c0992e27fc58f9744bdcf49e3a6c2d7a3 Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Thu, 11 Jul 2024 12:51:18 -0600 Subject: [PATCH] LU-18019 tests: Convert hostname to IP list modify h2name_or_ip to convert the specified hostname into a comma separated list of NIDs. If FORCE_LARGE_NID is true, and the host has IPv6 addresses, then only those IPv6 NIDs are listed. If it is false, and the host has IPv4 addresses, then only those IPv4 NIDs are listed. Otherwise, we list NIDs based on whichever addresses are present. h2name_or_ip() may be called prior to init_test_env, and in this case FORCE_LARGE_NID will not be initialized. Add FORCE_LARGE_NID to cfg/local.sh to ensure it is set before h2name_or_ip() is called. Signed-off-by: Chris Horn Change-Id: I0ef74eef5748d495e6b64f023c07d8eb4a23a5ed Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55707 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Frank Sehr Reviewed-by: Oleg Drokin --- lustre/tests/cfg/local.sh | 1 + lustre/tests/sanity-lnet.sh | 33 ----------------------- lustre/tests/test-framework.sh | 61 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/lustre/tests/cfg/local.sh b/lustre/tests/cfg/local.sh index bf0a2bc..d2d952c 100644 --- a/lustre/tests/cfg/local.sh +++ b/lustre/tests/cfg/local.sh @@ -74,6 +74,7 @@ OST_INDEX_LIST=${OST_INDEX_LIST:-} # The default index value of an individual OST is its facet number minus 1. # More specific ones override more general ones. See facet_index(). +FORCE_LARGE_NID=${FORCE_LARGE_NID:-false} NETTYPE=${NETTYPE:-tcp} MGSNID=${MGSNID:-$(h2nettype $mgs_HOST)} diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index 14e198b..be08658 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -246,39 +246,6 @@ validate_gateway_nids() { validate_nids } -# TODO: Switch to ipcalc if/when we need more sophisticated validation -ip_is_v4() { - local ipv4_re='^([0-9]{1,3}\.){3,3}[0-9]{1,3}$' - - if ! [[ $1 =~ $ipv4_re ]]; then - return 1 - fi - - local quads=(${1//\./ }) - - (( ${#quads[@]} == 4)) || return 1 - - (( quads[0] < 256 && quads[1] < 256 && - quads[2] < 256 && quads[3] < 256 )) || return 1 - - return 0 -} - -ip_is_v6() { - local ipv6_re='^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$' - - if ! [[ $1 =~ $ipv6_re ]]; then - return 1 - fi - - local segment - for segment in ${1//:/ }; do - ((0x$segment <= 0xFFFF)) || return 1 - done - - return 0 -} - intf_has_ipv6() { local addr=$(ip -o -6 a s "$1" | awk '{print $4}' | head -n 1 | grep -v '^fe80::' | sed 's,/[0-9]\+$,,') diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index da3e86e..595bf48 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -4357,9 +4357,66 @@ host_nids_address() { do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @" } +ip_is_v4() { + local ipv4_re='^([0-9]{1,3}\.){3,3}[0-9]{1,3}$' + + if ! [[ $1 =~ $ipv4_re ]]; then + return 1 + fi + + local quads=(${1//\./ }) + + (( ${#quads[@]} == 4)) || return 1 + + (( quads[0] < 256 && quads[1] < 256 && + quads[2] < 256 && quads[3] < 256 )) || return 1 + + return 0 +} + +ip_is_v6() { + local ipv6_re='^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$' + + if ! [[ $1 =~ $ipv6_re ]]; then + return 1 + fi + + local segment + for segment in ${1//:/ }; do + ((0x$segment <= 0xFFFF)) || return 1 + done + + return 0 +} + h2name_or_ip() { - if [ "$1" = "'*'" ]; then echo \'*\'; else - echo $1"@$2" + if [[ "$1" == '*' ]]; then + echo \'*\' + elif ip_is_v4 "$1" || ip_is_v6 "$1" ; then + echo "$1@$2" + else + local addr nidlist large_nidlist + local iplist=$(do_node $1 hostname -I | sed "s/$1://") + + for addr in ${iplist}; do + nid="${addr}@$2" + ip_is_v4 "$addr" && + nidlist="${nidlist:+$nidlist,}${nid}" || + large_nidlist="${large_nidlist:+$large_nidlist,}${nid}" + done + if [[ -n $nidlist ]] && [[ -n $large_nidlist ]]; then + if ${FORCE_LARGE_NID}; then + echo "$large_nidlist" + else + echo "$nidlist" + fi + elif [[ -n $nidlist ]]; then + echo "$nidlist" + elif [[ -n $large_nidlist ]]; then + echo "$large_nidlist" + else + echo "$1@$2" + fi fi } -- 1.8.3.1