Whamcloud - gitweb
LU-728 tests: pdsh HOSTLIST test suite support
authorJames Simmons <uja.ornl@gmail.com>
Thu, 29 Dec 2011 17:10:41 +0000 (12:10 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 4 Jan 2012 13:27:14 +0000 (08:27 -0500)
For large systems it becomes tedious to list all the nodes
or devices. The application pdsh uses a HOSTLIST form to
make listing nodes more compact. This patch takes data in
the HOSTLIST format and creates a expanded list for the
shell scripts in the test suite to use. Also this gives the
option for the pdsh commands to use the nodes list in
HOSTLIST format directly. Its is also possible to use the
HOSTLIST format for devices as well as nodes.

Signed-off-by: James Simmons <uja.ornl@gmail.com>
Change-Id: Ia7a6c95ab4e701a17fc2b80d8443a5ff79da3f3c
Reviewed-on: http://review.whamcloud.com/1462
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Yu Jian <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/test-framework.sh

index 0e5fa31..06224d3 100644 (file)
@@ -139,7 +139,7 @@ init_test_env() {
         export LOGDIR=${LOGDIR:-${TMP}/test_logs/}/$(date +%s)
         export LOGDIRSET=true
     fi
-    export HOSTNAME=${HOSTNAME:-`hostname`}
+    export HOSTNAME=${HOSTNAME:-$(hostname -s)}
     if ! echo $PATH | grep -q $LUSTRE/utils; then
         export PATH=$LUSTRE/utils:$PATH
     fi
@@ -691,7 +691,7 @@ stop() {
     local mntpt=$(facet_mntpt $facet)
     running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
     if [ ${running} -ne 0 ]; then
-        echo "Stopping $mntpt (opts:$@)"
+        echo "Stopping $mntpt (opts:$@) on $HOST"
         do_facet ${facet} umount -d $@ $mntpt
     fi
 
@@ -1667,6 +1667,95 @@ h2o2ib() {
 }
 declare -fx h2o2ib
 
+# This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
+# expressions format. As a bonus we can then just pass in those variables
+# to pdsh. What this function does is take a HOSTLIST type string and
+# expand it into a space deliminated list for us.
+hostlist_expand() {
+    local hostlist=$1
+    local offset=$2
+    local myList
+    local item
+    local list
+
+    [ -z "$hostlist" ] && return
+
+    # Translate the case of [..],..,[..] to [..] .. [..]
+    list="${hostlist/],/] }"
+    front=${list%%[*}
+    [[ "$front" == *,* ]] && {
+        new="${list%,*} "
+        old="${list%,*},"
+        list=${list/${old}/${new}}
+    }
+
+    for item in $list; do
+        # Test if we have any []'s at all
+        if [ "$item" != "${item/\[/}" ]; then {
+            # Expand the [*] into list
+            name=${item%%[*}
+            back=${item#*]}
+
+            if [ "$name" != "$item" ]; then
+                group=${item#$name[*}
+                group=${group%%]*}
+
+                for range in ${group//,/ }; do
+                    begin=${range%-*}
+                    end=${range#*-}
+
+                    # Number of leading zeros
+                    padlen=${#begin}
+                    padlen2=${#end}
+                    end=$(echo $end | sed 's/0*//')
+                    [[ -z "$end" ]] && end=0
+                    [[ $padlen2 -gt $padlen ]] && {
+                        [[ $padlen2 -eq ${#end} ]] && padlen2=0
+                        padlen=$padlen2
+                    }
+                    begin=$(echo $begin | sed 's/0*//')
+                    [ -z $begin ] && begin=0
+
+                    for num in $(seq -f "%0${padlen}g" $begin $end); do
+                        value="${name#*,}${num}${back}"
+                        [ "$value" != "${value/\[/}" ] && {
+                            value=$(hostlist_expand "$value")
+                        }
+                        myList="$myList $value"
+                    done
+                done
+            fi
+        } else {
+            myList="$myList $item"
+        } fi
+    done
+    myList=${myList//,/ }
+    myList=${myList:1} # Remove first character which is a space
+
+    # Filter any duplicates without sorting
+    list="$myList "
+    myList="${list%% *}"
+
+    while [[ "$list" != ${myList##* } ]]; do
+        list=${list//${list%% *} /}
+        myList="$myList ${list%% *}"
+    done
+    myList="${myList%* }";
+
+    # We can select an object at a offset in the list
+    [ $# -eq 2 ] && {
+        cnt=0
+        for item in $myList; do
+            let cnt=cnt+1
+            [ $cnt -eq $offset ] && {
+                myList=$item
+            }
+        done
+        [ $(get_node_count $myList) -ne 1 ] && myList=""
+    }
+    echo $myList
+}
+
 facet_host() {
     local facet=$1
 
@@ -3459,19 +3548,20 @@ remote_nodes_list () {
 
 init_clients_lists () {
     # Sanity check: exclude the local client from RCLIENTS
-    local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
+    local clients=$(hostlist_expand "$RCLIENTS")
+    local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
 
     # Sanity check: exclude the dup entries
-    rclients=$(for i in $rclients; do echo $i; done | sort -u)
+    RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
 
-    local clients="$SINGLECLIENT $HOSTNAME $rclients"
+    clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
 
     # Sanity check: exclude the dup entries from CLIENTS
     # for those configs which has SINGLCLIENT set to local client
     clients=$(for i in $clients; do echo $i; done | sort -u)
 
-    CLIENTS=`comma_list $clients`
-    local -a remoteclients=($rclients)
+    CLIENTS=$(comma_list $clients)
+    local -a remoteclients=($RCLIENTS)
     for ((i=0; $i<${#remoteclients[@]}; i++)); do
             varname=CLIENT$((i + 2))
             eval $varname=${remoteclients[i]}