]> sourceware.org Git - lvm2.git/commitdiff
tests: simplify removal of dangling bg procs
authorOndrej Kozina <okozina@redhat.com>
Mon, 27 Apr 2015 08:33:45 +0000 (10:33 +0200)
committerOndrej Kozina <okozina@redhat.com>
Tue, 28 Apr 2015 20:31:40 +0000 (22:31 +0200)
some tests left dangling bg processes originating in
lvm2 commands being able to spawn any bg polling process
(lvchange, vgchange, pvmove, lvconvert...)

Initial fn 'add_to_kill_list' should collect processes with
specific parameters (proc's command line and parent processes ID).
After testing finishes the fn kill_listed_processes should remove these
listed by 'add_to_kill_list'.

Unfortunately it proved to be prone to an error especially in scenarios
where cmd line of initiating command contained characters required to
be espaced before passing to shell script to make it work correctly.
(Or if cmd spawned more than one bg process with same cmd line. i.e.:
vgchange or lvchange).

The new implementation is much simpler. It uses env. variable (LVM_TEST_TAG)
for marking a process desired to be killed later or during test env. teardown.
(i.e.: LVM_TEST_TAG=kill_me_$PREFIX to kill only processes related to
current test environment)

test/lib/aux.sh
test/shell/pvmove-abort-all.sh
test/shell/pvmove-abort.sh
test/shell/pvmove-basic.sh
test/shell/pvmove-restart.sh

index 0e59d6e2cda70bf189b21a9bcc9745af91f77111..24be3233900d776c779e9da9245f019513c50697 100644 (file)
@@ -233,26 +233,18 @@ kill_sleep_kill_() {
        fi
 }
 
-# $1 cmd line
-# $2 optional parms for pgrep
-add_to_kill_list() {
-       local p=$(pgrep ${@:2} -f "$1" 2>/dev/null)
-       test -z "$p" || echo "$p:$1" >> kill_list
+print_procs_by_tag_() {
+       ps -o pid=,args= ehax 2>/dev/null | grep -weLVM_TEST_TAG=${1:-kill_me_$PREFIX} 2>/dev/null || true
+}
+
+count_processes_with_tag() {
+       print_procs_by_tag_ | wc -l
 }
 
 kill_listed_processes() {
-       local tmp
-       local pid
-       local cmd
-       test -f kill_list || return 0
-       while read tmp; do
-               pid=${tmp%%:*}
-               cmd=${tmp##*:}
-               for tmp in $(pgrep -f "$cmd" -d ' '); do
-                       test "$tmp" = "$pid" && kill -9 "$tmp"
-               done
-       done < kill_list
-       rm -f kill_list
+       while read pid b; do
+               test -z "$pid" || kill -9 $pid
+       done <<< $(print_procs_by_tag_ $@)
 }
 
 teardown() {
index de6d8c9ac96819636b26e0f30a113b5bd3947941..5bca8a22f7491767bb1f4253dd4f1785388064cc 100644 (file)
@@ -50,12 +50,9 @@ if test -z "$backgroundarg" ; then
        aux wait_pvmove_lv_ready "$vg1-pvmove0"
         lvs -a $vg $vg1
 else
-       "${cmd1[@]}"
-       aux add_to_kill_list "${cmd1[*]}" -P 1
-       "${cmd2[@]}"
-       aux add_to_kill_list "${cmd2[*]}" -P 1
-       "${cmd3[@]}"
-       aux add_to_kill_list "${cmd3[*]}" -P 1
+       LVM_TEST_TAG="kill_me_$PREFIX" "${cmd1[@]}"
+       LVM_TEST_TAG="kill_me_$PREFIX" "${cmd2[@]}"
+       LVM_TEST_TAG="kill_me_$PREFIX" "${cmd3[@]}"
 fi
 
 # test removal of all pvmove LVs
index 3165c6f5fae2543631cffe7c4920c4eb23415a5c..2332521761410cfb3fed9cfeb17a55240818fe5a 100644 (file)
@@ -40,10 +40,8 @@ if test -z "$backgroundarg" ; then
        "${cmd2[@]}" &
        aux wait_pvmove_lv_ready "$vg-pvmove1"
 else
-       "${cmd1[@]}"
-       aux add_to_kill_list "${cmd1[*]}" -P 1
-       "${cmd2[@]}"
-       aux add_to_kill_list "${cmd2[*]}" -P 1
+       LVM_TEST_TAG="kill_me_$PREFIX" "${cmd1[@]}"
+       LVM_TEST_TAG="kill_me_$PREFIX" "${cmd2[@]}"
 fi
 
 # remove specific device
index d5b7845e69438aa6f945c0929c7c38cee96aab0c..f7830da80517f84bad14cfaeb62d282cc9dbd3b4 100644 (file)
@@ -334,9 +334,7 @@ check_and_cleanup_lvs_
 
 #COMM "pvmove abort"
 restore_lvs_
-cmd=(pvmove $mode -i100 -b "$dev1" "$dev3")
-"${cmd[@]}"
-aux add_to_kill_list "${cmd[*]}" -P 1
+LVM_TEST_TAG="kill_me_$PREFIX" pvmove $mode -i100 -b "$dev1" "$dev3"
 pvmove --abort
 check_and_cleanup_lvs_
 
index 88dfebedb867a3fd49965d8e556255f0898c55db..b91f6244e521fe704844ca36bbf82bef61d56d52 100644 (file)
@@ -79,7 +79,7 @@ dmsetup table
 
 # Restart pvmove
 # use exclusive activation to have usable pvmove without cmirrord
-vgchange -aey $vg
+LVM_TEST_TAG="kill_me_$PREFIX" vgchange --config 'activation{polling_interval=10}' -aey $vg
 aux wait_pvmove_lv_ready "$vg-pvmove0"
 dmsetup table
 
@@ -90,6 +90,7 @@ pvmove --abort
 lvs -a -o+devices $vg
 
 lvremove -ff $vg
+aux kill_listed_processes
 done
 
 # Restore delayed device back
This page took 0.043618 seconds and 5 git commands to generate.