summaryrefslogtreecommitdiffstats
path: root/run_unit_tests.sh
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-10-28 12:32:18 +0200
committerMorgan Richomme <morgan.richomme@orange.com>2016-11-04 09:04:16 +0100
commitb4b14bd13f97c495287ae67334179bf79ce047e9 (patch)
tree3202a96676bdffadd858111129cde38504df9fe8 /run_unit_tests.sh
parent4efc4d814a646bc0a04e23fa761a8188928e8e58 (diff)
Add exit return code for unit tests
Note that this patch should trigger some refactoring 1: repo structure, uggly hack due to the fact that the code is at the root of the repo. The name can be change when cloning leading to python path issues 2: logger is called with harcoded file in functest_logger.py uggly hack to create the file is not already present Basically hacks were necessary to be able to run the unit tests locally and from jenkins JIRA: FUNCTEST-336 Change-Id: Ib88256a167c003805d480f57c218c37d8d5962d8 Signed-off-by: Morgan Richomme <morgan.richomme@orange.com>
Diffstat (limited to 'run_unit_tests.sh')
-rwxr-xr-xrun_unit_tests.sh85
1 files changed, 80 insertions, 5 deletions
diff --git a/run_unit_tests.sh b/run_unit_tests.sh
index 80767d4d3..96b4a5807 100755
--- a/run_unit_tests.sh
+++ b/run_unit_tests.sh
@@ -2,25 +2,100 @@
set -o errexit
set -o pipefail
+# ******************************
+# prepare the env for the tests
+# ******************************
+# clean useless results dir
+# should be done at the end
+# but in case of crash during unit test
+# clean it anyway
+if [ -d "/home/opnfv/functest/results" ]
+then
+ sudo rm -rf /home/opnfv/functest
+fi
+
+# TODO clean that...
+# Create log dir if needed
+# log shall be disabled during unit tests
+# fix to be done in Logger
+if [ ! -d "/home/opnfv/functest/results" ]
+then
+ echo "Create dummy log file...."
+ sudo mkdir -p /home/opnfv/functest/results/odl
+ sudo touch /home/opnfv/functest/results/functest.log
+ sudo touch /home/opnfv/functest/results/odl/stdout.txt
+ sudo chmod -Rf a+rw /home/opnfv
+fi
+
+# Either Workspace is set (CI)
+# then useless log files must belong to jenkins:jenkins
+# or it is local tests and we do not care
+if [ -z $WORKSPACE ]
+then
+ WORKSPACE="."
+else
+ sudo chown -Rf jenkins:jenkins /home/opnfv
+ # as we import the module from the home repo
+ # and in jenkins the name is different
+ # functest-verify-master != functest
+ # make some ugly adjustments...
+ cd $WORKSPACE
+ export PYTHONPATH="${PYTHONPATH}:$WORKSPACE"
+ cd ..
+
+ if [ ! -d "./functest" ]
+ then
+ ln -s functest-verify-master functest
+ fi
+fi
+
+
+# ***************
+# Run unit tests
+# ***************
echo "Running unit tests..."
-cd .
# start vitual env
-virtualenv ./functest_venv
-source ./functest_venv/bin/activate
+virtualenv $WORKSPACE/functest_venv
+source $WORKSPACE/functest_venv/bin/activate
# install python packages
easy_install -U setuptools
easy_install -U pip
-pip install -r docker/requirements.pip
-pip install -e .
+pip install -r $WORKSPACE/docker/requirements.pip
+pip install -e $WORKSPACE
+
+python $WORKSPACE/setup.py develop
# unit tests
+# TODO: remove cover-erase
+# To be deleted when all functest packages will be listed
nosetests --with-xunit \
--with-coverage \
+ --cover-erase \
--cover-package=functest.core.TestCasesBase \
--cover-package=functest.testcases.Controllers.ODL.OpenDaylightTesting \
--cover-xml \
+ --cover-html \
unit_tests
+rc=$?
deactivate
+
+# *******
+# clean
+# *******
+# First as we had to start the test from ..
+# Push the results upstream for jenkins
+if [ $WORKSPACE != "." ]
+then
+ mv coverage.xml nosetests.xml $WORKSPACE
+fi
+
+# Clean useless logs
+if [ -d "/home/opnfv/functest/results" ]
+then
+ sudo rm -rf /home/opnfv/functest/results
+fi
+
+exit $rc