Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 120 lines (108 sloc) 3.601 kb
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
1 #!/bin/bash
2
3 function usage {
4 echo "Usage: $0 [OPTION]..."
5 echo "Run Nova's test suite(s)"
6 echo ""
7 echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
8 echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
10552f6 Updated run_tests.sh usage info to reflect the --stop flag
Alex Meade authored
9 echo " -x, --stop Stop running tests after the first error or failure."
7c8c2f5 Adds --force option to run_tests.sh to clear virtualenv. Useful when dep...
jaypipes@gmail.com authored
10 echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
33ca304 @ironcamel Changed pep8 command line option from --just-pep8 to --pep8.
ironcamel authored
11 echo " -p, --pep8 Just run pep8"
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
12 echo " -h, --help Print this usage message"
43dd1ec @rconradharris Showing elapsed time is now default
rconradharris authored
13 echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list"
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
14 echo ""
15 echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
16 echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
17 echo " prefer to run tests NOT in a virtual environment, simply pass the -N option."
18 exit
19 }
20
21 function process_option {
7c8c2f5 Adds --force option to run_tests.sh to clear virtualenv. Useful when dep...
jaypipes@gmail.com authored
22 case "$1" in
3d15adb Merge case statement options
jaypipes@gmail.com authored
23 -h|--help) usage;;
24 -V|--virtual-env) let always_venv=1; let never_venv=0;;
25 -N|--no-virtual-env) let always_venv=0; let never_venv=1;;
7c8c2f5 Adds --force option to run_tests.sh to clear virtualenv. Useful when dep...
jaypipes@gmail.com authored
26 -f|--force) let force=1;;
33ca304 @ironcamel Changed pep8 command line option from --just-pep8 to --pep8.
ironcamel authored
27 -p|--pep8) let just_pep8=1;;
e204445 @rconradharris Ensuring pep8 runs even when nose optons are passed
rconradharris authored
28 -*) noseopts="$noseopts $1";;
821fc6b @ewanmellor Bug #694890: run_tests.sh sometimes doesn't pass arguments to nosetest
ewanmellor authored
29 *) noseargs="$noseargs $1"
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
30 esac
31 }
849a406 @emonty Changed Makefile to shell script. The Makefile approach completely broke
emonty authored
32
33 venv=.nova-venv
34 with_venv=tools/with_venv.sh
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
35 always_venv=0
36 never_venv=0
7c8c2f5 Adds --force option to run_tests.sh to clear virtualenv. Useful when dep...
jaypipes@gmail.com authored
37 force=0
821fc6b @ewanmellor Bug #694890: run_tests.sh sometimes doesn't pass arguments to nosetest
ewanmellor authored
38 noseargs=
e204445 @rconradharris Ensuring pep8 runs even when nose optons are passed
rconradharris authored
39 noseopts=
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
40 wrapper=""
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
41 just_pep8=0
7e46969 Output of run_tests.sh to be closer to trial
termie authored
42
7c8c2f5 Adds --force option to run_tests.sh to clear virtualenv. Useful when dep...
jaypipes@gmail.com authored
43 for arg in "$@"; do
44 process_option $arg
45 done
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
46
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
47 function run_tests {
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
48 # Just run the test suites in current environment
5e2f82b @vishvananda revert logfile redirection and make colors work by temporarily switching...
vishvananda authored
49 ${wrapper} $NOSETESTS 2> run_tests.log
2bbbfc5 @termie dump error output directly on short import errors
termie authored
50 # If we get some short import error right away, print the error log directly
51 RESULT=$?
52 if [ "$RESULT" -ne "0" ];
53 then
5e2f82b @vishvananda revert logfile redirection and make colors work by temporarily switching...
vishvananda authored
54 ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
2bbbfc5 @termie dump error output directly on short import errors
termie authored
55 if [ "$ERRSIZE" -lt "40" ];
56 then
3aa0183 @vishvananda fix missed err.log
vishvananda authored
57 cat run_tests.log
2bbbfc5 @termie dump error output directly on short import errors
termie authored
58 fi
59 fi
60 return $RESULT
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
61 }
849a406 @emonty Changed Makefile to shell script. The Makefile approach completely broke
emonty authored
62
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
63 function run_pep8 {
64 echo "Running pep8 ..."
67148b1 @galstrom21 Added opt-out system for excluding files/dirs from pep8 (using GLOBIGNOR...
galstrom21 authored
65 # Opt-out files from pep8
66 ignore_scripts="*.sh:*nova-debug:*clean-vlans"
67 ignore_files="*eventlet-patch:*pip-requires"
68 ignore_dirs="*ajaxterm*"
69 GLOBIGNORE="$ignore_scripts:$ignore_files:$ignore_dirs"
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
70 srcfiles=`find bin -type f ! -name "nova.conf*"`
67148b1 @galstrom21 Added opt-out system for excluding files/dirs from pep8 (using GLOBIGNOR...
galstrom21 authored
71 srcfiles+=" `find tools/*`"
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
72 srcfiles+=" nova setup.py plugins/xenserver/xenapi/etc/xapi.d/plugins/glance"
d4742cf Added virtual environment to PEP8 tests
Alex Meade authored
73 # Just run PEP8 in current environment
74 ${wrapper} pep8 --repeat --show-pep8 --show-source \
75 --exclude=vcsversion.py ${srcfiles}
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
76 }
77
e204445 @rconradharris Ensuring pep8 runs even when nose optons are passed
rconradharris authored
78 NOSETESTS="python run_tests.py $noseopts $noseargs"
7c8c2f5 Adds --force option to run_tests.sh to clear virtualenv. Useful when dep...
jaypipes@gmail.com authored
79
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
80 if [ $never_venv -eq 0 ]
81 then
82 # Remove the virtual environment if --force used
83 if [ $force -eq 1 ]; then
84 echo "Cleaning virtualenv..."
85 rm -rf ${venv}
86 fi
87 if [ -e ${venv} ]; then
88 wrapper="${with_venv}"
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
89 else
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
90 if [ $always_venv -eq 1 ]; then
91 # Automatically install the virtualenv
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
92 python tools/install_venv.py
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
93 wrapper="${with_venv}"
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
94 else
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
95 echo -e "No virtual environment found...create one? (Y/n) \c"
96 read use_ve
97 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
98 # Install the virtualenv and run the test suite in it
99 python tools/install_venv.py
86b96d3 @termie Only run pep8 after tests if running all the tests
termie authored
100 wrapper=${with_venv}
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
101 fi
fb382c8 Adapts the run_tests.sh script to allow interactive or automated creatio...
jaypipes@gmail.com authored
102 fi
103 fi
849a406 @emonty Changed Makefile to shell script. The Makefile approach completely broke
emonty authored
104 fi
50ec058 @sorenh Refactor run_tests.sh to allow us to run an extra command after the test...
sorenh authored
105
d4742cf Added virtual environment to PEP8 tests
Alex Meade authored
106 if [ $just_pep8 -eq 1 ]; then
107 run_pep8
108 exit
109 fi
110
2ea651d @ironcamel Exit early if tests fail, before pep8 is run.
ironcamel authored
111 run_tests || exit
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
112
e204445 @rconradharris Ensuring pep8 runs even when nose optons are passed
rconradharris authored
113 # NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
114 # not when we're running tests individually. To handle this, we need to
115 # distinguish between options (noseopts), which begin with a '-', and
116 # arguments (noseargs).
1483311 @ironcamel Added an option to run_tests.sh so you can run just pep8. So now you can...
ironcamel authored
117 if [ -z "$noseargs" ]; then
118 run_pep8
86b96d3 @termie Only run pep8 after tests if running all the tests
termie authored
119 fi
Something went wrong with that request. Please try again.