]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(test): nfs_fetch_url test into nfs test
author“Masahiro <mmatsuya@redhat.com>
Tue, 7 Feb 2023 09:30:36 +0000 (18:30 +0900)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Fri, 24 Feb 2023 15:06:05 +0000 (10:06 -0500)
This is to check the behavior of nfs_fetch_url() in nfs-lib.sh.
nfs_fetch_url() calls nfs_already_mounted() internally.
A file /nfs/client/root/fetchfile is on NFS server, which is fetched
from clients for testing with nfs_fetch_url().

test/TEST-20-NFS/client-init.sh
test/TEST-20-NFS/test.sh

index c7e88314b233844c819102748e5bf71c38931679..061a2b15a5570ea8f2506ea76e2377dcff3a9945 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 : > /dev/watchdog
 . /lib/dracut-lib.sh
+. /lib/url-lib.sh
 
 export PATH=/usr/sbin:/usr/bin:/sbin:/bin
 command -v plymouth > /dev/null 2>&1 && plymouth --quit
@@ -23,6 +24,25 @@ while read -r dev _ fstype opts rest || [ -n "$dev" ]; do
     break
 done < /proc/mounts
 
+if [ "$fstype" = "nfs" -o "$fstype" = "nfs4" ]; then
+
+    serverip=${dev%:*}
+    path=${dev#*:}
+    echo serverip="${serverip}"
+    echo path="${path}"
+    echo /proc/mounts status
+    cat /proc/mounts
+
+    echo test:nfs_fetch_url nfs::"${serverip}":"${path}"/root/fetchfile
+    if nfs_fetch_url nfs::"${serverip}":"${path}"/root/fetchfile /run/nfsfetch.out; then
+        echo nfsfetch-OK
+        echo "nfsfetch-OK" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker2
+    fi
+else
+    echo nfsfetch-BYPASS fstype="${fstype}"
+    echo "nfsfetch-OK" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker2
+fi
+
 : > /dev/watchdog
 
 sync
index 9a943bab6bda479a3834dcf2e5e653b98c6d665b..33c8757a2fadffb342c7ab5aaa240903d2912d52 100755 (executable)
@@ -57,10 +57,12 @@ client_test() {
 
     # Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
     dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
+    dd if=/dev/zero of="$TESTDIR"/marker2.img bs=1MiB count=1
     declare -a disk_args=()
     # shellcheck disable=SC2034
     declare -i disk_index=0
     qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
+    qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker2.img marker2
     cmdline="$cmdline rd.net.timeout.dhcp=30"
 
     "$testdir"/run-qemu \
@@ -115,6 +117,11 @@ client_test() {
         return 1
     fi
 
+    if ! grep -U --binary-files=binary -F -m 1 -q nfsfetch-OK "$TESTDIR"/marker2.img; then
+        echo "CLIENT TEST END: $test_name [FAILED - NFS FETCH FAILED]"
+        return 1
+    fi
+
     echo "CLIENT TEST END: $test_name [OK]"
     return 0
 }
@@ -257,6 +264,7 @@ test_setup() {
         done
         type -P portmap > /dev/null && inst_multiple portmap
         type -P rpcbind > /dev/null && inst_multiple rpcbind
+
         [ -f /etc/netconfig ] && inst_multiple /etc/netconfig
         type -P dhcpd > /dev/null && inst_multiple dhcpd
         [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
@@ -302,6 +310,7 @@ test_setup() {
         (
             cd "$initdir" || exit
             mkdir -p dev sys proc etc run root usr var/lib/nfs/rpc_pipefs
+            echo "TEST FETCH FILE" > root/fetchfile
         )
 
         inst_multiple sh shutdown poweroff stty cat ps ln ip dd \
@@ -315,6 +324,9 @@ test_setup() {
 
         inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
         inst_simple "${basedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh"
+        inst_simple "${basedir}/modules.d/45url-lib/url-lib.sh" "/lib/url-lib.sh"
+        inst_simple "${basedir}/modules.d/40network/net-lib.sh" "/lib/net-lib.sh"
+        inst_simple "${basedir}/modules.d/95nfs/nfs-lib.sh" "/lib/nfs-lib.sh"
         inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util"
         ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
         ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"