/
run_tempest.sh
267 lines (226 loc) · 10.4 KB
/
run_tempest.sh
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/sh
# run_tempest.sh
# ==============
#
# This script is executed inside the tempest containers defined in the tcib
# repository (tempest, tempest-all and tempest-extra). The main purpose of this
# script is executing the tempest command with correct arguments and preparing
# the tempest.conf file. The execution of the script can be influenced by
# setting values for environment variables which match the TEMPEST_* or
# TEMPESTCONF_* regex.
#
#
# TEMPESTCONF_* environment variables
# -----------------------------------
#
# These variables define with which arguments should be the
# discover-tempest-config command executed.
#
# Supported boolean arguments:
# --create, --insecure, --collect-timing, --no-default-deployer, --debug
# --verbose, --no-rng, --non-admin, --retry-image, --convert-to-raw
#
# Supported string arguments:
# --timeout, --out, --deployer-input, --test-accounts, --create-accounts-file
# --profile, --generate-profile, --image-disk-format, --image,
# --flavor-min-mem, --flavor-min-disk, --disk, --network-id
#
# If you want discover-tempest-config to be executed with any of the boolean arguments
# mentioned above, then set corresponding environment variable to 'true'. The
# name of the variable consists of the prefix 'TEMPESTCONF_' plus the name
# of the argument. For example, if you want to run discover-tempest-config with
# --non-admin argument then set TEMPESTCONF_NON_ADMIN=true. Similarly, in the case
# of string arguments, when you want to run discover-tempest-config with
# --timeout 600 then set TEMPESTCONF_TIMEOUT=600.
#
# To override values in tempest.conf generated by discover-tempest-config please
# use TEMPESTCONF_OVERRIDES.
#
# TEMPEST_* environment ariables
# ------------------------------
#
# These variables define behaviour of the part of the script which is
# responsible for the tempest tests execution.
#
# Supported boolean arguments:
# --smoke, --parallel, --serial
#
# Supported string arguments:
# --include-list, --exclude-list, --concurrency, --worker-file,
#
# If you want the tempest command to be executed with any of the boolean
# arguments mentioned above, then set the corresponding environment variable to
# 'true'. The name of the variable consists of the prefix 'TEMPEST_' plus the
# name of the argument. For example, if you want to run tempest with --smoke
# argument then set TEMPEST_SMOKE=true. Similarly, in the case of string
# arguments, when you want to run tempest witn --include-list=/path/to/list.txt
# then set TEMPEST_INCLUDE_LIST=/path/to/list.txt
#
# The script, putting the above-mentioned tempest environment variables aside,
# offers also the following extra variables: TEMPEST_EXTERNAL_PLUGIN_GIT_URL,
# TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL, TEMPEST_EXTERNAL_PLUGIN_REFSPEC. These
# can be used to specify extra tempest plugins you want to be installed within
# the container plus patches you want to be applied on top of the installed
# plugins.
#
# For example, by setting the environment variables like in the example below
# you ensure that the script downloads barbican-tempest-plugin and
# neutron-tempest-plugin and installs neutron-tempest-plugin with
# "refs/changes/97/896397/2" change from gerrit:
#
#
# TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL=\
# "https://opendev.org/openstack/barbican-tempest-plugin.git,"\
# "https://opendev.org/openstack/neutron-tempest-plugin.git"
#
# TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL=\
# "-,"\
# "https://review.opendev.org/openstack/neutron-tempest-plugin"
#
# TEMPEST_EXTERNAL_PLUGIN_REFSPEC=\
# "-,"\
# "refs/changes/97/896397/2"
#
# Note, that if you specify these variables then tempest will have access only
# to plugins which were specified by these variables. Meaning, if you consider
# the example above, then tempest won't be able to execute tests from
# octavia-tempest-plugin for example.
set -x
HOMEDIR=/var/lib/tempest
TEMPEST_PATH=$HOMEDIR/
TEMPEST_DIR=$HOMEDIR/openshift
CONCURRENCY="${CONCURRENCY:-}"
TEMPESTCONF_ARGS=""
TEMPEST_ARGS=""
[[ ! -z ${USE_EXTERNAL_FILES} ]] && TEMPEST_PATH=$HOMEDIR/external_files/
[[ ${TEMPESTCONF_CREATE:=true} == true ]] && TEMPESTCONF_ARGS+="--create "
[[ ${TEMPESTCONF_INSECURE} == true ]] && TEMPESTCONF_ARGS+="--insecure "
[[ ${TEMPESTCONF_COLLECT_TIMING} == true ]] && TEMPESTCONF_ARGS+="--collect-timing "
[[ ${TEMPESTCONF_NO_DEFAULT_DEPLOYER} == true ]] && TEMPESTCONF_ARGS+="--no-default-deployer "
[[ ${TEMPESTCONF_DEBUG:=true} == true ]] && TEMPESTCONF_ARGS+="--debug "
[[ ${TEMPESTCONF_VERBOSE} == true ]] && TEMPESTCONF_ARGS+="--verbose "
[[ ${TEMPESTCONF_NO_RNG} == true ]] && TEMPESTCONF_ARGS+="--no-rng "
[[ ${TEMPESTCONF_NON_ADMIN} == true ]] && TEMPESTCONF_ARGS+="--non-admin "
[[ ${TEMPESTCONF_RETRY_IMAGE} == true ]] && TEMPESTCONF_ARGS+="--retry-image "
[[ ${TEMPESTCONF_CONVERT_TO_RAW} == true ]] && TEMPESTCONF_ARGS+="--convert-to-raw "
[[ ! -z ${TEMPESTCONF_TIMEOUT} ]] && TEMPESTCONF_ARGS+="--timeout ${TEMPESTCONF_TIMEOUT} "
[[ ! -z ${TEMPESTCONF_OUT} ]] && TEMPESTCONF_ARGS+="--out ${TEMPESTCONF_OUT} "
[[ ! -z ${TEMPESTCONF_DEPLOYER_INPUT} ]] && TEMPESTCONF_ARGS+="--deployer-input ${TEMPESTCONF_DEPLOYER_INPUT} "
[[ ! -z ${TEMPESTCONF_TEST_ACCOUNTS} ]] && TEMPESTCONF_ARGS+="--test-accounts ${TEMPESTCONF_TEST_ACCOUNTS} "
[[ ! -z ${TEMPESTCONF_CREATE_ACCOUNTS_FILE} ]] && TEMPESTCONF_ARGS+="--create-accounts-file ${TEMPESTCONF_CREATE_ACCOUNTS_FILE} "
[[ ! -z ${TEMPESTCONF_PROFILE} ]] && TEMPESTCONF_ARGS+="--profile ${TEMPESTCONF_PROFILE} "
[[ ! -z ${TEMPESTCONF_GENERATE_PROFILE} ]] && TEMPESTCONF_ARGS+="--generate-profile ${TEMPESTCONF_GENERATE_PROFILE} "
[[ ! -z ${TEMPESTCONF_IMAGE_DISK_FORMAT} ]] && TEMPESTCONF_ARGS+="--image-disk-format ${TEMPESTCONF_IMAGE_DISK_FORMAT} "
[[ ! -z ${TEMPESTCONF_IMAGE} ]] && TEMPESTCONF_ARGS+="--image ${TEMPESTCONF_IMAGE} "
[[ ! -z ${TEMPESTCONF_FLAVOR_MIN_MEM} ]] && TEMPESTCONF_ARGS+="--flavor-min-mem ${TEMPESTCONF_FLAVOR_MIN_MEM} "
[[ ! -z ${TEMPESTCONF_FLAVOR_MIN_DISK} ]] && TEMPESTCONF_ARGS+="--flavor-min-disk ${TEMPESTCONF_FLAVOR_MIN_DISK} "
[[ ! -z ${TEMPESTCONF_NETWORK_ID} ]] && TEMPESTCONF_ARGS+="--network-id ${TEMPESTCONF_NETWORK_ID} "
TEMPESTCONF_OVERRIDES="$(echo ${TEMPESTCONF_OVERRIDES} | tr '\n' ' ') identity.v3_endpoint_type public"
# Tempest arguments
TEMPEST_EXTERNAL_PLUGIN_GIT_URL="${TEMPEST_EXTERNAL_PLUGIN_GIT_URL:-}"
TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL="${TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL:-}"
TEMPEST_EXTERNAL_PLUGIN_REFSPEC="${TEMPEST_EXTERNAL_PLUGIN_REFSPEC:-}"
TEMPEST_EXTERNAL_PLUGIN_DIR=/var/lib/tempest/external-plugins
# Convert comma separated lists to arrays
OLD_IFS=$IFS
IFS=","
read -ra TEMPEST_EXTERNAL_PLUGIN_GIT_URL <<< $TEMPEST_EXTERNAL_PLUGIN_GIT_URL
read -ra TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL <<< $TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL
read -ra TEMPEST_EXTERNAL_PLUGIN_REFSPEC <<< $TEMPEST_EXTERNAL_PLUGIN_REFSPEC
IFS=$OLD_IFS
[[ ${TEMPEST_SMOKE} == true ]] && TEMPEST_ARGS+="--smoke "
[[ ${TEMPEST_PARALLEL:=true} == true ]] && TEMPEST_ARGS+="--parallel "
[[ ${TEMPEST_SERIAL} == true ]] && TEMPEST_ARGS+="--serial "
[[ ! -z ${TEMPEST_INCLUDE_LIST} ]] && TEMPEST_ARGS+="--include-list ${TEMPEST_INCLUDE_LIST} "
[[ ! -z ${TEMPEST_EXCLUDE_LIST} ]] && TEMPEST_ARGS+="--exclude-list ${TEMPEST_EXCLUDE_LIST} "
[[ ! -z ${TEMPEST_CONCURRENCY} ]] && TEMPEST_ARGS+="--concurrency ${TEMPEST_CONCURRENCY} "
[[ ! -z ${TEMPEST_WORKER_FILE} ]] && TEMPEST_ARGS+="--worker-file ${TEMPEST_WORKER_FILE} "
[[ -z ${TEMPEST_INCLUDE_LIST} ]] && TEMPEST_ARGS+="--include-list ${TEMPEST_PATH}include.txt "
[[ -z ${TEMPEST_EXCLUDE_LIST} ]] && TEMPEST_ARGS+="--exclude-list ${TEMPEST_PATH}exclude.txt "
if [[ ! -z ${TEMPESTCONF_APPEND} ]]; then
while IFS= read -r line; do
TEMPESTCONF_ARGS+="--append $line "
done <<< "$TEMPESTCONF_APPEND"
fi
if [[ ! -z ${TEMPESTCONF_REMOVE} ]]; then
while IFS= read -r line; do
TEMPESTCONF_ARGS+="--remove $line "
done <<< "$TEMPESTCONF_REMOVE"
fi
if [ -n "$CONCURRENCY" ] && [ -z ${TEMPEST_CONCURRENCY} ]; then
TEMPEST_ARGS+="--concurrency ${CONCURRENCY} "
fi
function run_git_tempest {
mkdir -p $TEMPEST_EXTERNAL_PLUGIN_DIR
pushd $TEMPEST_EXTERNAL_PLUGIN_DIR
python3 -m venv .venv
source ./.venv/bin/activate
for plugin_index in "${!TEMPEST_EXTERNAL_PLUGIN_GIT_URL[@]}"; do
git_url=${TEMPEST_EXTERNAL_PLUGIN_GIT_URL[plugin_index]}
change_url=${TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL[plugin_index]}
refspec=${TEMPEST_EXTERNAL_PLUGIN_REFSPEC[plugin_index]}
plugin_name=$(basename -s .git $git_url)
git clone $git_url
if [[ ! -z $change_url ]] && [[ ! -z $refspec ]] || \
[[ $change_url != "-" ]] && [[ $refspec != "-" ]]; then
pushd $plugin_name
git fetch $change_url $refspec
git checkout FETCH_HEAD
popd
fi
pip install -chttps://releases.openstack.org/constraints/upper/2023.1 ./$plugin_name
done
pushd $HOMEDIR
tempest init openshift
pushd $TEMPEST_DIR
discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES}
tempest run ${TEMPEST_ARGS}
RETURN_VALUE=$?
deactivate
popd
popd
popd
}
function run_rpm_tempest {
pushd $HOMEDIR
tempest init openshift
pushd $TEMPEST_DIR
discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES}
tempest run ${TEMPEST_ARGS}
RETURN_VALUE=$?
popd
popd
}
function generate_test_results {
pushd $TEMPEST_DIR
echo "Generate subunit"
stestr last --subunit > ${TEMPEST_PATH}testrepository.subunit || true
echo "Generate subunit xml file"
subunit2junitxml ${TEMPEST_PATH}testrepository.subunit > ${TEMPEST_PATH}tempest_results.xml || true
echo "Generate html result"
subunit2html ${TEMPEST_PATH}testrepository.subunit ${TEMPEST_PATH}stestr_results.html || true
echo Copying logs file
cp -rf ${TEMPEST_DIR}/* ${TEMPEST_PATH}
popd
}
export OS_CLOUD=default
if [ ! -z ${USE_EXTERNAL_FILES} ]; then
mkdir -p $HOME/.config/openstack
cp ${TEMPEST_PATH}clouds.yaml $HOME/.config/openstack/clouds.yaml
fi
if [ -f ${TEMPEST_PATH}profile.yaml ] && [ -z ${TEMPESTCONF_PROFILE} ]; then
TEMPESTCONF_ARGS+="--profile ${TEMPEST_PATH}profile.yaml "
fi
if [ ! -f ${TEMPEST_PATH}include.txt ] && [ -z ${TEMPEST_INCLUDE_LIST} ]; then
echo "tempest.api.identity.v3" > ${TEMPEST_PATH}include.txt
fi
if [ ! -f ${TEMPEST_PATH}exclude.txt ] && [ -z ${TEMPEST_EXCLUDE_LIST} ]; then
touch ${TEMPEST_PATH}exclude.txt
fi
if [ -z $TEMPEST_EXTERNAL_PLUGIN_GIT_URL ]; then
run_rpm_tempest
else
run_git_tempest
fi
generate_test_results
exit ${RETURN_VALUE}