From db4e3a371c66c400b3cb95d4e7701625bef4ac95 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Tue, 11 Aug 2015 13:45:26 +0530 Subject: tests: call cleanup on receiving external signals INT, TERM and HUP problem: when executing testcases manually, some time we may want to terminate the testcase execution in between due to various reasons. Existing testcase flow has no mechanism to call cleanup before they terminate abnormally, hence we endup with volume setups and mount points uncleaned. Solution: This patch traps such kind of abnormal terminations and calls 'cleanup' function soon after they are caught and then terminates the testcases with appropriate status.. $ ./tests/basic/mount-nfs-auth.t 1..87 ========================= TEST 1 (line 8): glusterd ok 1 RESULT 1: 0 ========================= TEST 2 (line 9): pidof glusterd ok 2 RESULT 2: 0 ========================= TEST 3 (line 10): gluster -mode=script --wignore volume info No volumes present ok 3 RESULT 3: 0 ^C received external signal --INT--, calling 'cleanup' ... $ glusterd && gluster vol status No volumes present Change-Id: Ia51a850c356e599b8b789cec22b9bb5e87e1548a BUG: 1252374 Signed-off-by: Prasanna Kumar Kalever Reviewed-on: http://review.gluster.org/11882 Reviewed-by: Niels de Vos Tested-by: NetBSD Build System Reviewed-by: Raghavendra Talur --- tests/include.rc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/include.rc b/tests/include.rc index bf480c22bdb..1d084c03357 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -525,6 +525,16 @@ function cleanup() return 0 } +function force_terminate () { + local ret=$?; + >&2 echo -e "\nreceived external"\ + "signal --`kill -l $ret`--, calling 'cleanup' ...\n"; + cleanup; + exit $ret; +} + +trap force_terminate INT TERM HUP + function volinfo_field() { local vol=$1; -- cgit