tests/complex: Fix NFS tests to work with root_squash
authorMartin Schwenke <martin@meltin.net>
Mon, 22 Jul 2013 04:32:13 +0000 (14:32 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 23 Jul 2013 01:28:07 +0000 (11:28 +1000)
Refactor the NFS test setup/cleanup code into new common functions.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit 29e98017221326bdc9b1c4f7c05b3b495c1de29b)

ctdb/tests/complex/43_failover_nfs_basic.sh
ctdb/tests/complex/44_failover_nfs_oneway.sh
ctdb/tests/complex/45_failover_nfs_kill.sh
ctdb/tests/scripts/integration.bash

index 71a822968f71d9e8e88e277a965078f29897a4f7..a68f7db6811eda8e14f0257c990f496ef442d0cc 100755 (executable)
@@ -49,22 +49,11 @@ cluster_is_healthy
 # Reset configuration
 ctdb_restart_when_done
 
-select_test_node_and_ips
-
-first_export=$(showmount -e $test_ip | sed -n -e '2s/ .*//p')
-mnt_d=$(mktemp -d)
-test_file="${mnt_d}/$RANDOM"
-
-ctdb_test_exit_hook_add rm -f "$test_file"
-ctdb_test_exit_hook_add umount -f "$mnt_d"
-ctdb_test_exit_hook_add rmdir "$mnt_d"
-
-echo "Mounting ${test_ip}:${first_export} on ${mnt_d} ..."
-mount -o timeo=1,hard,intr,vers=3 ${test_ip}:${first_export} ${mnt_d}
+nfs_test_setup
 
 echo "Create file containing random data..."
-dd if=/dev/urandom of=$test_file bs=1k count=1
-original_sum=$(sum $test_file)
+dd if=/dev/urandom of=$nfs_local_file bs=1k count=1
+original_sum=$(sum $nfs_local_file)
 [ $? -eq 0 ]
 
 gratarp_sniff_start
@@ -75,7 +64,7 @@ wait_until_node_has_status $test_node disabled
 
 gratarp_sniff_wait_show
 
-new_sum=$(sum $test_file)
+new_sum=$(sum $nfs_local_file)
 [ $? -eq 0 ]
 
 if [ "$original_md5" = "$new_md5" ] ; then
index 7da8d019ec3862e335bf57c6490da635a15ea2c8..aaec2ed9905992d2b8a41ce6b30f8cef62f968ca 100755 (executable)
@@ -51,31 +51,18 @@ cluster_is_healthy
 # Reset configuration
 ctdb_restart_when_done
 
-select_test_node_and_ips
+nfs_test_setup
 
-first_export=$(showmount -e $test_ip | sed -n -e '2s/ .*//p')
+echo "Create file containing random data..."
 local_f=$(mktemp)
-mnt_d=$(mktemp -d)
-nfs_f="${mnt_d}/$RANDOM"
-remote_f="${test_ip}:${first_export}/$(basename $nfs_f)"
-
 ctdb_test_exit_hook_add rm -f "$local_f"
-ctdb_test_exit_hook_add rm -f "$nfs_f"
-ctdb_test_exit_hook_add umount -f "$mnt_d"
-ctdb_test_exit_hook_add rmdir "$mnt_d"
-
-echo "Create file containing random data..."
 dd if=/dev/urandom of=$local_f bs=1k count=1
-chmod 644 "$local_f" # needed for *_squash?
 local_sum=$(sum $local_f)
-[ $? -eq 0 ]
-
-scp -p "$local_f" "$remote_f"
 
-echo "Mounting ${test_ip}:${first_export} on ${mnt_d} ..."
-mount -o timeo=1,hard,intr,vers=3 ${test_ip}:${first_export} ${mnt_d}
+scp -p "$local_f" "${test_ip}:${nfs_remote_file}"
+try_command_on_node $test_node "chmod 644 $nfs_remote_file"
 
