~ubuntu-branches/ubuntu/quantal/horizon/quantal

« back to all changes in this revision

Viewing changes to .pc/fix-ubuntu-tests.patch/run_tests.sh

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2012-08-16 14:01:33 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20120816140133-8b0f0fobvtg7wm0j
Tags: 2012.2~f3-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/fix-ubuntu-tests.patch: Fix test suites again to
  run during the builds.
* debian/watch: Update.
* debian/control: Add python-glanceclient. (LP: #1030911)
* debian/openstack-dashboard.conf: Don't hijack apache's webroot. (LP:
  #1020313)
* debian/control: Update horizon deps to reflect reality.

[ Adam Gandelman ]
* debian/control: Bump required python-django version to 1.4.
* wrap-and-sort.
* Fix (LP: #1036571):
    - debian/rules, openstack-dashboard.{links, dirs, postinst}: Add required
      symlinks and directories to allow Horizon to function with the packaged
      lessc.
    - debian/control: Add python-{cinder, swift, quantum}client,
      python-django-openstack-auth, python-netaddr, python-compressor, lessc.
* debian/rules: Improve dh_auto_clean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
set -o errexit
 
4
 
 
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...
 
9
environment_version=27
 
10
#--------------------------------------------------------#
 
11
 
 
12
function usage {
 
13
  echo "Usage: $0 [OPTION]..."
 
14
  echo "Run Horizon's test suite(s)"
 
15
  echo ""
 
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"
 
19
  echo "                           environment"
 
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"
 
23
  echo "                           been added."
 
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"
 
35
  echo "                           environment."
 
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"
 
41
  echo ""
 
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."
 
46
  exit
 
47
}
 
48
 
 
49
# DEFAULTS FOR RUN_TESTS.SH
 
50
#
 
51
root=`pwd`
 
52
venv=$root/.venv
 
53
with_venv=tools/with_venv.sh
 
54
included_dirs="openstack_dashboard horizon"
 
55
 
 
56
always_venv=0
 
57
backup_env=0
 
58
command_wrapper=""
 
59
destroy=0
 
60
force=0
 
61
just_pep8=0
 
62
just_pylint=0
 
63
just_docs=0
 
64
just_tabs=0
 
65
never_venv=0
 
66
quiet=0
 
67
restore_env=0
 
68
runserver=0
 
69
only_selenium=0
 
70
with_selenium=0
 
71
testargs=""
 
72
with_coverage=0
 
73
makemessages=0
 
74
manage=0
 
75
 
 
76
# Jenkins sets a "JOB_NAME" variable, if it's not set, we'll make it "default"
 
77
[ "$JOB_NAME" ] || JOB_NAME="default"
 
78
 
 
79
function process_option {
 
80
  case "$1" in
 
81
    -h|--help) usage;;
 
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;;
 
86
    -f|--force) force=1;;
 
87
    -t|--tabs) just_tabs=1;;
 
88
    -q|--quiet) quiet=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;;
 
94
    --docs) just_docs=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"
 
100
  esac
 
101
}
 
102
 
 
103
function run_management_command {
 
104
  ${command_wrapper} python $root/manage.py $testargs
 
105
}
 
106
 
 
107
function run_server {
 
108
  echo "Starting Django development server..."
 
109
  ${command_wrapper} python $root/manage.py runserver $testargs
 
110
  echo "Server stopped."
 
111
}
 
112
 
 
113
function run_pylint {
 
114
  echo "Running pylint ..."
 
115
  PYTHONPATH=$root ${command_wrapper} pylint --rcfile=.pylintrc -f parseable $included_dirs > pylint.txt || true
 
116
  CODE=$?
 
117
  grep Global -A2 pylint.txt
 
118
  if [ $CODE -lt 32 ]; then
 
119
      echo "Completed successfully."
 
120
      exit 0
 
121
  else
 
122
      echo "Completed with problems."
 
123
      exit $CODE
 
124
  fi
 
125
}
 
126
 
 
127
function run_pep8 {
 
128
  echo "Running pep8 ..."
 
129
  ${command_wrapper} pep8 $included_dirs || true
 
130
}
 
131
 
 
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."
 
137
}
 
138
 
 
139
function tab_check {
 
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
 
145
    do
 
146
      TAB_COUNT=`awk '/\t/' $TABBED_FILE | wc -l`
 
147
      if [ $TAB_COUNT -gt 0 ]; then
 
148
        echo "$TABBED_FILE: $TAB_COUNT"
 
149
      fi
 
150
    done
 
151
  fi
 
152
  return $TAB_VIOLATIONS;
 
153
}
 
154
 
 
155
function destroy_venv {
 
156
  echo "Cleaning environment..."
 
157
  echo "Removing virtualenv..."
 
158
  rm -rf $venv
 
159
  echo "Virtualenv removed."
 
160
  rm -f .environment_version
 
161
  echo "Environment cleaned."
 
162
}
 
163
 
 
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."
 
173
        return 0
 
174
      fi
 
175
    fi
 
176
  fi
 
177
 
 
178
  if [ $always_venv -eq 1 ]; then
 
179
    install_venv
 
180
  else
 
181
    if [ ! -e ${venv} ]; then
 
182
      echo -e "Environment not found. Install? (Y/n) \c"
 
183
    else
 
184
      echo -e "Your environment appears to be out of date. Update? (Y/n) \c"
 
185
    fi
 
186
    read update_env
 
187
    if [ "x$update_env" = "xY" -o "x$update_env" = "x" -o "x$update_env" = "xy" ]; then
 
188
      install_venv
 
