chore(ci): debug oe_test_nfs
This commit is contained in:
@@ -38,56 +38,76 @@ function pre_test() {
|
||||
export LANG=en_US.UTF-8
|
||||
DNF_INSTALL "nfs-utils nfs4-acl-tools diffutils"
|
||||
useradd $test_user
|
||||
mkdir $server_dir $client_dir
|
||||
test -f /etc/exports && cp /etc/exports .
|
||||
echo "$server_dir *(rw,sync,no_root_squash)" >>/etc/exports
|
||||
exportfs -avr
|
||||
mkdir -p $server_dir $client_dir
|
||||
chmod 755 $server_dir $client_dir
|
||||
|
||||
test -f /etc/exports && cp /etc/exports ./exports.bak
|
||||
|
||||
echo "$server_dir *(rw,sync,no_root_squash,no_subtree_check)" > /etc/exports
|
||||
exportfs -rav
|
||||
CHECK_RESULT $?
|
||||
|
||||
systemctl enable --now nfs-server rpcbind
|
||||
CHECK_RESULT $?
|
||||
|
||||
sleep 2
|
||||
|
||||
systemctl is-active nfs-server | grep -q active
|
||||
CHECK_RESULT $? "nfs-server service is not running"
|
||||
|
||||
systemctl is-active rpcbind | grep -q active
|
||||
CHECK_RESULT $? "rpcbind service is not running"
|
||||
|
||||
LOG_INFO "End of environmental preparation!"
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "Start testing..."
|
||||
systemctl restart nfs-server
|
||||
CHECK_RESULT $?
|
||||
systemctl status nfs-server | grep 'Active: active'
|
||||
CHECK_RESULT $?
|
||||
systemctl restart rpcbind
|
||||
CHECK_RESULT $?
|
||||
systemctl status rpcbind | grep 'Active: active'
|
||||
CHECK_RESULT $?
|
||||
|
||||
showmount -e localhost | grep -w "$server_dir"
|
||||
CHECK_RESULT $?
|
||||
CHECK_RESULT $? "showmount failed to display export directory"
|
||||
|
||||
mount -t nfs4 localhost:$server_dir $client_dir
|
||||
CHECK_RESULT $?
|
||||
echo "$$" >$client_dir/file
|
||||
CHECK_RESULT $? "Failed to mount NFS share"
|
||||
|
||||
echo "$$" > $client_dir/file
|
||||
CHECK_RESULT $? "Failed to write file to NFS mount"
|
||||
|
||||
diff $server_dir/file $client_dir/file
|
||||
CHECK_RESULT $?
|
||||
CHECK_RESULT $? "File content mismatch between server and client"
|
||||
|
||||
chmod 640 $client_dir/file
|
||||
sudo -u $test_user cat $client_dir/file 2>/tmp/error.log && return 1
|
||||
grep "Permission denied" /tmp/error.log
|
||||
CHECK_RESULT $?
|
||||
grep -q "Permission denied" /tmp/error.log
|
||||
CHECK_RESULT $? "Expected permission denied error not found"
|
||||
|
||||
uid=$(id -u $test_user)
|
||||
nfs4_setfacl -a "A::${uid}:r" $client_dir/file
|
||||
CHECK_RESULT $?
|
||||
CHECK_RESULT $? "Failed to set NFS4 ACL"
|
||||
|
||||
nfs4_getfacl $client_dir/file | grep "A::${uid}:r"
|
||||
CHECK_RESULT $?
|
||||
CHECK_RESULT $? "NFS4 ACL verification failed"
|
||||
|
||||
sudo -u $test_user cat $client_dir/file
|
||||
CHECK_RESULT $? "User cannot read file with ACL permissions"
|
||||
|
||||
umount $client_dir
|
||||
CHECK_RESULT $?
|
||||
CHECK_RESULT $? "Failed to unmount NFS share"
|
||||
|
||||
LOG_INFO "Finish test!"
|
||||
}
|
||||
|
||||
function post_test() {
|
||||
LOG_INFO "start environment cleanup."
|
||||
umount $client_dir
|
||||
umount $client_dir 2>/dev/null || true
|
||||
rm -rf $client_dir $server_dir
|
||||
userdel -r $test_user
|
||||
userdel -r $test_user 2>/dev/null || true
|
||||
rm -f /tmp/error.log
|
||||
test -f exports && mv exports /etc/exports
|
||||
test -f exports.bak && mv exports.bak /etc/exports || rm -f /etc/exports
|
||||
exportfs -rav 2>/dev/null || true
|
||||
DNF_REMOVE "$@"
|
||||
export LANG=${OLD_LANG}
|
||||
LOG_INFO "Finish environment cleanup!"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user