-nfs_sum=$(sum $nfs_f)
+nfs_sum=$(sum $nfs_local_file)
 
 if [ "$local_sum" = "$nfs_sum" ] ; then
     echo "GOOD: file contents read correctly via NFS"
@@ -94,7 +81,7 @@ wait_until_node_has_status $test_node disabled
 
 gratarp_sniff_wait_show
 
-new_sum=$(sum $nfs_f)
+new_sum=$(sum $nfs_local_file)
 [ $? -eq 0 ]
 
 if [ "$nfs_sum" = "$new_sum" ] ; then
index f5510365301aa85a44301b61888d369a06e5720e..52b423fb12b29456b4bef1310e1fa7fffef56bec 100755 (executable)
@@ -49,22 +49,11 @@ cluster_is_healthy
 # Reset configuration
 ctdb_restart_when_done
 
-select_test_node_and_ips
-
-first_export=$(showmount -e $test_ip | sed -n -e '2s/ .*//p')
-mnt_d=$(mktemp -d)
-test_file="${mnt_d}/$RANDOM"
-
-ctdb_test_exit_hook_add rm -f "$test_file"
-ctdb_test_exit_hook_add umount -f "$mnt_d"
-ctdb_test_exit_hook_add rmdir "$mnt_d"
-
-echo "Mounting ${test_ip}:${first_export} on ${mnt_d} ..."
-mount -o timeo=1,hard,intr,vers=3 ${test_ip}:${first_export} ${mnt_d}
+nfs_test_setup
 
 echo "Create file containing random data..."
-dd if=/dev/urandom of=$test_file bs=1k count=1
-original_sum=$(sum $test_file)
+dd if=/dev/urandom of=$nfs_local_file bs=1k count=1
+original_sum=$(sum $nfs_local_file)
 [ $? -eq 0 ]
 
 gratarp_sniff_start
@@ -77,7 +66,7 @@ wait_until_node_has_status $test_node disconnected
 
 gratarp_sniff_wait_show
 
-new_sum=$(sum $test_file)
+new_sum=$(sum $nfs_local_file)
 [ $? -eq 0 ]
 
 if [ "$original_md5" = "$new_md5" ] ; then
index 95d67c3a35e0d513a134e19301e93a69b840ecc1..df93dcf6bbb4ef4122eba6e346c3c8cdb9248843 100644 (file)
@@ -949,6 +949,42 @@ wait_for_monitor_event ()
 
 }
 
+#######################################
+
+nfs_test_setup ()
+{
+    select_test_node_and_ips
+
+    nfs_first_export=$(showmount -e $test_ip | sed -n -e '2s/ .*//p')
+
+    echo "Creating test subdirectory..."
+    try_command_on_node $test_node "mktemp -d --tmpdir=$nfs_first_export"
+    nfs_test_dir="$out"
+    try_command_on_node $test_node "chmod 777 $nfs_test_dir"
+
+    nfs_mnt_d=$(mktemp -d)
+    nfs_local_file="${nfs_mnt_d}/${nfs_test_dir##*/}/TEST_FILE"
+    nfs_remote_file="${nfs_test_dir}/TEST_FILE"
+
+    ctdb_test_exit_hook_add nfs_test_cleanup
+
+    echo "Mounting ${test_ip}:${nfs_first_export} on ${nfs_mnt_d} ..."
+    mount -o timeo=1,hard,intr,vers=3 \
+       ${test_ip}:${nfs_first_export} ${nfs_mnt_d}
+}
+
+nfs_test_cleanup ()
+{
+    rm -f "$nfs_local_file"
+    umount -f "$nfs_mnt_d"
+    rmdir "$nfs_mnt_d"
+    onnode -q $test_node rmdir "$nfs_test_dir"
+}
+
+
+
+#######################################
+
 # Make sure that $CTDB is set.
 : ${CTDB:=ctdb}