Whamcloud - gitweb
LU-8055 ldev: File system label filtering
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
index 48252bf..000be7a 100755 (executable)
@@ -6345,7 +6345,7 @@ generate_ldev_conf() {
        printf "%s\t-\t%s-MGS0000\t%s\n" \
                $mgs_HOST \
                $FSNAME \
        printf "%s\t-\t%s-MGS0000\t%s\n" \
                $mgs_HOST \
                $FSNAME \
-               $(mgsdevname) >> $ldevconfpath
+               $(mgsdevname) > $ldevconfpath
 
        local mdsfo_host=$mdsfailover_HOST;
        if [ -z "$mdsfo_host" ]; then
 
        local mdsfo_host=$mdsfailover_HOST;
        if [ -z "$mdsfo_host" ]; then
@@ -6374,6 +6374,11 @@ generate_ldev_conf() {
                        $num \
                        $(ostdevname $num) >> $ldevconfpath
        done
                        $num \
                        $(ostdevname $num) >> $ldevconfpath
        done
+
+       echo "----- $ldevconfpath -----"
+       cat $ldevconfpath
+       echo "--- END $ldevconfpath ---"
+
 }
 
 generate_nids() {
 }
 
 generate_nids() {
@@ -6381,11 +6386,37 @@ generate_nids() {
        # looks like we only have the MGS nid available to us
        # so just echo that to a file
        local nidspath=$1
        # looks like we only have the MGS nid available to us
        # so just echo that to a file
        local nidspath=$1
-       touch $nidspath
-       echo -e "${mgs_HOST}\t${MGSNID}" >> $nidspath
+       echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
+
+       echo "----- $nidspath -----"
+       cat $nidspath
+       echo "--- END $nidspath ---"
+}
+
+compare_ldev_output() {
+       ldev_output=$1
+       expected_output=$2
+
+       sort $expected_output -o $expected_output
+       sort $ldev_output -o $ldev_output
+
+       echo "-- START OF LDEV OUTPUT --"
+       cat $ldev_output
+       echo "--- END OF LDEV OUTPUT ---"
+
+       echo "-- START OF EXPECTED OUTPUT --"
+       cat $expected_output
+       echo "--- END OF EXPECTED OUTPUT ---"
+
+       diff $expected_output $ldev_output
+       return $?
 }
 
 test_92() {
 }
 
 test_92() {
+       if [ -z "$LDEV" ]; then
+               error "ldev is missing!"
+       fi
+
        local LDEVCONFPATH=$TMP/ldev.conf
        local NIDSPATH=$TMP/nids
 
        local LDEVCONFPATH=$TMP/ldev.conf
        local NIDSPATH=$TMP/nids
 
@@ -6394,32 +6425,11 @@ test_92() {
        generate_ldev_conf $LDEVCONFPATH
        generate_nids $NIDSPATH
 
        generate_ldev_conf $LDEVCONFPATH
        generate_nids $NIDSPATH
 
-       echo "----- ldev.conf -----"
-       cat $LDEVCONFPATH
-       echo "--- END ldev.conf ---"
-
-       echo "----- /etc/nids -----"
-       cat $NIDSPATH
-       echo "--- END /etc/nids ---"
-
-       # ldev can be in our build tree and if we aren't in a
-       # build tree, use 'which' to try and find it
-       local LDEV=$LUSTRE/scripts/ldev
-       [ ! -f "$LDEV" ] && local LDEV=$(which ldev 2> /dev/null)
-
-       echo "ldev path is $LDEV"
-
-       if [ ! -f "$LDEV" ]; then
-               rm $LDEVCONFPATH $NIDSPATH
-               error "failed to find ldev!"
-       fi
-
        # echo the mgs nid and compare it to environment variable MGSNID
        # also, ldev.conf and nids is a server side thing, use the OSS
        # hostname
        local output
        # echo the mgs nid and compare it to environment variable MGSNID
        # also, ldev.conf and nids is a server side thing, use the OSS
        # hostname
        local output
-       output=$(perl $LDEV -c $LDEVCONFPATH -H \
-                       $ost_HOST -n $NIDSPATH echo %m)
+       output=$($LDEV -c $LDEVCONFPATH -H $ost_HOST -n $NIDSPATH echo %m)
 
        echo "-- START OF LDEV OUTPUT --"
        echo -e "$output"
 
        echo "-- START OF LDEV OUTPUT --"
        echo -e "$output"
@@ -6472,6 +6482,137 @@ test_93() {
 }
 run_test 93 "register mulitple MDT at the same time"
 
 }
 run_test 93 "register mulitple MDT at the same time"
 
+test_94() {
+       if [ -z "$LDEV" ]; then
+               error "ldev is missing!"
+       fi
+
+       local LDEVCONFPATH=$TMP/ldev.conf
+       local NIDSPATH=$TMP/nids
+
+       generate_ldev_conf $LDEVCONFPATH
+       generate_nids $NIDSPATH
+
+       local LDEV_OUTPUT=$TMP/ldev-output.txt
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
+
+       # ldev failed, error
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
+               error "ldev failed to execute!"
+       fi
+
+       # expected output
+       local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
+
+       printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
+
+       for num in $(seq $MDSCOUNT); do
+               printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
+       done
+
+       for num in $(seq $OSTCOUNT); do
+               printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
+       done
+
+       compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
+
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
+               error "ldev failed to produce the correct hostlist!"
+       fi
+
+       rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
+}
+run_test 94 "ldev outputs correct labels for file system name query"
+
+test_95() {
+       if [ -z "$LDEV" ]; then
+               error "ldev is missing!"
+       fi
+
+       local LDEVCONFPATH=$TMP/ldev.conf
+       local NIDSPATH=$TMP/nids
+
+       generate_ldev_conf $LDEVCONFPATH
+       generate_nids $NIDSPATH
+
+       # SUCCESS CASES
+       # file sys filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -F failed!"
+       fi
+
+       # local filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -l failed!"
+       fi
+
+       # foreign filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -f failed!"
+       fi
+
+       # all filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a failed!"
+       fi
+
+       # FAILURE CASES
+       # all & file sys
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a and -F incorrectly succeeded"
+       fi
+
+       # all & foreign
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a and -f incorrectly succeeded"
+       fi
+
+       # all & local
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a and -l incorrectly succeeded"
+       fi
+
+       # foreign & local
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -f and -l incorrectly succeeded"
+       fi
+
+       # file sys & local
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -F and -l incorrectly succeeded"
+       fi
+
+       # file sys & foreign
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -F and -f incorrectly succeeded"
+       fi
+
+       rm $LDEVCONFPATH $NIDSPATH
+}
+run_test 95 "ldev should only allow one label filter"
+
 if ! combined_mgs_mds ; then
        stop mgs
 fi
 if ! combined_mgs_mds ; then
        stop mgs
 fi