Whamcloud - gitweb
LU-18019 tests: Convert hostname to IP list 07/55707/9
authorChris Horn <chris.horn@hpe.com>
Thu, 11 Jul 2024 18:51:18 +0000 (12:51 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 31 Jul 2024 16:07:31 +0000 (16:07 +0000)
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 <chris.horn@hpe.com>
Change-Id: I0ef74eef5748d495e6b64f023c07d8eb4a23a5ed
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55707
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/cfg/local.sh
lustre/tests/sanity-lnet.sh
lustre/tests/test-framework.sh

index bf0a2bc..d2d952c 100644 (file)
@@ -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)}
 
index 14e198b..be08658 100755 (executable)
@@ -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]\+$,,')
index da3e86e..595bf48 100755 (executable)
@@ -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
 }