From 1dfda720c080e39890e5a659a30c8988ca498a7c Mon Sep 17 00:00:00 2001 From: Quentin Bouget Date: Tue, 17 Oct 2017 19:14:41 +0000 Subject: [PATCH] LU-9474 tests: add the stack_trap() utility function This patch implements the stack_trap() function and uses it in test_24d of sanity-hsm (where the need for it first arose). The stack_trap() function is meant to be used to register multiple cleanup actions on a single sigspec (most likely EXIT). Over time, any call to bash's trap builtin in tests should be replaced by a call to stack_trap(). Note that cleanup functions do not need to start with "trap - EXIT". Each test is run in a subshell of its own (in run_one_logged()) and therefore traps do not leak from one test to another. This is true with or without this patch. Test-Parameters: trivial testlist=sanity-hsm,sanity-hsm Change-Id: I47f92a963f094d3d7055592a748e81ce357bff75 Signed-off-by: Quentin Bouget Reviewed-on: https://review.whamcloud.com/29653 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Dominique Martinet Reviewed-by: James Nunez --- lustre/tests/sanity-hsm.sh | 10 ++-------- lustre/tests/test-framework.sh | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lustre/tests/sanity-hsm.sh b/lustre/tests/sanity-hsm.sh index ddef7ab..85224e0 100755 --- a/lustre/tests/sanity-hsm.sh +++ b/lustre/tests/sanity-hsm.sh @@ -286,14 +286,13 @@ copytool_setup() { [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME local copytool_log=$prefix.copytool${arc_id}_log.$agent.log + stack_trap cleanup EXIT do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" if [[ $? != 0 ]]; then [[ $HSMTOOL_NOERROR == true ]] || error "start copytool $facet on $agent failed" echo "start copytool $facet on $agent failed" fi - - trap cleanup EXIT } get_copytool_event_log() { @@ -2174,7 +2173,6 @@ test_24c() { run_test 24c "check that user,group,other request masks work" cleanup_test_24d() { - trap 0 mount -o remount,rw $MOUNT2 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3" } @@ -2201,7 +2199,6 @@ test_24d() { mount -o remount,ro $MOUNT2 do_nodes $(comma_list $(nodes_list)) $LCTL clear - start_full_debug_logging fid2=$(path2fid $file2) [ "$fid1" == "$fid2" ] || @@ -2214,8 +2211,6 @@ test_24d() { $LFS hsm_archive $file1 || error "Fail to archive $file1" wait_request_state $fid1 ARCHIVE SUCCEED - stop_full_debug_logging - $LFS hsm_release $file1 $LFS hsm_restore $file2 wait_request_state $fid1 RESTORE SUCCEED @@ -2226,8 +2221,7 @@ test_24d() { $LFS hsm_release $file2 && error "release should fail on read-only mount" - copytool_cleanup - cleanup_test_24d + return 0 } run_test 24d "check that read-only mounts are respected" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 9874da4..3f02efa 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -5288,6 +5288,29 @@ report_error() { # Test interface ################################## +# usage: stack_trap arg sigspec +# +# stack_trap() behaves like bash's built-in trap, except that it "stacks" the +# command ``arg`` on top of previously defined commands for ``sigspec`` instead +# of overwriting them. +# stacked traps are executed in reverse order of their registration +# +# arg and sigspec have the same meaning as in man (1) trap +stack_trap() +{ + local arg="$1" + local sigspec="$2" + + local cmd="$(trap -p $sigspec)" + + cmd="${cmd#trap -- \'}" + cmd="${cmd%\'*}" + [ -n "$cmd" ] && cmd="; $cmd" + cmd="${arg}$cmd" + + trap "$cmd" $sigspec +} + error_noexit() { report_error "$@" } -- 1.8.3.1