From c6d1b9797dd2850cd0b8be7f17a41db525cbe93d Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Sun, 10 Apr 2016 10:51:11 -0400 Subject: tests: use trap mechanism to ensure that proper cleanups happen This actually consists of several parts. * Added a generic cleanup-scheduling mechanism. Instead of calling "trap ... EXIT" directly, just call "push_trapfunc ..." instead and your cleanup function will be called along with any others. * Converted a few tests to use push_trapfunc. * Added "push_trapfunc cleanup_lvm" to snapshot.rc to address the particular problem that's driving this - snapshot tests not calling cleanup_lvm on their own and leaving bad state for the next test. Change-Id: I548a97a26328390992fc71ee1f03c0463703f9d7 Signed-off-by: Jeff Darcy Reviewed-on: http://review.gluster.org/13933 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Atin Mukherjee Reviewed-by: Rajesh Joseph --- tests/traps.rc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/traps.rc (limited to 'tests/traps.rc') diff --git a/tests/traps.rc b/tests/traps.rc new file mode 100644 index 00000000000..f011960c97e --- /dev/null +++ b/tests/traps.rc @@ -0,0 +1,22 @@ +#!/bin/bash + +# Make sure this only gets included/executed once. Unfortunately, bash doesn't +# usually distinguish between values that are unset and values that are null. +# To work around that, we declare TRAPFUNCS to be a one-element array right at +# the start, but that one element is : which is defined to do nothing. + +if [ ${#TRAPFUNCS[@]} = 0 ]; then + TRAPFUNCS=(:) + + push_trapfunc () { + TRAPFUNCS[${#TRAPFUNCS[@]}]="$@" + } + + execute_trapfuncs () { + for i in "${TRAPFUNCS[@]}"; do + $i + done + } + + trap execute_trapfuncs EXIT +fi -- cgit