Whamcloud - gitweb
LU-13580 tests: fix retrieval of SELinux context
[fs/lustre-release.git] / lustre / tests / sanity-selinux.sh
index 44ec962..7d9ef93 100755 (executable)
@@ -93,6 +93,13 @@ check_selinux_xattr() {
        echo $xattrval
 }
 
+get_sel_ctx() {
+       local file=$1
+
+       [ -n "$file" ] || return;
+       [ -f $file ] || return;
+       stat $file | awk '$1 == "Context:" {print $2}'
+}
 
 test_1() {
        local devname=$(mdsdevname 1)
@@ -230,7 +237,7 @@ test_5() {
 
        # get sec context
        ls -lZ $filename
-       local secctxseen=$(ls -lZ $filename | awk '{print $4}' | cut -d: -f3)
+       local secctxseen=$(get_sel_ctx $filename | cut -d: -f3)
 
        [ "$newsecctx" == "$secctxseen" ] ||
                error "sec context seen from 1st mount point is not correct"
@@ -254,7 +261,7 @@ test_10() {
 
        # get sec context from 1st mount point
        ls -lZ $filename1
-       local secctxseen=$(ls -lZ $filename1 | awk '{print $4}' | cut -d: -f3)
+       local secctxseen=$(get_sel_ctx $filename1 | cut -d: -f3)
 
        [ "$newsecctx" == "$secctxseen" ] ||
                error_ignore LU-6784 \
@@ -288,12 +295,12 @@ test_20a() {
 
        # get sec info on second mount point
        if [ -e "$filename2" ]; then
-               secinfo2=$(ls -lZ $filename2 | awk '{print $4}')
+               secinfo2=$(get_sel_ctx $filename2)
        fi
 
        # get sec info on first mount point
        wait $touchpid
-       secinfo1=$(ls -lZ $filename1 | awk '{print $4}')
+       secinfo1=$(get_sel_ctx $filename1)
 
        # compare sec contexts
        [ -z "$secinfo2" -o "$secinfo1" == "$secinfo2" ] ||
@@ -465,6 +472,7 @@ check_nodemap() {
        local nm=$1
        local key=$2
        local val=$3
+       local facets=""
        local i
 
        if [ "$nm" == "active" ]; then
@@ -472,17 +480,23 @@ check_nodemap() {
        else
                proc_param="$nm.$key"
        fi
-       is_sync=false
-       for i in $(seq 1 20); do
-               out=$(do_facet mds1 $LCTL get_param -n \
+       # check all MDS nodes, in reverse order to privilege remote ones first
+       for i in $(seq $MDSCOUNT); do
+               facets="mds$i $facets"
+       done
+       for facet in $facets; do
+               is_sync=false
+               for i in {1..20}; do
+                       out=$(do_facet $facet $LCTL get_param -n \
                                   nodemap.$proc_param 2>/dev/null)
-               echo "On mds1, ${proc_param} = $out"
-               [ "$val" == "$out" ] && is_sync=true && break
-               sleep 1
+                       echo "On $facet, ${proc_param} = $out"
+                       [ "$val" == "$out" ] && is_sync=true && break
+                       sleep 1
+               done
+               if ! $is_sync; then
+                       error "$proc_param not updated on $facet after 20 secs"
+               fi
        done
-       if ! $is_sync; then
-               error "$proc_param not updated on mds1 after 20 secs"
-       fi
 }
 
 create_nodemap() {
@@ -504,6 +518,7 @@ create_nodemap() {
        check_nodemap $nm admin_nodemap 1
        check_nodemap $nm trusted_nodemap 1
 
+       sleep 10
        sepol=$(l_getsepol | cut -d':' -f2- | xargs)
        do_facet mgs $LCTL set_param -P nodemap.$nm.sepol="$sepol"