Whamcloud - gitweb
LU-13580 tests: fix retrieval of SELinux context 48/38648/6
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 18 May 2020 09:43:22 +0000 (11:43 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 16 Jun 2020 15:28:37 +0000 (15:28 +0000)
Use 'stat' command instead of 'ls -lZ' to retrieve SELinux security
context, to make it more portable.

Test-Parameters: trivial clientselinux testlist=sanity-selinux mdtcount=2 clientcount=2
Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Change-Id: I61bc0efb1e8ae0427d05827e2933eb0b848fb442
Reviewed-on: https://review.whamcloud.com/38648
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-selinux.sh

index 8f0869a..7d9ef93 100755 (executable)
@@ -93,6 +93,13 @@ check_selinux_xattr() {
        echo $xattrval
 }
 
        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)
 
 test_1() {
        local devname=$(mdsdevname 1)
@@ -230,7 +237,7 @@ test_5() {
 
        # get sec context
        ls -lZ $filename
 
        # 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"
 
        [ "$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
 
        # 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 \
 
        [ "$newsecctx" == "$secctxseen" ] ||
                error_ignore LU-6784 \
@@ -288,12 +295,12 @@ test_20a() {
 
        # get sec info on second mount point
        if [ -e "$filename2" ]; then
 
        # 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
        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" ] ||
 
        # compare sec contexts
        [ -z "$secinfo2" -o "$secinfo1" == "$secinfo2" ] ||