From 0e122e8e356369b19d42fc423e67594c3a153cfc Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Wed, 30 Sep 2015 11:55:40 +0200 Subject: [PATCH] Add a tox target to run functional tests locally Now 'tox -efunc' can be invoked to run all functional tests in the 'venv' tox environment. Also `tox -efunc element-name` can be used to run function tests for one element (e.g. ironic-agent). Change-Id: Ia685d1b2a7deef2f8b98876ac09792134dd30f2f --- doc/source/developer/developing_elements.rst | 12 +++++++ tests/run_functests.sh | 8 +++-- tests/test_elements.bash | 34 ++++++++++++++------ tox.ini | 4 +++ 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/doc/source/developer/developing_elements.rst b/doc/source/developer/developing_elements.rst index aaa0739e..da09d32f 100644 --- a/doc/source/developer/developing_elements.rst +++ b/doc/source/developer/developing_elements.rst @@ -310,6 +310,18 @@ order to create a test case, follow these steps: * To exit early and indicate a success, touch a file /tmp/dib-test-should-fail in the image chroot, then exit 1. +To run functional tests locally, install and start docker, then use +the following tox command:: + + tox -efunc + +Note that running functional tests requires *sudo* rights, thus you may be +asked for your password. + +To run functional tests for one element, append its name to the command:: + + tox -efunc ironic-agent + Additionally, elements can be tested using python unittests. To create a a python test: diff --git a/tests/run_functests.sh b/tests/run_functests.sh index 8c903e27..cb98cb1c 100755 --- a/tests/run_functests.sh +++ b/tests/run_functests.sh @@ -3,7 +3,11 @@ set -eux set -o pipefail -$(dirname $0)/image_output_formats.bash -$(dirname $0)/test_elements.bash +element=${1:-} + +if [ -z $element ]; then + $(dirname $0)/image_output_formats.bash +fi +$(dirname $0)/test_elements.bash $element echo "Tests passed!" diff --git a/tests/test_elements.bash b/tests/test_elements.bash index 068f0d19..9acaa2bb 100755 --- a/tests/test_elements.bash +++ b/tests/test_elements.bash @@ -4,16 +4,30 @@ set -eux set -o pipefail basedir=$(dirname $0) +requested_element=${1:-} source $basedir/test_functions.bash -for test_element in $basedir/../elements/*/test-elements/*; do - if [ -d "$test_element" ]; then - # our element name is two dirs up - element_name=$(basename $(dirname $(dirname $test_element))) - element_type=disk - if [ -f "$test_element/element-type" ]; then - element_type=$(cat "$test_element/element-type") - fi - run_${element_type}_element_test "$(basename $test_element)" "$element_name" +function run_on_element { + test_element=$1 + # our element name is two dirs up + local element_name=$(basename $(dirname $(dirname $test_element))) + local element_type=disk + if [ -f "$test_element/element-type" ]; then + element_type=$(cat "$test_element/element-type") fi -done + run_${element_type}_element_test "$(basename $test_element)" "$element_name" +} + +if [ -z $requested_element ]; then + for test_element in $basedir/../elements/*/test-elements/*; do + if [ -d "$test_element" ]; then + run_on_element "$test_element" + fi + done +else + for test_element in $basedir/../elements/$requested_element/test-elements/*; do + if [ -d "$test_element" ]; then + run_on_element "$test_element" + fi + done +fi diff --git a/tox.ini b/tox.ini index 828c27dd..d7965f83 100644 --- a/tox.ini +++ b/tox.ini @@ -19,6 +19,10 @@ commands = [testenv:venv] commands = {posargs} +[testenv:func] +envdir = {toxworkdir}/venv +commands = {toxinidir}/tests/run_functests.sh {posargs} + [testenv:cover] setenv = PYTHON=coverage run --source diskimage_builder commands = bash -c 'if [ ! -d ./.testrepository ] ; then testr init ; fi'