189
    else
 
190
      # Set our command wrapper anyway.
 
191
      command_wrapper="${root}/${with_venv}"
 
192
    fi
 
193
  fi
 
194
}
 
195
 
 
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?"
 
202
      exit 1
 
203
    fi
 
204
  fi
 
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 {} \;
 
208
}
 
209
 
 
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."
 
215
      return 0
 
216
    fi
 
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
 
220
    fi
 
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"
 
227
  fi
 
228
}
 
229
 
 
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."
 
235
      return 0
 
236
    fi
 
237
 
 
238
    cp -r /tmp/.horizon_environment/$JOB_NAME/.venv ./ || true
 
239
    cp -r /tmp/.horizon_environment/$JOB_NAME/.environment_version ./ || true
 
240
 
 
241
    echo "Environment restored successfully."
 
242
  fi
 
243
}
 
244
 
 
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
 
251
  fi
 
252
  echo "Fetching new src packages..."
 
253
  rm -rf $venv/src
 
254
  python tools/install_venv.py
 
255
  command_wrapper="$root/${with_venv}"
 
256
  # Make sure it worked and record the environment version
 
257
  sanity_check
 
258
  chmod -R 754 $venv
 
259
  echo $environment_version > .environment_version
 
260
}
 
261
 
 
262
function run_tests {
 
263
  sanity_check
 
264
 
 
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
 
270
  fi
 
271
 
 
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
 
277
  HORIZON_RESULT=$?
 
278
 
 
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
 
283
  DASHBOARD_RESULT=$?
 
284
 
 
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
 
290
  fi
 
291
  # Remove the leftover coverage files from the -p flag earlier.
 
292
  rm -f .coverage.*
 
293
 
 
294
  if [ $(($HORIZON_RESULT || $DASHBOARD_RESULT)) -eq 0 ]; then
 
295
    echo "Tests completed successfully."
 
296
  else
 
297
    echo "Tests failed."
 
298
  fi
 
299
  exit $(($HORIZON_RESULT || $DASHBOARD_RESULT))
 
300
}
 
301
 
 
302
function run_makemessages {
 
303
  cd horizon
 
304
  ${command_wrapper} $root/manage.py makemessages --all --no-obsolete
 
305
  HORIZON_PY_RESULT=$?
 
306
  ${command_wrapper} $root/manage.py makemessages -d djangojs --all --no-obsolete
 
307
  HORIZON_JS_RESULT=$?
 
308
  cd ../openstack_dashboard
 
309
  ${command_wrapper} $root/manage.py makemessages --all --no-obsolete
 
310
  DASHBOARD_RESULT=$?
 
311
  cd ..
 
312
  exit $(($HORIZON_PY_RESULT || $HORIZON_JS_RESULT || $DASHBOARD_RESULT))
 
313
}
 
314
 
 
315
 
 
316
# ---------PREPARE THE ENVIRONMENT------------ #
 
317
 
 
318
# PROCESS ARGUMENTS, OVERRIDE DEFAULTS
 
319
for arg in "$@"; do
 
320
    process_option $arg
 
321
done
 
322
 
 
323
if [ $quiet -eq 1 ] && [ $never_venv -eq 0 ] && [ $always_venv -eq 0 ]
 
324
then
 
325
  always_venv=1
 
326
fi
 
327
 
 
328
# If destroy is set, just blow it away and exit.
 
329
if [ $destroy -eq 1 ]; then
 
330
  destroy_venv
 
331
  exit 0
 
332
fi
 
333
 
 
334
# Ignore all of this if the -N flag was set
 
335
if [ $never_venv -eq 0 ]; then
 
336
 
 
337
  # Restore previous environment if desired
 
338
  if [ $restore_env -eq 1 ]; then
 
339
    restore_environment
 
340
  fi
 
341
 
 
342
  # Remove the virtual environment if --force used
 
343
  if [ $force -eq 1 ]; then
 
344
    destroy_venv
 
345
  fi
 
346
 
 
347
  # Then check if it's up-to-date
 
348
  environment_check
 
349
 
 
350
  # Create a backup of the up-to-date environment if desired
 
351
  if [ $backup_env -eq 1 ]; then
 
352
    backup_environment
 
353
  fi
 
354
fi
 
355
 
 
356
# ---------EXERCISE THE CODE------------ #
 
357
 
 
358
# Run management commands
 
359
if [ $manage -eq 1 ]; then
 
360
    run_management_command
 
361
    exit $?
 
362
fi
 
363
 
 
364
# Build the docs
 
365
if [ $just_docs -eq 1 ]; then
 
366
    run_sphinx
 
367
    exit $?
 
368
fi
 
369
 
 
370
# Update translation files
 
371
if [ $makemessages -eq 1 ]; then
 
372
    run_makemessages
 
373
    exit $?
 
374
fi
 
375
 
 
376
# PEP8
 
377
if [ $just_pep8 -eq 1 ]; then
 
378
    run_pep8
 
379
    exit $?
 
380
fi
 
381
 
 
382
# Pylint
 
383
if [ $just_pylint -eq 1 ]; then
 
384
    run_pylint
 
385
    exit $?
 
386
fi
 
387
 
 
388
# Tab checker
 
389
if [ $just_tabs -eq 1 ]; then
 
390
    tab_check
 
391
    exit $?
 
392
fi
 
393
 
 
394
# Django development server
 
395
if [ $runserver -eq 1 ]; then
 
396
    run_server
 
397
    exit $?
 
398
fi
 
399
 
 
400
# Full test suite
 
401
run_tests || exit