diff options
author | Harshavardhana <harsha@harshavardhana.net> | 2014-08-19 16:14:03 -0700 |
---|---|---|
committer | Harshavardhana <harsha@harshavardhana.net> | 2014-08-26 15:27:29 -0700 |
commit | 74cf4e1920db1edae6728cfe632e4ca7aea5be59 (patch) | |
tree | 33f116ca794e57979ceccd340f8151995e51569a /tests | |
parent | 77ce88681c15e711e87d23b891a488b2fd825eb0 (diff) |
porting: `pidof` portability for OSX/FreeBSD
- Provide a portable `pidof` just to be used specifically with
glusterfs regression tests on OSX and FreeBSD. This was
written after countless hrs of effort to get a sane `pidof`
working on either of the environments.
`pidof` comes at the wake of lack of proper procfs support
and also incompatible way of handling process names since
glusterd/glusterfs are symbolic links to 'glusterfsd'
- tests/utils/* directory should be part of 'PATH' to avoid
abspath calculation using $(dirname)
- cleanup() - rpcinfo command prints error on FreeBSD/OSX fix it
Change-Id: I35f86273624cb279da1c8fae056ca27669e251d8
BUG: 1131713
Signed-off-by: Harshavardhana <harsha@harshavardhana.net>
Reviewed-on: http://review.gluster.org/8499
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/afr/self-heal.t | 12 | ||||
-rw-r--r-- | tests/bugs/bug-1111490.t | 4 | ||||
-rwxr-xr-x | tests/bugs/bug-857330/normal.t | 2 | ||||
-rwxr-xr-x | tests/bugs/bug-857330/xml.t | 2 | ||||
-rw-r--r-- | tests/include.rc | 22 | ||||
-rwxr-xr-x | tests/utils/create-files.py | 2 | ||||
-rwxr-xr-x | tests/utils/gfid-access.py | 1 | ||||
-rwxr-xr-x | tests/utils/pidof.py | 45 |
8 files changed, 72 insertions, 18 deletions
diff --git a/tests/basic/afr/self-heal.t b/tests/basic/afr/self-heal.t index acdd6b73ca0..d02820ca624 100644 --- a/tests/basic/afr/self-heal.t +++ b/tests/basic/afr/self-heal.t @@ -59,7 +59,7 @@ TEST ls $B0/brick0/def/ghi/file2.txt TEST ls $B0/brick0/jkl/mno/file.txt TEST ! ls $B0/brick0/abc/ghi EXPECT "$NEW_UID$NEW_GID" stat -c %u%g $B0/brick0/abc/def/file_abc_def_2.txt -TEST diff <($AREQUAL_PATH/arequal-checksum -p $B0/brick0 -i .glusterfs) <($AREQUAL_PATH/arequal-checksum -p $B0/brick1 -i .glusterfs) +TEST diff <(arequal-checksum -p $B0/brick0 -i .glusterfs) <(arequal-checksum -p $B0/brick1 -i .glusterfs) #Cleanup TEST rm -rf $M0/* @@ -83,7 +83,7 @@ EXPECT_WITHIN $HEAL_TIMEOUT "0" afr_get_pending_heal_count $V0 #check heal has happened in the correct direction TEST test -d $B0/brick0/file -TEST diff <($AREQUAL_PATH/arequal-checksum -p $B0/brick0 -i .glusterfs) <($AREQUAL_PATH/arequal-checksum -p $B0/brick1 -i .glusterfs) +TEST diff <(arequal-checksum -p $B0/brick0 -i .glusterfs) <(arequal-checksum -p $B0/brick1 -i .glusterfs) #Cleanup TEST rm -rf $M0/* @@ -106,7 +106,7 @@ EXPECT_WITHIN $HEAL_TIMEOUT "0" afr_get_pending_heal_count $V0 #check heal has happened in the correct direction EXPECT "777" stat -c %a $B0/brick0/file -TEST diff <($AREQUAL_PATH/arequal-checksum -p $B0/brick0 -i .glusterfs) <($AREQUAL_PATH/arequal-checksum -p $B0/brick1 -i .glusterfs) +TEST diff <(arequal-checksum -p $B0/brick0 -i .glusterfs) <(arequal-checksum -p $B0/brick1 -i .glusterfs) #Cleanup TEST rm -rf $M0/* @@ -130,7 +130,7 @@ EXPECT_WITHIN $HEAL_TIMEOUT "0" afr_get_pending_heal_count $V0 #check heal has happened in the correct direction EXPECT "$NEW_UID$NEW_GID" stat -c %u%g $B0/brick0/file -TEST diff <($AREQUAL_PATH/arequal-checksum -p $B0/brick0 -i .glusterfs) <($AREQUAL_PATH/arequal-checksum -p $B0/brick1 -i .glusterfs) +TEST diff <(arequal-checksum -p $B0/brick0 -i .glusterfs) <(arequal-checksum -p $B0/brick1 -i .glusterfs) #Cleanup TEST rm -rf $M0/* @@ -161,7 +161,7 @@ EXPECT_WITHIN $HEAL_TIMEOUT "0" afr_get_pending_heal_count $V0 #check heal has happened in the correct direction EXPECT 0 stat -c %s $B0/brick1/file -TEST diff <($AREQUAL_PATH/arequal-checksum -p $B0/brick0 -i .glusterfs) <($AREQUAL_PATH/arequal-checksum -p $B0/brick1 -i .glusterfs) +TEST diff <(arequal-checksum -p $B0/brick0 -i .glusterfs) <(arequal-checksum -p $B0/brick1 -i .glusterfs) #Cleanup TEST rm -rf $M0/* @@ -209,7 +209,7 @@ EXPECT_WITHIN $HEAL_TIMEOUT "0" afr_get_pending_heal_count $V0 #check heal has happened in the correct direction TEST test -f $B0/brick0/hard_link_to_file TEST test -h $B0/brick0/link_to_file -TEST diff <($AREQUAL_PATH/arequal-checksum -p $B0/brick0 -i .glusterfs) <($AREQUAL_PATH/arequal-checksum -p $B0/brick1 -i .glusterfs) +TEST diff <(arequal-checksum -p $B0/brick0 -i .glusterfs) <(arequal-checksum -p $B0/brick1 -i .glusterfs) #Cleanup TEST rm -rf $M0/* diff --git a/tests/bugs/bug-1111490.t b/tests/bugs/bug-1111490.t index 39aa0f9a69e..7b13c8798ec 100644 --- a/tests/bugs/bug-1111490.t +++ b/tests/bugs/bug-1111490.t @@ -16,7 +16,7 @@ TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 # create file with specific gfid uuid=`uuidgen` -EXPECT "File creation OK" python2 $(dirname $0)/../utils/gfid-access.py $M0 ROOT file0 $uuid file +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 @@ -27,6 +27,6 @@ TEST umount $M0 TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0 --aux-gfid-mount # touch the file again (gfid-access.py handles errno) -EXPECT "File creation OK" python2 $(dirname $0)/../utils/gfid-access.py $M0 ROOT file0 $uuid file +EXPECT "File creation OK" gfid-access.py $M0 ROOT file0 $uuid file cleanup; diff --git a/tests/bugs/bug-857330/normal.t b/tests/bugs/bug-857330/normal.t index 44635a19e42..b7409078775 100755 --- a/tests/bugs/bug-857330/normal.t +++ b/tests/bugs/bug-857330/normal.t @@ -14,7 +14,7 @@ TEST $CLI volume start $V0; TEST glusterfs -s $H0 --volfile-id=$V0 $M0; -TEST python2 $(dirname $0)/../../utils/create-files.py --multi -b 10 -d 10 -n 10 $M0; +TEST create-files.py --multi -b 10 -d 10 -n 10 $M0; EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0 diff --git a/tests/bugs/bug-857330/xml.t b/tests/bugs/bug-857330/xml.t index 2029c343093..bacca453dbe 100755 --- a/tests/bugs/bug-857330/xml.t +++ b/tests/bugs/bug-857330/xml.t @@ -15,7 +15,7 @@ TEST $CLI volume start $V0; TEST glusterfs -s $H0 --volfile-id=$V0 $M0; -TEST python2 $(dirname $0)/../../utils/create-files.py --multi -b 10 -d 10 -n 10 $M0; +TEST create-files.py --multi -b 10 -d 10 -n 10 $M0; EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0 diff --git a/tests/include.rc b/tests/include.rc index 6b933b036f7..38f713ae73a 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -25,6 +25,8 @@ MOUNT_TYPE_FUSE="fuse.glusterfs" GREP_MOUNT_OPT_RO="grep (ro" GREP_MOUNT_OPT_RW="grep (rw" +PATH=$PATH:${PWD}/tests/utils + case $OSTYPE in Linux) H0=${H0:=`hostname --fqdn`}; # hostname @@ -256,6 +258,12 @@ which killall > /dev/null || { } } +which pidof > /dev/null || { + pidof() { + pidof.py $1 + } +} + stat -c %s /dev/null > /dev/null 2>&1 || { stat() { local format="" @@ -322,17 +330,17 @@ function cleanup() # unregister nfs and related services from portmapper/rpcbind ## nfs - rpcinfo -d 100003 3 + rpcinfo -d 100003 3 2>/dev/null || true; ## mountd - rpcinfo -d 100005 1 - rpcinfo -d 100005 3 + rpcinfo -d 100005 1 2>/dev/null || true; + rpcinfo -d 100005 3 2>/dev/null || true; ## nlockmgr - rpcinfo -d 100021 1 - rpcinfo -d 100021 4 + rpcinfo -d 100021 1 2>/dev/null || true; + rpcinfo -d 100021 4 2>/dev/null || true; ## nfs_acl - rpcinfo -d 100227 3 + rpcinfo -d 100227 3 2>/dev/null || true; - type cleanup_lvm &>/dev/null && cleanup_lvm + type cleanup_lvm &>/dev/null && cleanup_lvm || true; case `uname -s` in Linux) diff --git a/tests/utils/create-files.py b/tests/utils/create-files.py index 0d937eff978..05cf1279999 100755 --- a/tests/utils/create-files.py +++ b/tests/utils/create-files.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # This script was developed by Vijaykumar Koppad (vkoppad@redhat.com) # The latest version of this script can found at diff --git a/tests/utils/gfid-access.py b/tests/utils/gfid-access.py index 25fe35bf50b..4fd4b6dfa8d 100755 --- a/tests/utils/gfid-access.py +++ b/tests/utils/gfid-access.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python2 # # Copyright (c) 2011-2014 Red Hat, Inc. <http://www.redhat.com> # This file is part of GlusterFS. diff --git a/tests/utils/pidof.py b/tests/utils/pidof.py new file mode 100755 index 00000000000..575b899b6cc --- /dev/null +++ b/tests/utils/pidof.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import sys + +try: + import psutil +except ImportError: + print("Please install psutil --> pip install psutil") + sys.exit(1) + +def pmap_find(p, name): + for m in p.memory_maps(grouped=True): + if m.path.endswith("%s.so" % name): + return True + continue + return False + +def pidof(processname): + for p in psutil.process_iter(): + if p.pid == 0: + continue + if "gluster" in processname: + if processname == "glusterd" and pmap_find(p, "glusterd"): + print (p.pid) + if processname == "glusterfs" and pmap_find(p, "client"): + print (p.pid) + if processname == "glusterfsd" and pmap_find(p, "posix-acl"): + print (p.pid) + continue + if processname.strip() == p.name(): + print (p.pid) + +def main(argv): + if len(argv) < 2: + sys.stderr.write("Usage: %s <processname>\n" % (argv[0],)) + return 1 + try: + pidof(argv[1]) + except Exception as err: + print err + sys.stderr.write("Please be root - %s\n" % err); + sys.exit(1) + +if __name__ == "__main__": + main(sys.argv) |