summaryrefslogtreecommitdiffstats
path: root/run-tests.sh
diff options
context:
space:
mode:
authorShyamsundarR <srangana@redhat.com>2018-08-08 18:29:01 -0400
committerAtin Mukherjee <amukherj@redhat.com>2018-08-09 14:42:15 +0000
commit69c557ad8468f9e32090cbef78512f82a98f7043 (patch)
tree9a7c6c3736b6205d93afb7c6a67e4e745a54d9e2 /run-tests.sh
parent22d5540f5618ea0726a5eab1252163c48124cc06 (diff)
tests: Add ability to preserve older tarball for retried tests
When a test is retried, the cleanup directives overwrite the older tarball with the latest one, thus losing the logs from the failed run. This patch changes run-tests.sh to rename the older tarball when retrying a test, thus preserving the same. The tarball is renamed using a time stamp and optionally a trailing sequence number, in case the test fails within the very second. Although the sequence # is not strictly required as we retry only once, it provides a defence for any future enhancements to the same. Fixes: bz#1614062 Change-Id: I9afe486b0b6f6a26f2ad0642e38bc0ba15b3ecc9 Signed-off-by: ShyamsundarR <srangana@redhat.com>
Diffstat (limited to 'run-tests.sh')
-rwxr-xr-xrun-tests.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/run-tests.sh b/run-tests.sh
index c8eaf9b..5efdc20 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -17,6 +17,38 @@ kill_after_time=5
OSTYPE=$(uname -s)
+# Function for use in generating filenames with increasing "-<n>" index
+# In:
+# $1 basepath: Directory where file needs to be created
+# $2 filename: Name of the file sans extension
+# $3 extension: Extension string that would be appended to the generated
+# filename
+# Out:
+# string of next available filename with appended "-<n>" if applicable
+# Example:
+# Interested routines that want to create a file name, say foo.txt at
+# location /var/log/gluster would pass in "/var/log/gluster" "foo" "txt"
+# and be returned next available foo.txt filename to create. If foo.txt
+# is available then foo is returned, else foo-<n> (where n is the next
+# integer) is returned for use"
+# Notes:
+# Function will not accept empty extension, and will return the same name
+# over and over (which can be fixed when there is a use-case for it)
+function get_next_filename()
+{
+ local basepath=$1
+ local filename=$2
+ local extension=$3
+ local next=2
+ local tfilename=${filename}
+ while [ -e "${basepath}/${tfilename}.${extension}" ]; do
+ tfilename="${filename}-${next}"
+ next=$((next+1))
+ done
+
+ echo "$tfilename"
+}
+
function check_dependencies()
{
## Check all dependencies are present
@@ -320,6 +352,13 @@ function run_tests()
echo " * we got some spurious failures *"
echo " *********************************"
echo ""
+ # backup old tar ball with time stamp
+ # TODO: Using gluster CLI here is possibly not the best thing!
+ logdir=$(gluster --print-logdir)
+ basetarname=$(basename "$t" .t)
+ savetarname=$(get_next_filename "${logdir}" "${basetarname}-$(date +%H:%M:%S)" "tar" | tail -1)
+ mv "$logdir"/"$basetarname".tar "$logdir"/"$savetarname".tar
+
if [ ${timeout_cmd_exists} == "yes" ]; then
timeout -k ${kill_after_time} ${cmd_timeout} prove -vmfe '/bin/bash' ${t}
else