6
echo "Usage: $0 [OPTION]..."
7
echo "Run Nova's test suite(s)"
9
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
10
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
11
echo " -s, --no-site-packages Isolate the virtualenv from the global Python environment"
12
echo " -r, --recreate-db Recreate the test database (deprecated, as this is now the default)."
13
echo " -n, --no-recreate-db Don't recreate the test database."
14
echo " -x, --stop Stop running tests after the first error or failure."
15
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
16
echo " -p, --pep8 Just run PEP8 and HACKING compliance check"
17
echo " -P, --no-pep8 Don't run static code checks"
18
echo " -c, --coverage Generate coverage report"
19
echo " -h, --help Print this usage message"
20
echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list"
22
echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
23
echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
24
echo " prefer to run tests NOT in a virtual environment, simply pass the -N option."
28
function process_option {
31
-V|--virtual-env) always_venv=1; never_venv=0;;
32
-N|--no-virtual-env) always_venv=0; never_venv=1;;
33
-s|--no-site-packages) no_site_packages=1;;
34
-r|--recreate-db) recreate_db=1;;
35
-n|--no-recreate-db) recreate_db=0;;
36
-m|--patch-migrate) patch_migrate=1;;
37
-w|--no-patch-migrate) patch_migrate=0;;
39
-p|--pep8) just_pep8=1;;
40
-P|--no-pep8) no_pep8=1;;
41
-c|--coverage) coverage=1;;
42
-*) noseopts="$noseopts $1";;
43
*) noseargs="$noseargs $1"
48
with_venv=tools/with_venv.sh
63
export NOSE_WITH_OPENSTACK=1
64
export NOSE_OPENSTACK_COLOR=1
65
export NOSE_OPENSTACK_RED=0.05
66
export NOSE_OPENSTACK_YELLOW=0.025
67
export NOSE_OPENSTACK_SHOW_ELAPSED=1
68
export NOSE_OPENSTACK_STDOUT=1
70
export LANG=en_US.UTF-8
71
export LANGUAGE=en_US:en
78
# If enabled, tell nose to collect coverage data
79
if [ $coverage -eq 1 ]; then
80
noseopts="$noseopts --with-coverage --cover-package=nova"
83
if [ $no_site_packages -eq 1 ]; then
84
installvenvopts="--no-site-packages"
89
${wrapper} find . -type f -name "*.pyc" -delete
90
# Just run the test suites in current environment
91
${wrapper} $NOSETESTS | tee nosetests.log
92
# If we get some short import error right away, print the error log directly
94
if [ "$RESULT" -ne "0" ];
96
ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
97
if [ "$ERRSIZE" -lt "40" ];
102
tests_run=$(awk '/^Ran/ {print $2}' nosetests.log)
103
if [ -z "$tests_run" ] || [ "$tests_run" -eq 0 ];
105
echo "ERROR: Zero tests ran, something is wrong!"
106
echo "This is usually caused by a parse error in some python"
107
echo "file or a failure to set up the environment (i.e. during"
108
echo "temporary database preparation). Running nosetests directly"
109
echo "may offer more clues."
118
echo "Running PEP8 and HACKING compliance check..."
121
# NOTE(lzyeval): Avoid selecting nova-api-paste.ini and nova.conf in nova/bin
122
# when running on devstack.
123
# NOTE(lzyeval): Avoid selecting *.pyc files to reduce pep8 check-up time
124
# when running on devstack.
125
srcfiles=`find nova -type f -name "*.py" ! -wholename "nova\/openstack*"`
126
srcfiles+=" `find bin -type f ! -name "nova.conf*" ! -name "*api-paste.ini*"`"
127
srcfiles+=" `find tools -type f -name "*.py"`"
128
srcfiles+=" setup.py"
130
# Until all these issues get fixed, ignore.
131
ignore='--ignore=N4,E12,E711,E721,E712'
133
${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
135
# NOTE(sirp): Dom0 plugins are written for Python 2.4, meaning some HACKING
136
# checks are too strict.
137
pep8onlyfiles=`find plugins -type f -name "*.py"`
138
pep8onlyfiles+=" `find plugins/xenserver/xenapi/etc/xapi.d/plugins/ -type f -perm +111`"
139
${wrapper} pep8 ${ignore} ${pep8onlyfiles}
143
NOSETESTS="nosetests $noseopts $noseargs"
145
if [ $never_venv -eq 0 ]
147
# Remove the virtual environment if --force used
148
if [ $force -eq 1 ]; then
149
echo "Cleaning virtualenv..."
152
if [ -e ${venv} ]; then
153
wrapper="${with_venv}"
155
if [ $always_venv -eq 1 ]; then
156
# Automatically install the virtualenv
157
python tools/install_venv.py $installvenvopts
158
wrapper="${with_venv}"
160
echo -e "No virtual environment found...create one? (Y/n) \c"
162
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
163
# Install the virtualenv and run the test suite in it
164
python tools/install_venv.py $installvenvopts
171
# Delete old coverage data from previous runs
172
if [ $coverage -eq 1 ]; then
173
${wrapper} coverage erase
176
if [ $just_pep8 -eq 1 ]; then
181
if [ $recreate_db -eq 1 ]; then
187
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
188
# not when we're running tests individually. To handle this, we need to
189
# distinguish between options (noseopts), which begin with a '-', and
190
# arguments (noseargs).
191
if [ -z "$noseargs" ]; then
192
if [ $no_pep8 -eq 0 ]; then
197
if [ $coverage -eq 1 ]; then
198
echo "Generating coverage report in covhtml/"
199
# Don't compute coverage for common code, which is tested elsewhere
200
${wrapper} coverage html --include='nova/*' --omit='nova/openstack/common/*' -d covhtml -i