From 4b4441390cbbc969f010e7133ea7aa021877edd2 Mon Sep 17 00:00:00 2001
From: Bob Ball <bob.ball@citrix.com>
Date: Sat, 15 Feb 2014 12:13:09 +0000
Subject: [PATCH] Updated to allow disowning of the run_tests process

---
 disown_child.sh |  5 +++++
 run_tests.sh    | 25 ++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100755 disown_child.sh
 mode change 100644 => 100755 run_tests.sh

diff --git a/disown_child.sh b/disown_child.sh
new file mode 100755
index 0000000..63ef3d8
--- /dev/null
+++ b/disown_child.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+THISDIR=$(dirname $(readlink -f $0))
+$THISDIR/$1 </dev/null &
+disown
diff --git a/run_tests.sh b/run_tests.sh
old mode 100644
new mode 100755
index cd62aa8..f62b967
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+exec > run_tests.log 2>&1
+
 set -ex
 
 #REPLACE_ENV
@@ -59,8 +61,8 @@ export SKIP_DEVSTACK_GATE_PROJECT=1
 sudo pip install -i https://pypi.python.org/simple/ XenAPI
 
 # These came from the Readme
-export REPO_URL=https://review.openstack.org/p
-export ZUUL_URL=/home/jenkins/workspace-cache
+export ZUUL_URL=https://review.openstack.org/p
+export REPO_URL=/home/jenkins/workspace-cache
 export WORKSPACE=/home/jenkins/workspace/testing
 
 # Check out a custom branch
@@ -107,4 +109,21 @@ git clone https://github.com/matelakat/devstack-gate -b xenserver-integration
 #( sudo mkdir -p /opt/stack/new && sudo chown -R jenkins:jenkins /opt/stack/new && cd /opt/stack/new && git clone https://github.com/matelakat/devstack-gate -b xenserver-integration )
 
 cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh
-./safe-devstack-vm-gate-wrap.sh
\ No newline at end of file
+
+# Trap the exit code + log a final message
+function trapexit {
+    exit_code=$?
+    if [ $exit_code -eq 0 ]; then
+	echo "Final result: Tests passed"
+    else
+	echo "Final result: Tests failed"
+    fi
+
+    # Do not use 'exit' - bash will preserve the status
+}
+
+trap trapexit EXIT
+
+# OpenStack doesn't care much about unset variables...
+set +ue
+source ./safe-devstack-vm-gate-wrap.sh