From 2a8e6841a3b6bf18f09f1b3dc14a9733251df351 Mon Sep 17 00:00:00 2001
From: Clark Boylan <clark.boylan@gmail.com>
Date: Mon, 8 Apr 2013 16:34:39 -0700
Subject: [PATCH] Handle new subunit version 2 log files.

* modules/jenkins/files/slave_scripts/run-tox.sh: Subunit v2 log files
written by testr will output to .testrepository/$id.2. If this file is
present copy it instead of .testrepository/$id as the subunit log.

Change-Id: I3b43aa2c267773ee9d51ca369f0236e8bf9d628d
Reviewed-on: https://review.openstack.org/26417
Reviewed-by: lifeless <robertc@robertcollins.net>
Reviewed-by: James E. Blair <corvus@inaugust.com>
Approved: Jeremy Stanley <fungi@yuggoth.org>
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Tested-by: Jenkins
---
 .../jenkins/files/slave_scripts/run-tox.sh    | 38 +++++++++----------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/modules/jenkins/files/slave_scripts/run-tox.sh b/modules/jenkins/files/slave_scripts/run-tox.sh
index ab8e79b3d6..af61dd4bf8 100755
--- a/modules/jenkins/files/slave_scripts/run-tox.sh
+++ b/modules/jenkins/files/slave_scripts/run-tox.sh
@@ -53,12 +53,27 @@ echo "======================================================================"
 .tox/$venv/bin/pip freeze
 echo "======================================================================"
 
-if [ -f ".testrepository/0" ]
-then
-    cp .testrepository/0 ./subunit_log.txt
+if [ -d ".testrepository" ] ; then
+    if [ -f ".testrepository/0.2" ] ; then
+        cp .testrepository/0.2 ./subunit_log.txt
+    elif [ -f ".testrepository/0" ] ; then
+        cp .testrepository/0 ./subunit_log.txt
+    fi
     .tox/$venv/bin/python /usr/local/jenkins/slave_scripts/subunit2html.py ./subunit_log.txt testr_results.html
     gzip -9 ./subunit_log.txt
     gzip -9 ./testr_results.html
+
+    foundcount=$(.tox/$venv/bin/python testr list-tests | sed -e '1d' | wc -l)
+    rancount=$(.tox/$venv/bin/python testr last | sed -ne 's/Ran \([0-9]\+\).*tests in.*/\1/p')
+    if [ "$foundcount" -ne "$rancount" ] ; then
+        echo
+        echo "The number of tests found did not match the number of tests"
+        echo "that were run. This indicates a fatal error occured while"
+        echo "running the tests."
+        echo "Tests found: $foundcount Tests ran: $rancount"
+        echo
+        exit 1
+    fi
 fi
 
 sudo /usr/local/jenkins/slave_scripts/jenkins-sudo-grep.sh post
@@ -105,21 +120,4 @@ else
     echo
 fi
 
-if [ -d ".testrepository" ]
-then
-    source .tox/$venv/bin/activate
-    foundcount=$(testr list-tests | sed -e '1d' | wc -l)
-    rancount=$(testr last | sed -ne 's/Ran \([0-9]\+\).*tests in.*/\1/p')
-    if [ "$foundcount" -ne "$rancount" ]
-    then
-        echo
-        echo "The number of tests found did not match the number of tests"
-        echo "that were run. This indicates a fatal error occured while"
-        echo "running the tests."
-        echo "Tests found: $foundcount Tests ran: $rancount"
-        echo
-        exit 1
-    fi
-fi
-
 exit $result