2010-08-11 17:40:28 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2011-08-28 16:19:55 +05:30
|
|
|
set -eu
|
|
|
|
|
2010-08-11 17:40:28 -04:00
|
|
|
function usage {
|
|
|
|
echo "Usage: $0 [OPTION]..."
|
|
|
|
echo "Run Nova's test suite(s)"
|
|
|
|
echo ""
|
|
|
|
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
|
|
|
|
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
|
2011-10-30 09:00:59 -04:00
|
|
|
echo " -s, --no-site-packages Isolate the virtualenv from the global Python environment"
|
2011-06-29 07:47:51 -07:00
|
|
|
echo " -r, --recreate-db Recreate the test database (deprecated, as this is now the default)."
|
|
|
|
echo " -n, --no-recreate-db Don't recreate the test database."
|
2011-04-26 13:22:24 -04:00
|
|
|
echo " -x, --stop Stop running tests after the first error or failure."
|
2010-09-28 14:48:03 -04:00
|
|
|
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
|
2011-04-13 12:46:51 -04:00
|
|
|
echo " -p, --pep8 Just run pep8"
|
2011-09-22 18:22:42 -04:00
|
|
|
echo " -P, --no-pep8 Don't run pep8"
|
2011-07-19 10:52:38 -04:00
|
|
|
echo " -c, --coverage Generate coverage report"
|
2010-08-11 17:40:28 -04:00
|
|
|
echo " -h, --help Print this usage message"
|
2011-06-15 01:21:11 +00:00
|
|
|
echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list"
|
2010-08-11 17:40:28 -04:00
|
|
|
echo ""
|
|
|
|
echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
|
|
|
|
echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
|
|
|
|
echo " prefer to run tests NOT in a virtual environment, simply pass the -N option."
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_option {
|
2010-09-28 14:48:03 -04:00
|
|
|
case "$1" in
|
2010-08-13 10:14:34 -04:00
|
|
|
-h|--help) usage;;
|
2011-08-28 16:19:55 +05:30
|
|
|
-V|--virtual-env) always_venv=1; never_venv=0;;
|
|
|
|
-N|--no-virtual-env) always_venv=0; never_venv=1;;
|
2011-10-30 09:00:59 -04:00
|
|
|
-s|--no-site-packages) no_site_packages=1;;
|
2011-08-28 16:19:55 +05:30
|
|
|
-r|--recreate-db) recreate_db=1;;
|
|
|
|
-n|--no-recreate-db) recreate_db=0;;
|
|
|
|
-f|--force) force=1;;
|
|
|
|
-p|--pep8) just_pep8=1;;
|
2011-09-22 18:22:42 -04:00
|
|
|
-P|--no-pep8) no_pep8=1;;
|
2011-08-28 16:19:55 +05:30
|
|
|
-c|--coverage) coverage=1;;
|
2011-06-15 01:16:53 +00:00
|
|
|
-*) noseopts="$noseopts $1";;
|
2010-12-28 01:09:42 +00:00
|
|
|
*) noseargs="$noseargs $1"
|
2010-08-11 17:40:28 -04:00
|
|
|
esac
|
|
|
|
}
|
2010-07-27 21:35:55 -07:00
|
|
|
|
|
|
|
venv=.nova-venv
|
|
|
|
with_venv=tools/with_venv.sh
|
2010-08-11 17:40:28 -04:00
|
|
|
always_venv=0
|
|
|
|
never_venv=0
|
2010-09-28 14:48:03 -04:00
|
|
|
force=0
|
2011-10-30 09:00:59 -04:00
|
|
|
no_site_packages=0
|
|
|
|
installvenvopts=
|
2010-12-28 01:09:42 +00:00
|
|
|
noseargs=
|
2011-06-15 01:16:53 +00:00
|
|
|
noseopts=
|
2011-01-19 10:50:54 +01:00
|
|
|
wrapper=""
|
2011-04-06 18:17:43 -04:00
|
|
|
just_pep8=0
|
2011-09-22 18:22:42 -04:00
|
|
|
no_pep8=0
|
2011-07-19 10:52:38 -04:00
|
|
|
coverage=0
|
2011-06-29 07:47:51 -07:00
|
|
|
recreate_db=1
|
2010-12-28 01:40:24 -08:00
|
|
|
|
2010-09-28 14:48:03 -04:00
|
|
|
for arg in "$@"; do
|
|
|
|
process_option $arg
|
|
|
|
done
|
2010-08-11 17:40:28 -04:00
|
|
|
|
2011-07-21 10:30:55 -04:00
|
|
|
# If enabled, tell nose to collect coverage data
|
2011-07-19 10:52:38 -04:00
|
|
|
if [ $coverage -eq 1 ]; then
|
|
|
|
noseopts="$noseopts --with-coverage --cover-package=nova"
|
|
|
|
fi
|
|
|
|
|
2011-10-30 09:00:59 -04:00
|
|
|
if [ $no_site_packages -eq 1 ]; then
|
|
|
|
installvenvopts="--no-site-packages"
|
|
|
|
fi
|
|
|
|
|
2011-01-19 10:50:54 +01:00
|
|
|
function run_tests {
|
2010-08-11 17:40:28 -04:00
|
|
|
# Just run the test suites in current environment
|
2011-02-23 15:29:02 -08:00
|
|
|
${wrapper} $NOSETESTS 2> run_tests.log
|
2011-02-23 08:46:11 -08:00
|
|
|
# If we get some short import error right away, print the error log directly
|
|
|
|
RESULT=$?
|
|
|
|
if [ "$RESULT" -ne "0" ];
|
|
|
|
then
|
2011-02-23 15:29:02 -08:00
|
|
|
ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
|
2011-02-23 08:46:11 -08:00
|
|
|
if [ "$ERRSIZE" -lt "40" ];
|
|
|
|
then
|
2011-08-12 14:33:27 -07:00
|
|
|
cat run_tests.log
|
2011-02-23 08:46:11 -08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return $RESULT
|
2011-01-19 10:50:54 +01:00
|
|
|
}
|
2010-07-27 21:35:55 -07:00
|
|
|
|
2011-04-06 18:17:43 -04:00
|
|
|
function run_pep8 {
|
|
|
|
echo "Running pep8 ..."
|
2011-05-16 20:08:51 -05:00
|
|
|
# Opt-out files from pep8
|
|
|
|
ignore_scripts="*.sh:*nova-debug:*clean-vlans"
|
|
|
|
ignore_files="*eventlet-patch:*pip-requires"
|
|
|
|
ignore_dirs="*ajaxterm*"
|
|
|
|
GLOBIGNORE="$ignore_scripts:$ignore_files:$ignore_dirs"
|
2011-04-06 18:17:43 -04:00
|
|
|
srcfiles=`find bin -type f ! -name "nova.conf*"`
|
2011-05-16 20:08:51 -05:00
|
|
|
srcfiles+=" `find tools/*`"
|
2011-04-06 18:17:43 -04:00
|
|
|
srcfiles+=" nova setup.py plugins/xenserver/xenapi/etc/xapi.d/plugins/glance"
|
2011-06-07 16:08:25 -04:00
|
|
|
# Just run PEP8 in current environment
|
2011-09-27 21:05:31 +00:00
|
|
|
#
|
|
|
|
# NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the
|
|
|
|
# following reasons:
|
|
|
|
#
|
|
|
|
# 1. It's needed to preserve traceback information when re-raising
|
|
|
|
# exceptions; this is needed b/c Eventlet will clear exceptions when
|
|
|
|
# switching contexts.
|
|
|
|
#
|
|
|
|
# 2. There doesn't appear to be an alternative, "pep8-tool" compatible way of doing this
|
|
|
|
# in Python 2 (in Python 3 `with_traceback` could be used).
|
|
|
|
#
|
|
|
|
# 3. Can find no corroborating evidence that this is deprecated in Python 2
|
|
|
|
# other than what the PEP8 tool claims. It is deprecated in Python 3, so,
|
|
|
|
# perhaps the mistake was thinking that the deprecation applied to Python 2
|
|
|
|
# as well.
|
2011-06-07 16:08:25 -04:00
|
|
|
${wrapper} pep8 --repeat --show-pep8 --show-source \
|
2011-09-27 21:05:31 +00:00
|
|
|
--ignore=E202,W602 \
|
2011-09-22 18:22:42 -04:00
|
|
|
--exclude=vcsversion.py ${srcfiles}
|
2011-04-06 18:17:43 -04:00
|
|
|
}
|
|
|
|
|
2011-06-15 01:16:53 +00:00
|
|
|
NOSETESTS="python run_tests.py $noseopts $noseargs"
|
2010-09-28 14:48:03 -04:00
|
|
|
|
2011-01-19 10:50:54 +01:00
|
|
|
if [ $never_venv -eq 0 ]
|
|
|
|
then
|
|
|
|
# Remove the virtual environment if --force used
|
|
|
|
if [ $force -eq 1 ]; then
|
|
|
|
echo "Cleaning virtualenv..."
|
|
|
|
rm -rf ${venv}
|
|
|
|
fi
|
|
|
|
if [ -e ${venv} ]; then
|
|
|
|
wrapper="${with_venv}"
|
2010-08-11 17:40:28 -04:00
|
|
|
else
|
2011-01-19 10:50:54 +01:00
|
|
|
if [ $always_venv -eq 1 ]; then
|
|
|
|
# Automatically install the virtualenv
|
2011-10-30 09:00:59 -04:00
|
|
|
python tools/install_venv.py $installvenvopts
|
2011-01-19 10:50:54 +01:00
|
|
|
wrapper="${with_venv}"
|
2010-08-11 17:40:28 -04:00
|
|
|
else
|
2011-01-19 10:50:54 +01:00
|
|
|
echo -e "No virtual environment found...create one? (Y/n) \c"
|
|
|
|
read use_ve
|
|
|
|
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
|
|
|
|
# Install the virtualenv and run the test suite in it
|
2011-10-30 09:00:59 -04:00
|
|
|
python tools/install_venv.py $installvenvopts
|
2011-01-30 21:55:32 -08:00
|
|
|
wrapper=${with_venv}
|
2011-01-19 10:50:54 +01:00
|
|
|
fi
|
2010-08-11 17:40:28 -04:00
|
|
|
fi
|
|
|
|
fi
|
2010-07-27 21:35:55 -07:00
|
|
|
fi
|
2011-01-19 10:50:54 +01:00
|
|
|
|
2011-07-21 10:30:55 -04:00
|
|
|
# Delete old coverage data from previous runs
|
|
|
|
if [ $coverage -eq 1 ]; then
|
|
|
|
${wrapper} coverage erase
|
|
|
|
fi
|
|
|
|
|
2011-06-07 16:08:25 -04:00
|
|
|
if [ $just_pep8 -eq 1 ]; then
|
|
|
|
run_pep8
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2011-06-25 17:26:38 -07:00
|
|
|
if [ $recreate_db -eq 1 ]; then
|
2011-07-04 17:31:24 +02:00
|
|
|
rm -f tests.sqlite
|
2011-06-25 17:26:38 -07:00
|
|
|
fi
|
|
|
|
|
2011-08-28 16:19:55 +05:30
|
|
|
run_tests
|
2011-04-06 18:17:43 -04:00
|
|
|
|
2011-06-15 01:16:53 +00:00
|
|
|
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
|
|
|
|
# not when we're running tests individually. To handle this, we need to
|
|
|
|
# distinguish between options (noseopts), which begin with a '-', and
|
|
|
|
# arguments (noseargs).
|
2011-04-06 18:17:43 -04:00
|
|
|
if [ -z "$noseargs" ]; then
|
2011-09-22 18:22:42 -04:00
|
|
|
if [ $no_pep8 -eq 0 ]; then
|
|
|
|
run_pep8
|
|
|
|
fi
|
2011-01-30 21:55:32 -08:00
|
|
|
fi
|
2011-07-19 10:52:38 -04:00
|
|
|
|
|
|
|
if [ $coverage -eq 1 ]; then
|
2011-07-21 10:47:34 -04:00
|
|
|
echo "Generating coverage report in covhtml/"
|
|
|
|
${wrapper} coverage html -d covhtml -i
|
2011-07-19 10:52:38 -04:00
|
|
|
fi
|