-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·212 lines (190 loc) · 5.96 KB
/
run_tests.sh
File metadata and controls
executable file
·212 lines (190 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
set -eu
function usage {
echo "Usage: $0 [OPTION]..."
echo "Run Devstacks's test suite(s)"
echo ""
echo " -O, --only test_suite Only run the specified test suite. Valid values are:"
echo " Note: by default, run_tests will run all suites."
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."
echo " -x, --stop Stop running tests after the first error or failure."
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " Note: you might need to 'sudo' this since it pip installs into the virtual environment."
echo " -P, --skip-pep8 Just run tests; skip pep8 check."
echo " -p, --pep8 Just run pep8."
echo " -l, --pylint Just run pylint."
echo " -y, --yaml Just validate YAML."
echo " -c, --with-coverage Generate coverage report."
echo " -h, --help Print this usage message."
echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list."
echo " --verbose Print additional logging."
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."
echo ""
echo "Note: with no options specified, the script will run the pep8 check after completing the tests."
echo " If you prefer not to run pep8, simply pass the -P option."
exit
}
only_run_flag=0
only_run=""
function process_option {
if [ $only_run_flag -eq 1 ]; then
only_run_flag=0
only_run=$1
return
else
case "$1" in
-h|--help) usage;;
-V|--virtual-env) always_venv=1; never_venv=0;;
-N|--no-virtual-env) always_venv=0; never_venv=1;;
-O|--only) only_run_flag=1;;
-f|--force) force=1;;
-P|--skip-pep8) skip_pep8=1;;
-p|--pep8) just_pep8=1;;
-l|--pylint) just_pylint=1;;
-y|--yaml) just_yaml=1;;
-c|--with-coverage) coverage=1;;
-*) addlopts="$addlopts $1";;
*) addlargs="$addlargs $1"
esac
fi
}
venv=.venv
with_venv=tools/with_venv.sh
always_venv=0
never_venv=0
force=0
addlargs=
addlopts=
wrapper=""
just_pep8=0
skip_pep8=0
just_pylint=0
just_yaml=0
coverage=0
pylintrc_fn="pylintrc"
for arg in "$@"; do
process_option $arg
done
# If enabled, tell nose/unittest to collect coverage data
if [ $coverage -eq 1 ]; then
addlopts="$addlopts --with-coverage --cover-package=devstack"
fi
if [ "x$only_run" = "x" ]; then
RUNTESTS="python run_tests.py$addlopts$addlargs"
else
RUNTESTS="python run_tests.py$addlopts$addlargs -O $only_run"
fi
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}"
else
if [ $always_venv -eq 1 ]; then
# Automatically install the virtualenv
python tools/install_venv.py
wrapper="${with_venv}"
else
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
python tools/install_venv.py
wrapper=${with_venv}
fi
fi
fi
fi
function run_tests {
OFN="run_tests.log"
# Just run the test suites in current environment
${wrapper} $RUNTESTS 2>$OFN | tee $OFN
# If we get some short import error right away, print the error log directly
RESULT=$?
echo "Check '$OFN' for a full error report."
if [ "$RESULT" -ne "0" ];
then
ERRSIZE=`wc -l $OFN | awk '{print \$1}'`
if [ "$ERRSIZE" -lt "40" ];
then
cat $OFN
fi
fi
return $RESULT
}
function run_pep8 {
echo "Running pep8 ..."
SRC_FILES=`find devstack -type f | grep "py\$"`
SRC_FILES+=" stack run_tests.py"
PEP_IGNORES="E202,E501"
TEE_FN="pep8.log"
PEP8_OPTS="--ignore=$PEP_IGNORES --repeat"
pep8 ${PEP8_OPTS} ${SRC_FILES} 2>&1 | tee $TEE_FN
if [ "$?" -ne "0" ]; then
echo "Sorry, cannot run pep8 ..."
exit 1
else
echo "Successfully ran pep8 ..."
echo "Check '$TEE_FN' for a full report."
fi
}
function run_pylint {
echo "Running pylint ..."
PYLINT_OPTIONS="--rcfile=$pylintrc_fn --output-format=parseable"
PYLINT_INCLUDE=`find devstack -type f | grep "py\$"`
PYLINT_INCLUDE+=" stack run_tests.py"
TEE_FN="pylint.log"
echo "Pylint messages count: "
pylint ${PYLINT_OPTIONS} ${PYLINT_INCLUDE} 2>&1 | tee $TEE_FN | grep 'devstack/' | wc -l
if [ "$?" -ne "0" ]; then
echo "Sorry, cannot run pylint ..."
exit 1
else
echo "Successfully ran pylint ..."
echo "Check '$TEE_FN' for a full report."
fi
}
function validate_yaml {
echo "Validating YAML files..."
for f in `find conf/ -name *.yaml -type f`; do
echo "Checking yaml file: $f"
tools/validate_yaml.py $f
done
}
# Delete old coverage data from previous runs
if [ $coverage -eq 1 ]; then
${wrapper} coverage erase
fi
if [ $just_pep8 -eq 1 ]; then
run_pep8
exit
fi
if [ $just_pylint -eq 1 ]; then
run_pylint
exit
fi
if [ $just_yaml -eq 1 ]; then
validate_yaml
exit
fi
echo "Running tests..."
run_tests
if [ $skip_pep8 -eq 0 ]; then
# Run the pep8 check
run_pep8
fi
# Since we run multiple test suites, we need to execute 'coverage combine'
if [ $coverage -eq 1 ]; then
echo "Generating coverage report in covhtml/"
${wrapper} coverage combine
${wrapper} coverage html -d covhtml -i
${wrapper} coverage report --omit='/usr*,devstack/test*,.,setup.py,*egg*,/Library*,*.xml,*.tpl'
fi