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>
This commit is contained in:
parent
77ce88681c
commit
74cf4e1920
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,6 +31,7 @@ log
|
||||
|
||||
# Generated files
|
||||
tests/env.rc
|
||||
tests/utils/libcxattr.pyc
|
||||
dht_layout_unittest
|
||||
mem_pool_unittest
|
||||
tests/utils/arequal-checksum
|
||||
|
@ -60,6 +60,14 @@ function check_dependencies()
|
||||
MISSING="$MISSING pidof"
|
||||
fi
|
||||
|
||||
# check for psutil python package
|
||||
test `uname -s` == "Darwin" || test `uname -s` == "FreeBSD" && {
|
||||
pip show psutil | grep -q psutil >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
MISSING="$MISSING psutil"
|
||||
fi
|
||||
}
|
||||
|
||||
## If dependencies are missing, warn the user and abort
|
||||
if [ "x$MISSING" != "x" ]; then
|
||||
test "x${force}" != "xyes" && echo "Aborting."
|
||||
|
@ -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/*
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
45
tests/utils/pidof.py
Executable file
45
tests/utils/pidof.py
Executable file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user