From cb7e968873248268e5c5bc15e71816d9aeda265d Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Wed, 7 May 2014 12:15:57 +0530 Subject: [PATCH] Modify unit tests and func tests * Updated tox.ini * Created .unittests and .functests * Added tempurl to pipeline in conf files so that tempurl tests are not skipped * Updated .gitignore file Signed-off-by: Prashanth Pai --- .functests | 88 +++++++++++++++++++ .gitignore | 22 +++-- unittests.sh => .unittests | 19 ++-- .../gswauth/conf/proxy-server.conf | 5 +- .../keystone/conf/proxy-server.conf | 5 +- .../swiftkerbauth/conf/proxy-server.conf | 5 +- .../tempauth/conf/proxy-server.conf | 5 +- tools/gswauth_functional_tests.sh | 12 +-- tools/keystone_functional_tests.sh | 6 +- tools/swkrbath_functional_tests.sh | 6 +- tox.ini | 26 +++--- 11 files changed, 157 insertions(+), 42 deletions(-) create mode 100755 .functests rename unittests.sh => .unittests (51%) diff --git a/.functests b/.functests new file mode 100755 index 0000000..ecaac60 --- /dev/null +++ b/.functests @@ -0,0 +1,88 @@ +#!/bin/bash + +# Copyright (c) 2013 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This program expects to be run by tox in a virtual python environment +# so that it does not pollute the host development system + +sudo_env() +{ + sudo bash -c "PATH=$PATH $*" +} + +cleanup() +{ + sudo service memcached stop + sudo_env swift-init main stop + sudo rm -rf /etc/swift > /dev/null 2>&1 + sudo rm -rf /mnt/gluster-object/test{,2}/* > /dev/null 2>&1 + sudo setfattr -x user.swift.metadata /mnt/gluster-object/test{,2} > /dev/null 2>&1 +} + +quit() +{ + echo "$1" + exit 1 +} + + +fail() +{ + cleanup + quit "$1" +} + +### MAIN ### +# This script runs functional tests only with tempauth + +if [ $EUID -ne 0 ]; then + echo "Functional tests must be run as root" + exit 1 +fi + +# Only run if there is no configuration in the system +if [ -x /etc/swift ] ; then + quit "/etc/swift exists, cannot run functional tests." +fi + +# Check the directories exist +DIRS="/mnt/gluster-object /mnt/gluster-object/test /mnt/gluster-object/test2" +for d in $DIRS ; do + if [ ! -x $d ] ; then + quit "$d must exist on an XFS or GlusterFS volume" + fi +done + +export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf + +# Install the configuration files +sudo mkdir /etc/swift > /dev/null 2>&1 +sudo cp -r test/functional_auth/tempauth/conf/* /etc/swift || fail "Unable to copy configuration files to /etc/swift" +sudo_env gluster-swift-gen-builders test test2 || fail "Unable to create ring files" + +# Start the services +sudo service memcached start || fail "Unable to start memcached" +sudo_env swift-init main start || fail "Unable to start swift" + +mkdir functional_tests_result > /dev/null 2>&1 +nosetests -v --exe \ + --with-xunit \ + --xunit-file functional_tests_result/gluster-swift-generic-functional-TC-report.xml \ + --with-html-output \ + --html-out-file functional_tests_result/gluster-swift-generic-functional-result.html \ + test/functional || fail "Functional tests failed" +cleanup +exit 0 diff --git a/.gitignore b/.gitignore index cd4a111..938554e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,13 @@ -/.tox -gluster_swift.egg-info -/test/unit/.coverage -/test/unit/nosetests.xml -/test/unit/coverage.xml -/test/unit/cover -/build -/swift -*.pyc +*.py[co] +*.sw? +*~ +dist +build +cover +functional_tests_result +.coverage +*.egg +*.egg-info +.tox +pycscope.* +cscope.* diff --git a/unittests.sh b/.unittests similarity index 51% rename from unittests.sh rename to .unittests index 940ada7..fcd066a 100755 --- a/unittests.sh +++ b/.unittests @@ -15,10 +15,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +TOP_DIR=$(python -c "import os; print os.path.dirname(os.path.realpath('$0'))") -cd $(dirname $0)/test/unit -nosetests -v --exe --with-coverage --cover-package gluster --cover-erase --cover-html --cover-branches $@ - -saved_status=$? +python -c 'from distutils.version import LooseVersion as Ver; import nose, sys; sys.exit(0 if Ver(nose.__version__) >= Ver("1.2.0") else 1)' +if [ $? != 0 ]; then + cover_branches="" +else + # Having the HTML reports is REALLY useful for achieving 100% branch + # coverage. + cover_branches="--cover-branches --cover-html --cover-html-dir=$TOP_DIR/cover" +fi +cd $TOP_DIR/test/unit +nosetests -v --exe --with-coverage --cover-package gluster. --cover-erase $cover_branches $@ +rvalue=$? rm -f .coverage -exit $saved_status +cd - +exit $rvalue diff --git a/test/functional_auth/gswauth/conf/proxy-server.conf b/test/functional_auth/gswauth/conf/proxy-server.conf index 165cb0c..60661e8 100644 --- a/test/functional_auth/gswauth/conf/proxy-server.conf +++ b/test/functional_auth/gswauth/conf/proxy-server.conf @@ -5,7 +5,7 @@ user = root workers = 1 [pipeline:main] -pipeline = catch_errors healthcheck proxy-logging cache gswauth proxy-logging proxy-server +pipeline = catch_errors healthcheck proxy-logging cache tempurl gswauth proxy-logging proxy-server [app:proxy-server] use = egg:gluster_swift#proxy @@ -76,3 +76,6 @@ use = egg:swift#memcache # Update this line to contain a comma separated list of memcache servers # shared by all nodes running the proxy-server service. memcache_servers = localhost:11211 + +[filter:tempurl] +use = egg:swift#tempurl diff --git a/test/functional_auth/keystone/conf/proxy-server.conf b/test/functional_auth/keystone/conf/proxy-server.conf index 084e6a5..4838c46 100644 --- a/test/functional_auth/keystone/conf/proxy-server.conf +++ b/test/functional_auth/keystone/conf/proxy-server.conf @@ -6,7 +6,7 @@ workers = 1 [pipeline:main] #pipeline = catch_errors healthcheck proxy-logging cache tempauth proxy-logging proxy-server -pipeline = catch_errors healthcheck proxy-logging cache authtoken keystoneauth proxy-logging proxy-server +pipeline = catch_errors healthcheck proxy-logging cache tempurl authtoken keystoneauth proxy-logging proxy-server [app:proxy-server] use = egg:gluster_swift#proxy @@ -92,3 +92,6 @@ use = egg:swift#memcache # Update this line to contain a comma separated list of memcache servers # shared by all nodes running the proxy-server service. memcache_servers = localhost:11211 + +[filter:tempurl] +use = egg:swift#tempurl diff --git a/test/functional_auth/swiftkerbauth/conf/proxy-server.conf b/test/functional_auth/swiftkerbauth/conf/proxy-server.conf index e6f8aa1..855499c 100644 --- a/test/functional_auth/swiftkerbauth/conf/proxy-server.conf +++ b/test/functional_auth/swiftkerbauth/conf/proxy-server.conf @@ -5,7 +5,7 @@ user = root workers = 1 [pipeline:main] -pipeline = catch_errors healthcheck proxy-logging cache proxy-logging kerbauth proxy-server +pipeline = catch_errors healthcheck proxy-logging cache tempurl proxy-logging kerbauth proxy-server [app:proxy-server] use = egg:gluster_swift#proxy @@ -68,3 +68,6 @@ use = egg:swift#memcache # Update this line to contain a comma separated list of memcache servers # shared by all nodes running the proxy-server service. memcache_servers = localhost:11211 + +[filter:tempurl] +use = egg:swift#tempurl diff --git a/test/functional_auth/tempauth/conf/proxy-server.conf b/test/functional_auth/tempauth/conf/proxy-server.conf index 830fadf..bcb3da9 100644 --- a/test/functional_auth/tempauth/conf/proxy-server.conf +++ b/test/functional_auth/tempauth/conf/proxy-server.conf @@ -5,7 +5,7 @@ user = root workers = 1 [pipeline:main] -pipeline = catch_errors healthcheck proxy-logging cache tempauth proxy-logging proxy-server +pipeline = catch_errors healthcheck proxy-logging cache tempurl tempauth proxy-logging proxy-server [app:proxy-server] use = egg:gluster_swift#proxy @@ -70,3 +70,6 @@ use = egg:swift#memcache # Update this line to contain a comma separated list of memcache servers # shared by all nodes running the proxy-server service. memcache_servers = localhost:11211 + +[filter:tempurl] +use = egg:swift#tempurl diff --git a/tools/gswauth_functional_tests.sh b/tools/gswauth_functional_tests.sh index dbe2248..0e4bc90 100755 --- a/tools/gswauth_functional_tests.sh +++ b/tools/gswauth_functional_tests.sh @@ -50,7 +50,7 @@ quit() fail() { cleanup - quit "$1" + quit "$1" } run_generic_tests() @@ -66,9 +66,9 @@ run_generic_tests() nosetests -v --exe \ --with-xunit \ - --xunit-file functional_tests/gluster-swift-gswauth-generic-functional-TC-report.xml \ + --xunit-file functional_tests_result/gluster-swift-gswauth-generic-functional-TC-report.xml \ --with-html-output \ - --html-out-file functional_tests/gluster-swift-gswauth-generic-functional-result.html \ + --html-out-file functional_tests_result/gluster-swift-gswauth-generic-functional-result.html \ test/functional || fail "Functional tests failed" } @@ -101,12 +101,12 @@ sudo_env swift-init main start || fail "Unable to start swift" #swauth-prep sudo_env gswauth-prep -K gswauthkey || fail "Unable to prep gswauth" -mkdir functional_tests > /dev/null 2>&1 +mkdir functional_tests_result > /dev/null 2>&1 nosetests -v --exe \ --with-xunit \ - --xunit-file functional_tests/gluster-swift-gswauth-functional-TC-report.xml \ + --xunit-file functional_tests_result/gluster-swift-gswauth-functional-TC-report.xml \ --with-html-output \ - --html-out-file functional_tests/gluster-swift-gswauth-functional-result.html \ + --html-out-file functional_tests_result/gluster-swift-gswauth-functional-result.html \ test/functional_auth/gswauth || fail "Functional gswauth test failed" run_generic_tests diff --git a/tools/keystone_functional_tests.sh b/tools/keystone_functional_tests.sh index 620bcc7..b5aa25a 100755 --- a/tools/keystone_functional_tests.sh +++ b/tools/keystone_functional_tests.sh @@ -87,15 +87,15 @@ sudo_env gluster-swift-gen-builders $accounts || fail "Unable to create ring fil sudo service memcached start || fail "Unable to start memcached" sudo_env swift-init main start || fail "Unable to start swift" -mkdir functional_tests > /dev/null 2>&1 +mkdir functional_tests_result > /dev/null 2>&1 echo "== Keystone: Generic Functional Tests ==" nosetests -v --exe \ --with-xunit \ - --xunit-file functional_tests/gluster-swift-keystone-generic-functional-TC-report.xml \ + --xunit-file functional_tests_result/gluster-swift-keystone-generic-functional-TC-report.xml \ --with-html-output \ - --html-out-file functional_tests/gluster-swift-keystone-generic-functional-result.html \ + --html-out-file functional_tests_result/gluster-swift-keystone-generic-functional-result.html \ test/functional || fail "Functional tests failed" cleanup diff --git a/tools/swkrbath_functional_tests.sh b/tools/swkrbath_functional_tests.sh index 9995f1d..0768de6 100755 --- a/tools/swkrbath_functional_tests.sh +++ b/tools/swkrbath_functional_tests.sh @@ -80,16 +80,16 @@ sudo_env gluster-swift-gen-builders $accounts || fail "Unable to create ring fil sudo service memcached start || fail "Unable to start memcached" sudo_env swift-init main start || fail "Unable to start swift" -mkdir functional_tests > /dev/null 2>&1 +mkdir functional_tests_result > /dev/null 2>&1 echo "== SwiftKerbAuth: Functional Tests ==" nosetests -v --exe \ --with-xunit \ - --xunit-file functional_tests/gluster-swift-swiftkerbauth-generic-functional-TC-report.xml \ + --xunit-file functional_tests_result/gluster-swift-swiftkerbauth-generic-functional-TC-report.xml \ --with-html-output \ - --html-out-file functional_tests/gluster-swift-swiftkerbauth-generic-functional-result.html \ + --html-out-file functional_tests_result/gluster-swift-swiftkerbauth-generic-functional-result.html \ test/functional_auth/swiftkerbauth || fail "Functional tests failed" cleanup diff --git a/tox.ini b/tox.ini index 44e4011..299fd6f 100644 --- a/tox.ini +++ b/tox.ini @@ -14,20 +14,29 @@ setenv = VIRTUAL_ENV={envdir} NOSE_OPENSTACK_YELLOW=0.025 NOSE_OPENSTACK_SHOW_ELAPSED=1 NOSE_OPENSTACK_STDOUT=1 + NOSE_WITH_COVERAGE=1 + NOSE_COVER_BRANCHES=1 + NOSE_COVER_PACKAGE=gluster deps = https://launchpad.net/swift/icehouse/1.13.1/+download/swift-1.13.1.tar.gz - --download-cache={homedir}/.pipcache -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt changedir = {toxinidir}/test/unit -commands = nosetests -v --exe --with-xunit --with-coverage --cover-package gluster --cover-erase --cover-xml --cover-html --cover-branches --with-html-output {posargs} +commands = nosetests -v {posargs} + +[testenv:cover] +setenv = VIRTUAL_ENV={envdir} + NOSE_WITH_COVERAGE=1 + NOSE_COVER_BRANCHES=1 + NOSE_COVER_HTML=1 + NOSE_COVER_HTML_DIR={toxinidir}/cover [tox:jenkins] downloadcache = ~/cache/pip [testenv:functest] changedir = {toxinidir} -commands = bash tools/functional_tests.sh +commands = bash ./.functests bash tools/gswauth_functional_tests.sh [testenv:ksfunctest] @@ -39,20 +48,13 @@ changedir = {toxinidir} commands = bash tools/swkrbath_functional_tests.sh [testenv:pep8] -deps = - --download-cache={homedir}/.pipcache - -r{toxinidir}/test-requirements.txt changedir = {toxinidir} commands = - flake8 - flake8 gluster test - -[testenv:cover] -setenv = NOSE_WITH_COVERAGE=1 + flake8 gluster test setup.py [testenv:venv] -commands = changedir = {toxinidir} +commands = {posargs} [testenv:run] changedir = {toxinidir}