summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-08-23 02:14:36 -0700
committerHarshavardhana <harsha@harshavardhana.net>2014-09-05 10:04:20 -0700
commitfd500d4396f910e4cf759e0fffa4daf4ed24745a (patch)
tree2e52c1b64659efc3cf98fed31a8a2fc6f8a4bc26 /tests
parent88159becd90d40323ecfc24cf40813538c9204cc (diff)
porting: Provide setfattr/getfattr implementation
- Use 'getfattr' properly avoid redundant options during xattr query - Untabify certain parts of tests (remove tabs) - Avoid backtick evaluation for certain values to make code more portable. - Use awk on FreeBSD/Darwin, since 'wc' implementation is broken and adds spurious spaces in its output. Change-Id: I7dcc0b70874e43b4cda8c306ed18a31b7a3f990a BUG: 1131713 Signed-off-by: Harshavardhana <harsha@harshavardhana.net> Reviewed-on: http://review.gluster.org/8520 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Emmanuel Dreyfus <manu@netbsd.org> Tested-by: Emmanuel Dreyfus <manu@netbsd.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/afr.rc4
-rw-r--r--tests/basic/ec/ec.t4
-rw-r--r--tests/basic/ec/self-heal.t2
-rw-r--r--tests/basic/gfid-access.t16
-rw-r--r--tests/bugs/949327.t2
-rw-r--r--tests/bugs/bug-1002207.t2
-rw-r--r--tests/bugs/bug-1111490.t6
-rw-r--r--tests/bugs/bug-765380.t8
-rw-r--r--tests/bugs/bug-856455.t10
-rw-r--r--tests/bugs/bug-906646.t6
-rwxr-xr-xtests/bugs/bug-924265.t2
-rwxr-xr-xtests/cluster.rc44
-rw-r--r--tests/dht.rc18
-rw-r--r--tests/fallocate.rc18
-rwxr-xr-xtests/features/readdir-ahead.t2
-rwxr-xr-xtests/features/ssl-authz.t2
-rwxr-xr-xtests/features/weighted-rebalance.t40
-rw-r--r--tests/fileio.rc56
-rw-r--r--tests/include.rc230
-rw-r--r--tests/nfs.rc5
-rwxr-xr-xtests/utils/getfattr.py133
-rwxr-xr-xtests/utils/setfattr.py78
-rw-r--r--tests/volume.rc4
23 files changed, 465 insertions, 227 deletions
diff --git a/tests/afr.rc b/tests/afr.rc
index 938f9c07ab2..721f24545d5 100644
--- a/tests/afr.rc
+++ b/tests/afr.rc
@@ -74,9 +74,9 @@ function is_file_heal_done {
function count_sh_entries()
{
val1=0
- for g in `ls $1/.glusterfs/indices/xattrop`
+ for g in $(ls $1/.glusterfs/indices/xattrop)
do
- val1=$(( val1 + 1 ))
+ val1=$(( val1 + 1 ))
done
echo $val1;
diff --git a/tests/basic/ec/ec.t b/tests/basic/ec/ec.t
index 569f4c7098a..b4ce338231c 100644
--- a/tests/basic/ec/ec.t
+++ b/tests/basic/ec/ec.t
@@ -226,7 +226,7 @@ EXPECT_WITHIN 5 "Y" check_setxattr $B0/${V0}{0..9}
EXPECT_WITHIN 5 "Y" check_removexattr $B0/${V0}{0..9}
EXPECT_WITHIN 5 "Y" check_perm_file $B0/${V0}{0..9}
-rm -rf $tmpdir
-userdel --force ${TEST_USER}
+TEST rm -rf $tmpdir
+TEST userdel --force ${TEST_USER}
cleanup
diff --git a/tests/basic/ec/self-heal.t b/tests/basic/ec/self-heal.t
index ba28b7d82f5..524c11d2220 100644
--- a/tests/basic/ec/self-heal.t
+++ b/tests/basic/ec/self-heal.t
@@ -118,6 +118,6 @@ EXPECT "2" stat -c "%h" test4
EXPECT_WITHIN 5 "3" stat -c "%h" ${brick[0]}/test4
EXPECT_WITHIN 5 "3" stat -c "%h" ${brick[1]}/test4
-rm -rf $tmp
+TEST rm -rf $tmp
cleanup
diff --git a/tests/basic/gfid-access.t b/tests/basic/gfid-access.t
index a2965cc1452..f83eb6d47ee 100644
--- a/tests/basic/gfid-access.t
+++ b/tests/basic/gfid-access.t
@@ -17,8 +17,8 @@ b_gfid_str=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/${V0}0/b))
#Operations on Directory
TEST setfattr -n trusted.abc -v abc $M0/a
-EXPECT "abc" echo $(getfattr -n trusted.abc $M0/a)
-EXPECT "abc" echo $(getfattr -n trusted.abc $M0/.gfid/$a_gfid_str)
+EXPECT "abc" echo $(getfattr -n trusted.abc --only-values $M0/a)
+EXPECT "abc" echo $(getfattr -n trusted.abc --only-values $M0/.gfid/$a_gfid_str)
TEST setfattr -x trusted.abc $M0/a
TEST ! getfattr -n trusted.abc $M0/a
TEST ! getfattr -n trusted.abc $M0/.gfid/$a_gfid_str
@@ -27,8 +27,8 @@ EXPECT "777" stat -c "%a" $M0/a
EXPECT "777" stat -c "%a" $M0/.gfid/$a_gfid_str
TEST setfattr -n trusted.abc -v def $M0/.gfid/$a_gfid_str
-EXPECT "def" echo $(getfattr -n trusted.abc $M0/a)
-EXPECT "def" echo $(getfattr -n trusted.abc $M0/.gfid/$a_gfid_str)
+EXPECT "def" echo $(getfattr -n trusted.abc --only-values $M0/a)
+EXPECT "def" echo $(getfattr -n trusted.abc --only-values $M0/.gfid/$a_gfid_str)
TEST setfattr -x trusted.abc $M0/.gfid/$a_gfid_str
TEST ! getfattr -n trusted.abc $M0/a
TEST ! getfattr -n trusted.abc $M0/.gfid/$a_gfid_str
@@ -56,8 +56,8 @@ TEST ! mknod $M0/.gfid/b b 0 0
#Operations on File
TEST setfattr -n trusted.abc -v abc $M0/b
-EXPECT "abc" echo $(getfattr -n trusted.abc $M0/b)
-EXPECT "abc" echo $(getfattr -n trusted.abc $M0/.gfid/$b_gfid_str)
+EXPECT "abc" echo $(getfattr -n trusted.abc --only-values $M0/b)
+EXPECT "abc" echo $(getfattr -n trusted.abc --only-values $M0/.gfid/$b_gfid_str)
TEST setfattr -x trusted.abc $M0/b
TEST ! getfattr -n trusted.abc $M0/b
TEST ! getfattr -n trusted.abc $M0/.gfid/$b_gfid_str
@@ -66,8 +66,8 @@ EXPECT "777" stat -c "%a" $M0/b
EXPECT "777" stat -c "%a" $M0/.gfid/$b_gfid_str
TEST setfattr -n trusted.abc -v def $M0/.gfid/$b_gfid_str
-EXPECT "def" echo $(getfattr -n trusted.abc $M0/b)
-EXPECT "def" echo $(getfattr -n trusted.abc $M0/.gfid/$b_gfid_str)
+EXPECT "def" echo $(getfattr -n trusted.abc --only-values $M0/b)
+EXPECT "def" echo $(getfattr -n trusted.abc --only-values $M0/.gfid/$b_gfid_str)
TEST setfattr -x trusted.abc $M0/.gfid/$b_gfid_str
TEST ! getfattr -n trusted.abc $M0/b
TEST ! getfattr -n trusted.abc $M0/.gfid/$b_gfid_str
diff --git a/tests/bugs/949327.t b/tests/bugs/949327.t
index 7b0c5c51a81..b8ac995f246 100644
--- a/tests/bugs/949327.t
+++ b/tests/bugs/949327.t
@@ -7,7 +7,7 @@ cleanup;
function tmp_file_count()
{
-echo $(ls -lh /tmp/tmp.* | wc -l)
+ echo $(ls -lh /tmp/tmp.* 2>/dev/null | wc -l)
}
diff --git a/tests/bugs/bug-1002207.t b/tests/bugs/bug-1002207.t
index 4fad2ff156c..c67738bd7ec 100644
--- a/tests/bugs/bug-1002207.t
+++ b/tests/bugs/bug-1002207.t
@@ -26,7 +26,7 @@ function xattr_query_check()
local path=$1
local xa_name=$2
- local ret=`getfattr -m . -n $xa_name $path 2>&1 | grep -o "$xa_name: No such attribute" | wc -l`
+ local ret=$(getfattr -n $xa_name $path 2>&1 | grep -o "$xa_name: No such attribute" | wc -l)
echo $ret
}
diff --git a/tests/bugs/bug-1111490.t b/tests/bugs/bug-1111490.t
index 7b13c8798ec..289ac70b4a1 100644
--- a/tests/bugs/bug-1111490.t
+++ b/tests/bugs/bug-1111490.t
@@ -12,19 +12,19 @@ TEST $CLI volume create $V0 $H0:$B0/${V0}0
TEST $CLI volume start $V0
# mount with auxillary gfid mount
-TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0 --aux-gfid-mount
+TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0 --aux-gfid-mount
# create file with specific gfid
uuid=`uuidgen`
EXPECT "File creation OK" gfid-access.py $M0 ROOT file0 $uuid file
# check gfid
-EXPECT "$uuid" getfattr -m . --only-values -n glusterfs.gfid.string $M0/file0
+EXPECT "$uuid" getfattr --only-values -n glusterfs.gfid.string $M0/file0
# unmount and mount again so as to start with a fresh inode table
# or use another mount...
TEST umount $M0
-TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0 --aux-gfid-mount
+TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0 --aux-gfid-mount
# touch the file again (gfid-access.py handles errno)
EXPECT "File creation OK" gfid-access.py $M0 ROOT file0 $uuid file
diff --git a/tests/bugs/bug-765380.t b/tests/bugs/bug-765380.t
index 65bc6597eea..cf580c4a811 100644
--- a/tests/bugs/bug-765380.t
+++ b/tests/bugs/bug-765380.t
@@ -13,15 +13,15 @@ TEST $CLI volume create $V0 replica $REPLICA $H0:$B0/${V0}00 $H0:$B0/${V0}01 $H0
TEST $CLI volume start $V0
## Mount FUSE with caching disabled
-TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0;
+TEST $GFS -s $H0 --volfile-id $V0 $M0;
function count_hostname_or_uuid_from_pathinfo()
{
- pathinfo=`getfattr -m . -n trusted.glusterfs.pathinfo $M0/f00f`
+ pathinfo=$(getfattr -n trusted.glusterfs.pathinfo $M0/f00f)
echo $pathinfo | grep -o $1 | wc -l
}
-touch $M0/f00f
+TEST touch $M0/f00f
EXPECT $REPLICA count_hostname_or_uuid_from_pathinfo $H0
@@ -31,7 +31,7 @@ TEST $CLI volume set $V0 node-uuid-pathinfo on
# do not expext hostname as part of the pathinfo string
EXPECT 0 count_hostname_or_uuid_from_pathinfo $H0
-uuid=`grep UUID $GLUSTERD_WORKDIR/glusterd.info | cut -f2 -d=`
+uuid=$(grep UUID $GLUSTERD_WORKDIR/glusterd.info | cut -f2 -d=)
# ... but expect the uuid $REPLICA times
EXPECT $REPLICA count_hostname_or_uuid_from_pathinfo $uuid
diff --git a/tests/bugs/bug-856455.t b/tests/bugs/bug-856455.t
index 3e314aa5bb3..0e79d9fa1c9 100644
--- a/tests/bugs/bug-856455.t
+++ b/tests/bugs/bug-856455.t
@@ -13,20 +13,20 @@ TEST $CLI volume create $V0 $H0:$B0/${V0}0 $H0:$B0/${V0}1 $H0:$B0/${V0}2
TEST $CLI volume start $V0
## Mount FUSE with caching disabled
-TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0;
+TEST $GFS -s $H0 --volfile-id $V0 $M0;
function query_pathinfo()
{
local path=$1;
local retval;
- local pathinfo=`getfattr -m . -n trusted.glusterfs.pathinfo $path`;
- retval=`echo $pathinfo | grep -o 'POSIX' | wc -l`;
+ local pathinfo=$(getfattr -n trusted.glusterfs.pathinfo $path);
+ retval=$(echo $pathinfo | grep -o 'POSIX' | wc -l);
echo $retval
}
-touch $M0/f00f;
-mkdir $M0/f00d;
+TEST touch $M0/f00f;
+TEST mkdir $M0/f00d;
# verify pathinfo for a file and directory
EXPECT 1 query_pathinfo $M0/f00f;
diff --git a/tests/bugs/bug-906646.t b/tests/bugs/bug-906646.t
index 754f193beb8..b11bb08bdd5 100644
--- a/tests/bugs/bug-906646.t
+++ b/tests/bugs/bug-906646.t
@@ -17,14 +17,14 @@ TEST $CLI volume set $V0 cluster.self-heal-daemon off
TEST $CLI volume set $V0 cluster.background-self-heal-count 0
## Mount FUSE with caching disabled
-TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0;
+TEST $GFS -s $H0 --volfile-id $V0 $M0;
function xattr_query_check()
{
local path=$1
local xa_name=$2
- local ret=`getfattr -m . -n $xa_name $path 2>&1 | grep -o "$xa_name: No such attribute" | wc -l`
+ local ret=$(getfattr -n $xa_name $path 2>&1 | grep -o "$xa_name: No such attribute" | wc -l)
echo $ret
}
@@ -50,7 +50,7 @@ function remove_xattr()
f=f00f
pth=$M0/$f
-touch $pth
+TEST touch $pth
# fetch backend paths
backend_paths=`get_backend_paths $pth`
diff --git a/tests/bugs/bug-924265.t b/tests/bugs/bug-924265.t
index b08c13fddcb..51eda7f6e97 100755
--- a/tests/bugs/bug-924265.t
+++ b/tests/bugs/bug-924265.t
@@ -8,7 +8,7 @@
# We only care about the exit code, so keep it quiet.
function silent_getfattr {
- getfattr $* &> /dev/null
+ getfattr $* &> /dev/null
}
cleanup
diff --git a/tests/cluster.rc b/tests/cluster.rc
index 49bd3caedec..42f3ad24434 100755
--- a/tests/cluster.rc
+++ b/tests/cluster.rc
@@ -21,12 +21,12 @@ function define_backends() {
local b;
for i in `seq 1 $count`; do
- eval "B$i=$B0/$i";
+ eval "B$i=$B0/$i";
done
for i in `seq 1 $count`; do
- b="B$i";
- mkdir -p ${!b}/glusterd;
+ b="B$i";
+ mkdir -p ${!b}/glusterd;
done
}
@@ -40,11 +40,11 @@ function define_glusterds() {
local popt;
for i in `seq 1 $count`; do
- b="B$i";
- h="H$i";
- wopt="management.working-directory=${!b}/glusterd";
- bopt="management.transport.socket.bind-address=${!h}";
- popt="--pid-file=${!b}/glusterd.pid";
+ b="B$i";
+ h="H$i";
+ wopt="management.working-directory=${!b}/glusterd";
+ bopt="management.transport.socket.bind-address=${!h}";
+ popt="--pid-file=${!b}/glusterd.pid";
sopt="management.glusterd-sockfile=${!b}/glusterd/gd.sock"
#Get the logdir
logdir=`gluster --print-logdir`
@@ -66,8 +66,8 @@ function start_glusterds() {
local g;
for i in `seq 1 $CLUSTER_COUNT`; do
- g="glusterd_$i";
- ${!g};
+ g="glusterd_$i";
+ ${!g};
done
}
@@ -98,15 +98,15 @@ function define_hosts() {
local count=$1;
for i in `seq 1 $count`; do
- eval "H_$i=${CLUSTER_PFX}.$i"
- eval "H$i=${CLUSTER_PFX}.$i";
- case $OSTYPE in
- NetBSD)
- ifconfig lo0 alias ${CLUSTER_PFX}.$i 2>/dev/null
- ;;
- *)
- ;;
- esac
+ eval "H_$i=${CLUSTER_PFX}.$i"
+ eval "H$i=${CLUSTER_PFX}.$i";
+ case $OSTYPE in
+ NetBSD)
+ ifconfig lo0 alias ${CLUSTER_PFX}.$i 2>/dev/null
+ ;;
+ *)
+ ;;
+ esac
done
}
@@ -116,9 +116,9 @@ function define_clis() {
local h;
for i in `seq 1 $count`; do
- b="B$i";
- eval "CLI_$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock'";
- eval "CLI$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock'";
+ b="B$i";
+ eval "CLI_$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock'";
+ eval "CLI$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock'";
done
}
diff --git a/tests/dht.rc b/tests/dht.rc
index 50c4532617e..4d4979ea082 100644
--- a/tests/dht.rc
+++ b/tests/dht.rc
@@ -1,9 +1,9 @@
#!/bin/bash
+
function get_layout()
{
- getfattr -n trusted.glusterfs.dht -e hex $1 2>&1|grep dht |cut -d = -f2
-
+ getfattr -n trusted.glusterfs.dht -e hex $1 2>&1 | grep dht | cut -d = -f2
}
## populates $BRICK1 and $BRICK2 with hashed/cached subvolume. These will be
@@ -15,7 +15,7 @@ function file_has_linkfile()
l=0
while [ $k -lt $BRICK_COUNT ]
do
- stat=`stat $B0/${V0}$k/$1 2>/dev/null`
+ stat=$(stat $B0/${V0}$k/$1 2>/dev/null)
if [ $? -eq 0 ]
then
let l++
@@ -33,7 +33,7 @@ function get_cached_brick()
brick=$BRICK1
while [ $i -lt 3 ]
do
- test=`getfattr -n trusted.glusterfs.dht.linkto -e text $B0/${V0}$brick/$1 2>&1`
+ test=$(getfattr -n trusted.glusterfs.dht.linkto -e text $B0/${V0}$brick/$1 2>&1)
if [ $? -eq 1 ]
then
cached=$brick
@@ -52,7 +52,7 @@ function get_hashed_brick()
brick=$BRICK1
while [ $j -lt 3 ]
do
- test=`getfattr -n trusted.glusterfs.dht.linkto -e text $B0/${V0}$brick/$1 2>&1`
+ test=$(getfattr -n trusted.glusterfs.dht.linkto -e text $B0/${V0}$brick/$1 2>&1)
if [ $? -eq 0 ]
then
hashed=$brick
@@ -69,7 +69,7 @@ function get_hashed_brick()
function rebalance_completed()
{
val=1
- test=`gluster volume rebalance $V0 status |grep localhost|grep -v "in progress" 2>&1`
+ test=$(gluster volume rebalance $V0 status | grep localhost | grep -v "in progress" 2>&1)
if [ $? -eq 0 ]
then
val=0
@@ -82,7 +82,7 @@ function rebalance_completed()
function remove_brick_completed()
{
val=1
- test=`gluster volume remove-brick $V0 $H0:$B0/${V0}2 status |grep localhost|grep -v "in progress" 2>&1`
+ test=$(gluster volume remove-brick $V0 $H0:$B0/${V0}2 status | grep localhost | grep -v "in progress" 2>&1)
if [ $? -eq 0 ]
then
val=0
@@ -95,14 +95,14 @@ function remove_brick_completed()
function dht_get_linkto_target()
{
local path=$1;
- echo `getfattr -d -m . -e text --only-values --absolute-names --name=trusted.glusterfs.dht.linkto $path`
+ echo $(getfattr -e text --only-values --absolute-names -n trusted.glusterfs.dht.linkto $path)
}
function is_dht_linkfile()
{
local path=$1
retval=0
- local output=`stat --format=%a $path`
+ local output=$(stat -c %a $path)
if [ $output -eq 1000 ]; then
retval=1
fi
diff --git a/tests/fallocate.rc b/tests/fallocate.rc
index 3756bb949bd..d117ba9c051 100644
--- a/tests/fallocate.rc
+++ b/tests/fallocate.rc
@@ -7,13 +7,13 @@
function require_fallocate()
{
- output=`fallocate $* 2>&1`
- ret=$?
- if [ ! $ret -eq 0 ] && ([[ $output == *unsupported* ]] ||
- [[ $output == *invalid* ]] ||
- [[ $output == *"not supported"* ]])
- then
- SKIP_TESTS
- exit
- fi
+ output=`fallocate $* 2>&1`
+ ret=$?
+ if [ ! $ret -eq 0 ] && ([[ $output == *unsupported* ]] ||
+ [[ $output == *invalid* ]] ||
+ [[ $output == *"not supported"* ]])
+ then
+ SKIP_TESTS
+ exit
+ fi
}
diff --git a/tests/features/readdir-ahead.t b/tests/features/readdir-ahead.t
index 6c09ee41208..75223df61bf 100755
--- a/tests/features/readdir-ahead.t
+++ b/tests/features/readdir-ahead.t
@@ -22,7 +22,7 @@ TEST $GFS --volfile-id=$V0 --volfile-server=$H0 $M0
TEST mkdir $M0/test
for i in $(seq 0 99)
do
- touch $M0/test/$i
+ touch $M0/test/$i
done
count=`ls -1 $M0/test | wc -l`
diff --git a/tests/features/ssl-authz.t b/tests/features/ssl-authz.t
index fa241907b9f..313d67c3eda 100755
--- a/tests/features/ssl-authz.t
+++ b/tests/features/ssl-authz.t
@@ -3,7 +3,7 @@
. $(dirname $0)/../include.rc
ping_file () {
- echo hello > $1 2> /dev/null
+ echo hello > $1 2> /dev/null
}
SSL_BASE=/etc/ssl
diff --git a/tests/features/weighted-rebalance.t b/tests/features/weighted-rebalance.t
index 5bd858b4c4c..b9d9eb4eb73 100755
--- a/tests/features/weighted-rebalance.t
+++ b/tests/features/weighted-rebalance.t
@@ -7,35 +7,35 @@
NFILES=1000
touch_files () {
- for i in $(seq 1 $NFILES); do
- touch $(printf $M0/dir/file%02d $i) 2> /dev/null
- done
+ for i in $(seq 1 $NFILES); do
+ touch $(printf $M0/dir/file%02d $i) 2> /dev/null
+ done
}
count_files () {
- found=0
- for i in $(seq 1 $NFILES); do
- if [ -f $(printf $1/dir/file%02d $i) ]; then
- found=$((found+1))
- fi
- done
- echo $found
+ found=0
+ for i in $(seq 1 $NFILES); do
+ if [ -f $(printf $1/dir/file%02d $i) ]; then
+ found=$((found+1))
+ fi
+ done
+ echo $found
}
wait_for_rebalance () {
- while true; do
- rebalance_completed
- if [ $? -eq 1 ]; then
- sleep 1
- else
- break
- fi
- done
+ while true; do
+ rebalance_completed
+ if [ $? -eq 1 ]; then
+ sleep 1
+ else
+ break
+ fi
+ done
}
get_xattr () {
- cmd="getfattr --absolute-names --only-values -n trusted.glusterfs.dht"
- $cmd $1 | od -tx1 -An | tr -d ' '
+ cmd="getfattr --absolute-names --only-values -n trusted.glusterfs.dht"
+ $cmd $1 | od -tx1 -An | tr -d ' '
}
cleanup
diff --git a/tests/fileio.rc b/tests/fileio.rc
index 58871b3b97a..ec0767832e8 100644
--- a/tests/fileio.rc
+++ b/tests/fileio.rc
@@ -2,53 +2,53 @@
function fd_available() {
for i in {1..65536}; do
- if [ ! -e /proc/$$/fd/$i ]; then
- echo $i;
- return 0;
- fi
- done
+ if [ ! -e /proc/$$/fd/$i ]; then
+ echo $i;
+ return 0;
+ fi
+ done
- return 1;
+ return 1;
}
function fd_open() {
- local fd=$1;
- local mode=$2
- local path=$3;
-
- case $mode in
- r)
- eval "exec $fd<$path";;
- w)
- eval "exec $fd>$path";;
- rw)
- eval "exec $fd<>$path";;
- *)
- false;;
- esac
+ local fd=$1;
+ local mode=$2
+ local path=$3;
+
+ case $mode in
+ r)
+ eval "exec $fd<$path";;
+ w)
+ eval "exec $fd>$path";;
+ rw)
+ eval "exec $fd<>$path";;
+ *)
+ false;;
+ esac
}
function fd_cat() {
- local fd=$1;
+ local fd=$1;
- eval "cat <&$fd";
+ eval "cat <&$fd";
}
function fd_write() {
- local fd=$1;
- shift;
- local msg="$@";
+ local fd=$1;
+ shift;
+ local msg="$@";
- eval "echo $@ >&$fd";
+ eval "echo $@ >&$fd";
}
function fd_close() {
- local fd=$1;
+ local fd=$1;
- eval "exec $fd>&-";
+ eval "exec $fd>&-";
}
diff --git a/tests/include.rc b/tests/include.rc
index 39d824e64ba..64a9d34dc99 100644
--- a/tests/include.rc
+++ b/tests/include.rc
@@ -62,59 +62,75 @@ mkdir -p $B0;
mkdir -p $M0 $M1;
mkdir -p $N0 $N1;
+case $OSTYPE in
+FreeBSD | Darwin)
+wc () {
+ if test "x$1" = "x-l"; then
+ awk '{ lines++ } END {print lines}'
+ fi
+ if test "x$1" = "x-w"; then
+ awk '{ words += NF } END {print words}' }
+ fi
+ if test "x$1" = "x-c"; then
+ awk '{ chars += length($0) + 1 } END {print chars}'
+ fi
+ if test "x$1" = "x-m"; then
+ awk '{ chars += length($0) + 1 } END {print chars}'
+ fi
+}
+;;
+esac
+
testcnt=`egrep '^[[:space:]]*(EXPECT|EXPECT_NOT|TEST|EXPECT_WITHIN|EXPECT_KEYWORD)[[:space:]]' $0 | wc -l`
expect_tests=`egrep '^[[:space:]]*TESTS_EXPECTED_IN_LOOP[[:space:]]*' $0`
x_ifs=$IFS
IFS=$'\n'
for line in $expect_tests; do
- expect_tests=`echo $line | cut -f 2 -d =`
- testcnt=`expr $testcnt + $expect_tests`
+ expect_tests=`echo $line | cut -f 2 -d =`
+ testcnt=`expr $testcnt + $expect_tests`
done
IFS=$x_ifs
-# Remove space again since `wc -l` on OSX and FreeBSD
-# adds spurious space which clobbers up TAP output
-testcnt_nospace=$(echo $testcnt | tr -d ' ')
-echo 1..$testcnt_nospace
+echo 1..$testcnt
t=1
function dbg()
{
- [ "x$DEBUG" = "x0" ] || echo "$*" >&2;
+ [ "x$DEBUG" = "x0" ] || echo "$*" >&2;
}
function test_header()
{
- dbg "=========================";
- dbg "TEST $t (line $TESTLINE): $*";
- saved_cmd="$*"
+ dbg "=========================";
+ dbg "TEST $t (line $TESTLINE): $*";
+ saved_cmd="$*"
}
function test_footer()
{
- RET=$?
+ RET=$?
local err=$1
- if [ $RET -eq 0 ]; then
- echo "ok $t";
- else
+ if [ $RET -eq 0 ]; then
+ echo "ok $t";
+ else
echo "not ok $t $err";
- # With DEBUG, this was already printed out, so skip it.
- if [ x"$DEBUG" = x"0" ]; then
- echo "FAILED COMMAND: $saved_cmd"
- fi
- if [ "$EXIT_EARLY" = "1" ]; then
- exit $RET
- fi
- fi
-
- dbg "RESULT $t: $RET";
-
- t=`expr $t + 1`;
+ # With DEBUG, this was already printed out, so skip it.
+ if [ x"$DEBUG" = x"0" ]; then
+ echo "FAILED COMMAND: $saved_cmd"
+ fi
+ if [ "$EXIT_EARLY" = "1" ]; then
+ exit $RET
+ fi
+ fi
+
+ dbg "RESULT $t: $RET";
+
+ t=`expr $t + 1`;
}
function test_expect_footer()
@@ -133,20 +149,20 @@ function test_expect_footer()
function _EXPECT()
{
- TESTLINE=$1;
- shift;
+ TESTLINE=$1;
+ shift;
local a=""
- test_header "$@";
+ test_header "$@";
- e="$1";
- shift;
- a=$("$@" | tail -1)
+ e="$1";
+ shift;
+ a=$("$@" | tail -1)
if [ "x$e" = "x" ] ; then
- test_expect_footer "x$e" "x$a";
+ test_expect_footer "x$e" "x$a";
else
- test_expect_footer "$e" "$a";
+ test_expect_footer "$e" "$a";
fi
}
@@ -166,15 +182,15 @@ function test_expect_not_footer()
function _EXPECT_NOT()
{
- TESTLINE=$1;
- shift;
+ TESTLINE=$1;
+ shift;
local a=""
- test_header "$@";
+ test_header "$@";
- e="$1";
- shift;
- a=$("$@" | tail -1)
+ e="$1";
+ shift;
+ a=$("$@" | tail -1)
if [ "x$e" = "x" ] ; then
test_expect_not_footer "x$e" "x$a";
@@ -185,34 +201,34 @@ function _EXPECT_NOT()
function _EXPECT_KEYWORD()
{
- TESTLINE=$1;
- shift;
+ TESTLINE=$1;
+ shift;
- test_header "$@";
+ test_header "$@";
- e="$1";
- shift;
- "$@" | tail -1 | grep -q "$e"
+ e="$1";
+ shift;
+ "$@" | tail -1 | grep -q "$e"
- test_footer;
+ test_footer;
}
function _TEST()
{
- TESTLINE=$1;
- shift;
+ TESTLINE=$1;
+ shift;
local redirect=""
- test_header "$@";
+ test_header "$@";
if [ "$1" = "!" ]; then
redirect="2>&1"
fi
- eval "$@" >/dev/null $redirect
+ eval "$@" >/dev/null $redirect
- test_footer;
+ test_footer;
}
function _EXPECT_WITHIN()
@@ -264,20 +280,20 @@ function SKIP_TESTS()
function _TEST_IN_LOOP()
{
- testcnt=`expr $testcnt + 1`;
- _TEST $@
+ testcnt=`expr $testcnt + 1`;
+ _TEST $@
}
which killall > /dev/null || {
- killall() {
- pkill $@
- }
+ killall() {
+ pkill $@
+ }
}
which pidof > /dev/null || {
- pidof() {
- pidof.py $1
- }
+ pidof() {
+ pidof.py $@
+ }
}
stat -c %s /dev/null > /dev/null 2>&1 || {
@@ -337,12 +353,12 @@ function cleanup()
umount $m
done
- killall -15 glusterfs glusterfsd glusterd 2>/dev/null || true;
- test "x`uname -s` = "xNetBSD" && pkill -15 perfused || true
+ killall -15 glusterfs glusterfsd glusterd 2>/dev/null || true;
+ test x"$OSTYPE" = x"NetBSD" && pkill -15 perfused || true
# allow completion of signal handlers for SIGTERM before issue SIGKILL
sleep 1
- killall -9 glusterfs glusterfsd glusterd 2>/dev/null || true;
- test "x`uname -s` = "xNetBSD" && pkill -9 perfused || true
+ killall -9 glusterfs glusterfsd glusterd 2>/dev/null || true;
+ test x"$OSTYPE" = x"NetBSD" && pkill -9 perfused || true
# unregister nfs and related services from portmapper/rpcbind
## nfs
@@ -358,45 +374,45 @@ function cleanup()
type cleanup_lvm &>/dev/null && cleanup_lvm || true;
- case `uname -s` in
- Linux)
- LOOPDEVICES=`losetup -a | grep "$B0/" | \
- awk '{print $1}' | tr -d :`
- for l in $LOOPDEVICES;
- do
- losetup -d $l
- done
- ;;
- NetBSD)
- vnd=`vnconfig -l | \
- awk '!/not in use/{printf("%s%s:%d ", $1, $2, $5);}'`
- for l in ${vnd} ; do
- dev=${l%%:*}
- tmp=${l#*:}
- fs=${tmp%%:*}
- inode=${tmp#*:}
- file=`find -x ${fs} -inum ${inode} -print -exit`
- echo ${file} | grep "$B0/" && \
- LOOPDEVICES="${LOOPDEVICES} $dev"
- done
- for l in $LOOPDEVICES;
- do
- vnconfig -u $l
- done
- ;;
- *)
- echo "`uname -s` loopback device supportmissing"
- ;;
- esac
+ case `uname -s` in
+ Linux)
+ LOOPDEVICES=`losetup -a | grep "$B0/" | \
+ awk '{print $1}' | tr -d :`
+ for l in $LOOPDEVICES;
+ do
+ losetup -d $l
+ done
+ ;;
+ NetBSD)
+ vnd=`vnconfig -l | \
+ awk '!/not in use/{printf("%s%s:%d ", $1, $2, $5);}'`
+ for l in ${vnd} ; do
+ dev=${l%%:*}
+ tmp=${l#*:}
+ fs=${tmp%%:*}
+ inode=${tmp#*:}
+ file=`find -x ${fs} -inum ${inode} -print -exit`
+ echo ${file} | grep "$B0/" && \
+ LOOPDEVICES="${LOOPDEVICES} $dev"
+ done
+ for l in $LOOPDEVICES;
+ do
+ vnconfig -u $l
+ done
+ ;;
+ *)
+ echo "`uname -s` loopback device supportmissing"
+ ;;
+ esac
if [ -n "${GLUSTERD_WORKDIR}" ] ; then
rm -rf $GLUSTERD_WORKDIR/* $B0/* /etc/glusterd/*;
fi
- umount -l $M0 2>/dev/null || umount -f $M0 2>/dev/null || true;
- umount -l $M1 2>/dev/null || umount -f $M1 2>/dev/null || true;
- umount -l $N0 2>/dev/null || umount -f $N0 2>/dev/null || true;
- umount -l $N1 2>/dev/null || umount -f $N1 2>/dev/null || true;
+ umount -l $M0 2>/dev/null || umount -f $M0 2>/dev/null || true;
+ umount -l $M1 2>/dev/null || umount -f $M1 2>/dev/null || true;
+ umount -l $N0 2>/dev/null || umount -f $N0 2>/dev/null || true;
+ umount -l $N1 2>/dev/null || umount -f $N1 2>/dev/null || true;
}
@@ -451,7 +467,7 @@ which truncate > /dev/null || {
;;
-o)
ioblocks=1;
- echo "Unimplemented -o option"
+ echo "Unimplemented -o option"
exit 2
;;
-r)
@@ -543,6 +559,18 @@ which md5sum > /dev/null || {
}
}
+which setfattr > /dev/null || {
+ setfattr() {
+ setfattr.py $@
+ }
+}
+
+which getfattr > /dev/null || {
+ getfattr() {
+ getfattr.py $@
+ }
+}
+
which sha1sum > /dev/null || {
sha1sum() {
case $OSTYPE in
@@ -569,9 +597,9 @@ alias TEST_IN_LOOP='_TEST_IN_LOOP $LINENO'
shopt -s expand_aliases
if [ x"$OSTYPE" = x"Linux" ]; then
- alias dd="dd status=none"
+ alias dd="dd status=none"
elif [ x"$OSTYPE" = x"NetBSD" ]; then
- alias dd="dd msgfmt=quiet"
+ alias dd="dd msgfmt=quiet"
fi
# MacOS doesn't seem to support either option. Doing nothing at all is
# probably the safest option there and on anything we don't recognize, but
diff --git a/tests/nfs.rc b/tests/nfs.rc
index a2d7c140012..f79be701a2d 100644
--- a/tests/nfs.rc
+++ b/tests/nfs.rc
@@ -26,7 +26,7 @@ function mount_nfs ()
opt="soft,intr,vers=3$opt"
nopt=""
- for o in ${opt//,/ }; do
+ for o in ${opt//,/ }; do
case $OSTYPE in
NetBSD)
test "x${nopt}" = "x" && nopt="tcp,"
@@ -52,7 +52,7 @@ function mount_nfs ()
;;
*)
;;
- esac
+ esac
;;
*)
;;
@@ -68,4 +68,3 @@ function umount_nfs {
umount -f $1
if [ $? -eq 0 ]; then echo "Y"; else echo "N"; fi
}
-
diff --git a/tests/utils/getfattr.py b/tests/utils/getfattr.py
new file mode 100755
index 00000000000..1a8369af7c4
--- /dev/null
+++ b/tests/utils/getfattr.py
@@ -0,0 +1,133 @@
+#!/usr/bin/env python2
+
+import os
+import sys
+from optparse import OptionParser
+
+import xattr
+
+def handle_textencoding(attr):
+ ### required for Python's handling of NULL strings.
+ attr_null_replace = (attr.encode('hex').decode('hex')).replace('\x00',
+ '\\000')
+ return attr_null_replace
+
+def getfattr(path, option):
+ attr = xattr.getxattr(path, option.name)
+ encoded_attr = attr
+
+ if option.encoding == "text":
+ ## special case handle it.
+ encoded_attr = handle_textencoding(attr)
+ else:
+ encoded_attr = attr.encode(option.encoding)
+
+ if option.onlyvalues:
+ print (encoded_attr)
+ return
+
+ print_getfattr (path, option, encoded_attr)
+ return
+
+def print_getfattr (path, option, encoded_attr=None):
+ if encoded_attr:
+ if option.encoding == "hex":
+ print ("%s=0x%s" % (option.name, encoded_attr))
+ elif option.encoding == "base64":
+ print ("%s=0s%s" % (option.name, encoded_attr))
+ else:
+ print ("%s=\"%s\"" % (option.name, encoded_attr))
+ else:
+ print option.name
+
+ return
+
+def print_header (path, absnames):
+ if absnames:
+ print ("# file: %s" % path)
+ else:
+ print ("getfattr: Removing leading '/' from absolute path names")
+ print ("# file: %s" % path[1:])
+
+if __name__ == '__main__':
+ usage = "usage: %prog [-n name|-d] [-e en] [-m pattern] path...."
+ parser = OptionParser(usage=usage)
+ parser.add_option("-n", action="store", dest="name", type="string",
+ help="Dump the value of the named extended attribute"
+ " extended attribute.")
+ parser.add_option("-d", action="store_true", dest="dump",
+ help="Dump the values of all extended attributes"
+ " associated with pathname.")
+ parser.add_option("-e", action="store", dest="encoding", type="string",
+ default="base64",
+ help="Encode values after retrieving"
+ " them. Valid values of [en] are `text`, `hex`,"
+ " and `base64`. Values encoded as text strings are"
+ " enclosed in double quotes (\"), while strings"
+ " encoded as hexidecimal and base64 are prefixed with"
+ " 0x and 0s, respectively.")
+ parser.add_option("-m", action="store", dest="pattern", type="string",
+ help="Only include attributes with names matching the"
+ " regular expression pattern. The default value for"
+ " pattern is \"^user\\.\", which includes all the"
+ " attributes in the user namespace. Specify \"-\" for"
+ " including all attributes. Refer to attr(5) for a more"
+ " detailed discussion of namespaces.")
+ parser.add_option("--absolute-names", action="store_true", dest="absnames",
+ help="Do not strip leading slash characters ('/')."
+ " The default behaviour is to strip leading slash characters.")
+ parser.add_option("--only-values", action="store_true", dest="onlyvalues",
+ help="Dump out the raw extended attribute value(s)"
+ " without encoding them.")
+
+ (option, args) = parser.parse_args()
+ if not args:
+ print ("Usage: getfattr [-hRLP] [-n name|-d] [-e en] [-m pattern]"
+ " path...")
+ print ("Try `getfattr --help' for more information.")
+ sys.exit(1)
+
+ if option.dump and option.name:
+ print ("-d and -n are mutually exclusive...")
+ sys.exit(1)
+
+ if option.pattern and option.name:
+ print ("-m and -n are mutually exclusive...")
+ sys.exit(1)
+
+ if option.encoding:
+ if (not (option.encoding.strip() == "hex" or
+ option.encoding.strip() == "base64" or
+ option.encoding.strip() == "text")):
+ print ("unrecognized encoding parameter... %s, please use"
+ " `text`, `base64` or `hex`" % option.encoding)
+ sys.exit(1)
+
+ args[0] = os.path.abspath(args[0])
+
+ if option.name:
+ print_header(args[0], option.absnames)
+ try:
+ getfattr(args[0], option)
+ except KeyError as err:
+ print ("Invalid key %s" % err)
+ sys.exit(1)
+ except IOError as err:
+ print (err)
+ sys.exit(1)
+
+ if option.pattern:
+ print_header(args[0], option.absnames)
+ try:
+ xattrs = xattr.listxattr(args[0])
+ for attr in xattrs:
+ if option.dump:
+ option.name = attr.encode('utf-8')
+ getfattr(args[0], option)
+ else:
+ option.name = attr.encode('utf-8')
+ print_getfattr(args[0], option, None)
+
+ except IOError as err:
+ print (err)
+ sys.exit(1)
diff --git a/tests/utils/setfattr.py b/tests/utils/setfattr.py
new file mode 100755
index 00000000000..d714d05edf3
--- /dev/null
+++ b/tests/utils/setfattr.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python2
+
+import os
+import sys
+from optparse import OptionParser
+
+import xattr
+
+def convert(string):
+ tmp_string = string
+ if (string[0] == '0' and
+ (string[1] == 's' or
+ string[1] == 'S')):
+ tmp_string = string.strip('%s%s' %
+ (string[0],
+ string[1]))
+ return tmp_string.decode('base64')
+
+ if (string[0] == '0' and
+ (string[1] == 'x' or
+ string[1] == 'X')):
+ tmp_string = string.split('%s%s' %
+ (string[0],
+ string[1]))
+ return tmp_string[1].decode('hex')
+
+ return tmp_string
+
+if __name__ == '__main__':
+ usage = "usage: %prog [-n name] [-v value] [-x name]"
+ parser = OptionParser(usage=usage)
+ parser.add_option("-n", action="store", dest="name", type="string",
+ help="Specifies the name of the extended attribute to set.")
+ parser.add_option("-v", action="store", dest="value", type="string",
+ help="Specifies the new value of the extended attribute."
+ " There are three methods available for encoding the value."
+ " If the given string is enclosed in double quotes, the"
+ " inner string is treated as text. In that case,"
+ " backslashes and double quotes have special meanings"
+ " and need to be escaped by a preceding backslash. Any"
+ " control characters can be encoded as a backslash"
+ " followed by three digits as its ASCII code in octal."
+ " If the given string begins with 0x or 0X, it expresses"
+ " a hexadecimal number. If the given string begins with"
+ " 0s or 0S, base64 encoding is expected.")
+ parser.add_option("-x", action="store", dest="xname", type="string",
+ help="Remove the named extended attribute entirely.")
+
+ (option,args) = parser.parse_args()
+ if not args:
+ print ("Usage: setfattr {-n name} [-v value] file...")
+ print (" setfattr {-x name} file...")
+ print ("Try `setfattr --help' for more information.")
+ sys.exit(1)
+
+ if option.name and option.xname:
+ print ("-n and -x are mutually exclusive...")
+ sys.exit(1)
+
+ if option.name:
+ if option.value is None:
+ print ("-n option requires -v value...")
+
+ args[0] = os.path.abspath(args[0])
+
+ if option.name and option.value:
+ try:
+ xattr.setxattr(args[0], option.name, convert(option.value))
+ except Exception as err:
+ print (err)
+ sys.exit(1)
+
+ if option.xname:
+ try:
+ xattr.removexattr(args[0], option.xname)
+ except Exception as err:
+ print (err)
+ sys.exit(1)
diff --git a/tests/volume.rc b/tests/volume.rc
index 9c0e20970b5..009f58b7c60 100644
--- a/tests/volume.rc
+++ b/tests/volume.rc
@@ -252,8 +252,8 @@ function gd_is_replace_brick_completed {
}
function dht_get_layout {
- local my_xa=trusted.glusterfs.dht
- getfattr -d -e hex -n $my_xa $1 2> /dev/null | grep "$my_xa=" | cut -d= -f2
+ local my_xa=trusted.glusterfs.dht
+ getfattr -d -e hex -n $my_xa $1 2> /dev/null | grep "$my_xa=" | cut -d= -f2
}
function afr_get_specific_changelog_xattr ()