5
# ---------------UPDATE ME-------------------------------#
6
# Increment me any time the environment should be rebuilt.
7
# This includes dependncy changes, directory renames, etc.
8
# Simple integer secuence: 1, 2, 3...
10
#--------------------------------------------------------#
13
echo "Usage: $0 [OPTION]..."
14
echo "Run Horizon's test suite(s)"
16
echo " -V, --virtual-env Always use virtualenv. Install automatically"
17
echo " if not present"
18
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local"
20
echo " -c, --coverage Generate reports using Coverage"
21
echo " -f, --force Force a clean re-build of the virtual"
22
echo " environment. Useful when dependencies have"
24
echo " -m, --manage Run a Django management command."
25
echo " --makemessages Update all translation files."
26
echo " -p, --pep8 Just run pep8"
27
echo " -t, --tabs Check for tab characters in files."
28
echo " -y, --pylint Just run pylint"
29
echo " -q, --quiet Run non-interactively. (Relatively) quiet."
30
echo " Implies -V if -N is not set."
31
echo " --only-selenium Run only the Selenium unit tests"
32
echo " --with-selenium Run unit tests including Selenium tests"
33
echo " --runserver Run the Django development server for"
34
echo " openstack_dashboard in the virtual"
36
echo " --docs Just build the documentation"
37
echo " --backup-environment Make a backup of the environment on exit"
38
echo " --restore-environment Restore the environment before running"
39
echo " --destroy-environment DEstroy the environment and exit"
40
echo " -h, --help Print this usage message"
42
echo "Note: with no options specified, the script will try to run the tests in"
43
echo " a virtual environment, If no virtualenv is found, the script will ask"
44
echo " if you would like to create one. If you prefer to run tests NOT in a"
45
echo " virtual environment, simply pass the -N option."
49
# DEFAULTS FOR RUN_TESTS.SH
53
with_venv=tools/with_venv.sh
54
included_dirs="openstack_dashboard horizon"
76
# Jenkins sets a "JOB_NAME" variable, if it's not set, we'll make it "default"
77
[ "$JOB_NAME" ] || JOB_NAME="default"
79
function process_option {
82
-V|--virtual-env) always_venv=1; never_venv=0;;
83
-N|--no-virtual-env) always_venv=0; never_venv=1;;
84
-p|--pep8) just_pep8=1;;
85
-y|--pylint) just_pylint=1;;
87
-t|--tabs) just_tabs=1;;
89
-c|--coverage) with_coverage=1;;
90
-m|--manage) manage=1;;
91
--makemessages) makemessages=1;;
92
--only-selenium) only_selenium=1;;
93
--with-selenium) with_selenium=1;;
95
--runserver) runserver=1;;
96
--backup-environment) backup_env=1;;
97
--restore-environment) restore_env=1;;
98
--destroy-environment) destroy=1;;
99
*) testargs="$testargs $1"
103
function run_management_command {
104
${command_wrapper} python $root/manage.py $testargs
107
function run_server {
108
echo "Starting Django development server..."
109
${command_wrapper} python $root/manage.py runserver $testargs
110
echo "Server stopped."
113
function run_pylint {
114
echo "Running pylint ..."
115
PYTHONPATH=$root ${command_wrapper} pylint --rcfile=.pylintrc -f parseable $included_dirs > pylint.txt || true
117
grep Global -A2 pylint.txt
118
if [ $CODE -lt 32 ]; then
119
echo "Completed successfully."
122
echo "Completed with problems."
128
echo "Running pep8 ..."
129
${command_wrapper} pep8 $included_dirs || true
132
function run_sphinx {
133
echo "Building sphinx..."
134
export DJANGO_SETTINGS_MODULE=openstack_dashboard.settings
135
${command_wrapper} sphinx-build -b html doc/source doc/build/html
136
echo "Build complete."
140
TAB_VIOLATIONS=`find $included_dirs -type f -regex ".*\.\(css\|js\|py\|html\)" -print0 | xargs -0 awk '/\t/' | wc -l`
141
if [ $TAB_VIOLATIONS -gt 0 ]; then
142
echo "TABS! $TAB_VIOLATIONS of them! Oh no!"
143
HORIZON_FILES=`find $included_dirs -type f -regex ".*\.\(css\|js\|py|\html\)"`
144
for TABBED_FILE in $HORIZON_FILES
146
TAB_COUNT=`awk '/\t/' $TABBED_FILE | wc -l`
147
if [ $TAB_COUNT -gt 0 ]; then
148
echo "$TABBED_FILE: $TAB_COUNT"
152
return $TAB_VIOLATIONS;
155
function destroy_venv {
156
echo "Cleaning environment..."
157
echo "Removing virtualenv..."
159
echo "Virtualenv removed."
160
rm -f .environment_version
161
echo "Environment cleaned."
164
function environment_check {
165
echo "Checking environment."
166
if [ -f .environment_version ]; then
167
ENV_VERS=`cat .environment_version`
168
if [ $ENV_VERS -eq $environment_version ]; then
169
if [ -e ${venv} ]; then
170
# If the environment exists and is up-to-date then set our variables
171
command_wrapper="${root}/${with_venv}"
172
echo "Environment is up to date."
178
if [ $always_venv -eq 1 ]; then
181
if [ ! -e ${venv} ]; then
182
echo -e "Environment not found. Install? (Y/n) \c"
184
echo -e "Your environment appears to be out of date. Update? (Y/n) \c"
187
if [ "x$update_env" = "xY" -o "x$update_env" = "x" -o "x$update_env" = "xy" ]; then
190
# Set our command wrapper anyway.
191
command_wrapper="${root}/${with_venv}"
196
function sanity_check {
197
# Anything that should be determined prior to running the tests, server, etc.
198
# Don't sanity-check anything environment-related in -N flag is set
199
if [ $never_venv -eq 0 ]; then
200
if [ ! -e ${venv} ]; then
201
echo "Virtualenv not found at $venv. Did install_venv.py succeed?"
205
# Remove .pyc files. This is sanity checking because they can linger
206
# after old files are deleted.
207
find . -name "*.pyc" -exec rm -rf {} \;
210
function backup_environment {
211
if [ $backup_env -eq 1 ]; then
212
echo "Backing up environment \"$JOB_NAME\"..."
213
if [ ! -e ${venv} ]; then
214
echo "Environment not installed. Cannot back up."
217
if [ -d /tmp/.horizon_environment/$JOB_NAME ]; then
218
mv /tmp/.horizon_environment/$JOB_NAME /tmp/.horizon_environment/$JOB_NAME.old
219
rm -rf /tmp/.horizon_environment/$JOB_NAME
221
mkdir -p /tmp/.horizon_environment/$JOB_NAME
222
cp -r $venv /tmp/.horizon_environment/$JOB_NAME/
223
cp .environment_version /tmp/.horizon_environment/$JOB_NAME/
224
# Remove the backup now that we've completed successfully
225
rm -rf /tmp/.horizon_environment/$JOB_NAME.old
226
echo "Backup completed"
230
function restore_environment {
231
if [ $restore_env -eq 1 ]; then
232
echo "Restoring environment from backup..."
233
if [ ! -d /tmp/.horizon_environment/$JOB_NAME ]; then
234
echo "No backup to restore from."
238
cp -r /tmp/.horizon_environment/$JOB_NAME/.venv ./ || true
239
cp -r /tmp/.horizon_environment/$JOB_NAME/.environment_version ./ || true
241
echo "Environment restored successfully."
245
function install_venv {
246
# Install with install_venv.py
247
export PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE-/tmp/.pip_download_cache}
248
export PIP_USE_MIRRORS=true
249
if [ $quiet -eq 1 ]; then
250
export PIP_NO_INPUT=true
252
echo "Fetching new src packages..."
254
python tools/install_venv.py
255
command_wrapper="$root/${with_venv}"
256
# Make sure it worked and record the environment version
259
echo $environment_version > .environment_version
265
if [ $with_selenium -eq 1 ]; then
266
export WITH_SELENIUM=1
267
elif [ $only_selenium -eq 1 ]; then
268
export WITH_SELENIUM=1
269
export SKIP_UNITTESTS=1
272
echo "Running Horizon application tests"
273
export NOSE_XUNIT_FILE=horizon/nosetests.xml
274
${command_wrapper} python-coverage erase
275
${command_wrapper} python-coverage run -p $root/manage.py test horizon --settings=horizon.tests.testsettings $testargs
276
# get results of the Horizon tests
279
echo "Running openstack_dashboard tests"
280
export NOSE_XUNIT_FILE=openstack_dashboard/nosetests.xml
281
${command_wrapper} python-coverage run -p $root/manage.py test openstack_dashboard --settings=openstack_dashboard.test.settings $testargs
282
# get results of the openstack_dashboard tests
285
if [ $with_coverage -eq 1 ]; then
286
echo "Generating coverage reports"
287
${command_wrapper} python-coverage combine
288
${command_wrapper} python-coverage xml -i --omit='/usr*,setup.py,*egg*,.venv/*'
289
${command_wrapper} python-coverage html -i --omit='/usr*,setup.py,*egg*,.venv/*' -d reports
291
# Remove the leftover coverage files from the -p flag earlier.
294
if [ $(($HORIZON_RESULT || $DASHBOARD_RESULT)) -eq 0 ]; then
295
echo "Tests completed successfully."
299
exit $(($HORIZON_RESULT || $DASHBOARD_RESULT))
302
function run_makemessages {
304
${command_wrapper} $root/manage.py makemessages --all --no-obsolete
306
${command_wrapper} $root/manage.py makemessages -d djangojs --all --no-obsolete
308
cd ../openstack_dashboard
309
${command_wrapper} $root/manage.py makemessages --all --no-obsolete
312
exit $(($HORIZON_PY_RESULT || $HORIZON_JS_RESULT || $DASHBOARD_RESULT))
316
# ---------PREPARE THE ENVIRONMENT------------ #
318
# PROCESS ARGUMENTS, OVERRIDE DEFAULTS
323
if [ $quiet -eq 1 ] && [ $never_venv -eq 0 ] && [ $always_venv -eq 0 ]
328
# If destroy is set, just blow it away and exit.
329
if [ $destroy -eq 1 ]; then
334
# Ignore all of this if the -N flag was set
335
if [ $never_venv -eq 0 ]; then
337
# Restore previous environment if desired
338
if [ $restore_env -eq 1 ]; then
342
# Remove the virtual environment if --force used
343
if [ $force -eq 1 ]; then
347
# Then check if it's up-to-date
350
# Create a backup of the up-to-date environment if desired
351
if [ $backup_env -eq 1 ]; then
356
# ---------EXERCISE THE CODE------------ #
358
# Run management commands
359
if [ $manage -eq 1 ]; then
360
run_management_command
365
if [ $just_docs -eq 1 ]; then
370
# Update translation files
371
if [ $makemessages -eq 1 ]; then
377
if [ $just_pep8 -eq 1 ]; then
383
if [ $just_pylint -eq 1 ]; then
389
if [ $just_tabs -eq 1 ]; then
394
# Django development server
395
if [ $runserver -eq 1 ]; then