-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathrun_tests.sh
executable file
·317 lines (277 loc) · 10.4 KB
/
run_tests.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash -ex
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
export PATH=$PATH:/usr/local/sbin:/usr/sbin
SCENARIO=${SCENARIO:-scenario001}
BRANCH=master
# Find OS version and release
source /etc/os-release
OS_NAME_VERS=${ID}${VERSION_ID}
# We could want to override the default repositories or install behavior
INSTALL_FROM_SOURCE=${INSTALL_FROM_SOURCE:-true}
MANAGE_REPOS=${MANAGE_REPOS:-true}
DELOREAN=${DELOREAN:-https://trunk.rdoproject.org/${OS_NAME_VERS}-master/current-passed-ci/delorean.repo}
DELOREAN_DEPS=${DELOREAN_DEPS:-https://trunk.rdoproject.org/${OS_NAME_VERS}-master/delorean-deps.repo}
GIT_BASE_URL=${GIT_BASE_URL:-https://git.openstack.org}
ADDITIONAL_ARGS=${ADDITIONAL_ARGS:-}
SELINUX_ENFORCING=${SELINUX_ENFORCING:-true}
# If logs should be retrieved automatically
COPY_LOGS=${COPY_LOGS:-true}
# Let's add an option for a secondary node, to act as a compute
CONTROLLER_NODE=${CONTROLLER_NODE:-}
COMPUTE_NODE=${COMPUTE_NODE:-}
# Use dnf as package manager if it exist
type -p dnf && export PKG_MGR=dnf || export PKG_MGR=yum
# Install external Puppet modules with r10k
# Uses the following variables:
#
# - ``GEM_BIN_DIR`` must be set to Gem bin directory
# - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
install_external() {
$SUDO ${GEM_BIN_DIR}r10k puppetfile install -v --moduledir ${PUPPETFILE_DIR} --puppetfile Puppetfile1
}
# Install Puppet OpenStack modules with zuul-cloner
# Uses the following variables:
#
# - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
# - ``ZUUL_REF`` must be set to Zuul ref. Fallback to 'None'.
# - ``ZUUL_BRANCH`` must be set to Zuul branch. Fallback to 'master'.
install_openstack() {
cat > clonemap.yaml <<EOF
clonemap:
- name: '(.*?)/puppet-(.*)'
dest: '$PUPPETFILE_DIR/\2'
EOF
# Periodic jobs run without ref on master
ZUUL_REF=${ZUUL_REF:-None}
ZUUL_BRANCH=${ZUUL_BRANCH:-master}
GIT_BASE_URL=${GIT_BASE_URL:-https://git.openstack.org}
local project_names=$(awk '{ if ($1 == ":git") print $3 }' \
Puppetfile0 | tr -d "'," | cut -d '/' -f 4- | xargs
)
$SUDO /usr/zuul-env/bin/zuul-cloner -m clonemap.yaml \
--cache-dir /opt/git \
--zuul-ref $ZUUL_REF \
--zuul-branch $ZUUL_BRANCH \
https://git.openstack.org $project_names
}
# Install all Puppet modules with r10k
# Uses the following variables:
#
# - ``GEM_BIN_DIR`` must be set to Gem bin directory
install_all() {
$SUDO ${GEM_BIN_DIR}r10k puppetfile install -v --puppetfile Puppetfile
}
# Install Puppet OpenStack modules and dependencies by using
# zuul-cloner or r10k.
# Uses the following variables:
#
# - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
# - ``ZUUL_REF`` must be set to Zuul ref
# - ``ZUUL_BRANCH`` must be set to Zuul branch
install_modules() {
# If zuul-cloner is there, have it install modules using zuul refs
if [ -e /usr/zuul-env/bin/zuul-cloner ] ; then
csplit Puppetfile /'Non-OpenStack modules'/ \
--prefix Puppetfile \
--suffix '%d'
install_external
install_openstack
else
install_all
fi
# Copy the Packstack Puppet module
$SUDO cp -r packstack/puppet/modules/packstack ${PUPPETFILE_DIR}
}
if [ $(id -u) != 0 ]; then
SUDO='sudo -E'
# Packstack will connect as root to localhost, set-up the keypair and sshd
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -t rsa -C "packstack-integration-test" -N "" -f ~/.ssh/id_rsa
fi
$SUDO mkdir -p /root/.ssh
cat ~/.ssh/id_rsa.pub | $SUDO tee -a /root/.ssh/authorized_keys
$SUDO chmod 0600 /root/.ssh/authorized_keys
$SUDO sed -i 's/^PermitRootLogin no/PermitRootLogin without-password/g' /etc/ssh/sshd_config
$SUDO service sshd restart
fi
# Make swap configuration consistent
# TODO: REMOVE ME
# https://review.openstack.org/#/c/300122/
source ./tools/fix_disk_layout.sh
# Bump ulimit to avoid too many open file errors
echo "${USER} soft nofile 65536" | $SUDO tee -a /etc/security/limits.conf
echo "${USER} hard nofile 65536" | $SUDO tee -a /etc/security/limits.conf
echo "root soft nofile 65536" | $SUDO tee -a /etc/security/limits.conf
echo "root hard nofile 65536" | $SUDO tee -a /etc/security/limits.conf
# Set SELinux to enforcing/permissive as needed
if [ "${SELINUX_ENFORCING}" = true ]; then
$SUDO setenforce 1
else
$SUDO setenforce 0
fi
# Setup repositories
if [ "${MANAGE_REPOS}" = true ]; then
$SUDO curl -L ${DELOREAN} -o /etc/yum.repos.d/delorean.repo
$SUDO curl -L ${DELOREAN_DEPS} -o /etc/yum.repos.d/delorean-deps.repo
$SUDO $PKG_MGR update -y
fi
# Install dependencies
$SUDO $PKG_MGR -y install puppet \
iproute \
iptables \
iptables-services \
dstat \
openssl-devel \
libffi-devel \
libxml2-devel \
libxslt-devel \
libyaml-devel \
ruby-devel \
openstack-selinux \
policycoreutils \
rubygems \
curl \
gettext \
diffstat \
doxygen \
patch \
patchutils \
subversion \
systemtap
# Some dependencies are not installed on RHEL/CentOS 8, or are renamed
OS_NAME=$(facter operatingsystem)
OS_VERSION=$(facter operatingsystemmajrelease)
$SUDO $PKG_MGR -y install python3-setuptools \
python3-devel \
python3-wheel \
python3-pyyaml
# Don't assume pip is installed
which pip3 && PIP=pip3
if [ -z $PIP ]; then
$SUDO $PKG_MGR -y install python3-pip python3-wheel
PIP=pip3
fi
# Try to use pre-cached cirros images, if available, otherwise download them
rm -rf /tmp/cirros
mkdir /tmp/cirros
export CIRROS_ARCH="$(uname -p)"
export CIRROS_VERSION=${CIRROS_VERSION:-"0.6.3"}
if [ -f ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz ]; then
tar -xzvf ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -C /tmp/cirros/
else
echo "No pre-cached uec archive found, downloading..."
curl -Lo /tmp/cirros/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz --retry 10 https://download.cirros-cloud.net/$CIRROS_VERSION/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz
tar -xzvf /tmp/cirros/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -C /tmp/cirros/
fi
if [ -f ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img ]; then
cp -p ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img /tmp/cirros/
else
echo "No pre-cached disk image found, downloading..."
curl -Lo /tmp/cirros/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img --retry 10 https://download.cirros-cloud.net/$CIRROS_VERSION/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img
fi
echo "Using pre-cached images:"
find /tmp/cirros -type f -printf "%m %n %u %g %s %t" -exec md5sum \{\} \;
# TO-DO: Packstack should handle Hiera and Puppet configuration, so that it works
# no matter the environment
$SUDO su -c 'cat > /etc/puppet/puppet.conf <<EOF
[main]
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl
hiera_config = /etc/puppet/hiera.yaml
[agent]
classfile = $vardir/classes.txt
localconfig = $vardir/localconfig
EOF'
$SUDO su -c 'cat > /etc/puppet/hiera.yaml <<EOF
---
:backends:
- yaml
:yaml:
:datadir: /placeholder
:hierarchy:
- common
- defaults
- "%{clientcert}"
- "%{environment}"
- global
EOF'
# To make sure wrong config files are not used
if [ -d /home/jenkins/.puppet ]; then
$SUDO rm -f /home/jenkins/.puppet
fi
$SUDO puppet config set hiera_config /etc/puppet/hiera.yaml
# Setup dstat for resource usage tracing
if type "dstat" 2>/dev/null; then
DSTAT_OPTS=""
set -e
if dstat --help 2>&1 | grep -q "top-io-adv"; then
DSTAT_OPTS="${DSTAT_OPTS} --top-io-adv"
fi
if dstat --help 2>&1 | grep -q "top-cpu-adv"; then
DSTAT_OPTS="${DSTAT_OPTS} --top-cpu-adv"
fi
set +e
$SUDO dstat -tcmndrylpg $DSTAT_OPTS --nocolor | $SUDO tee --append /var/log/dstat.log > /dev/null &
fi
# Setup packstack
if [ "${INSTALL_FROM_SOURCE}" = true ]; then
$SUDO $PIP install -U pip
$SUDO $PIP install --ignore-installed -c https://opendev.org/openstack/requirements/raw/branch/$BRANCH/upper-constraints.txt --prefix=/usr .
# In Fedora when running with sudo gems are installed at /usr/local/bin/ even when GEM_HOME/GEM_BIN_DIR are set
if [ "${PKG_MGR}" = "dnf" ]; then
export GEM_BIN_DIR=/usr/local/bin/
else
export GEM_BIN_DIR=/tmp/packstackgems/bin/
fi
export PUPPETFILE_DIR=/usr/share/openstack-puppet/modules
export GEM_HOME=/tmp/packstackgems
$SUDO gem install r10k
# make sure there is no puppet module pre-installed
$SUDO rm -rf "${PUPPETFILE_DIR:?}/"*
install_modules
else
$SUDO $PKG_MGR -y install openstack-packstack
fi
# Make sure there are no other puppet modules in the system (happens in gate)
$SUDO rm -rf /etc/puppet/modules/*
# Make sure the fqdn is associated to the IP in /etc/hosts
# Needed for Horizon SSL tests in Tempest
echo -e "\n127.0.0.1 $(facter fqdn)" | $SUDO tee -a /etc/hosts
# Generate configuration from selected scenario and run it
source ./tests/${SCENARIO}.sh
result=$?
# Print output and generate subunit if results exist
if [ -d /var/lib/tempest ]; then
# FIXME(jpena): Work around Fedora image issues with umask
$SUDO chown -R $USER /var/lib/tempest
pushd /var/lib/tempest
if [ -d .testrepository ]; then
$SUDO /usr/bin/testr last || true
$SUDO bash -c "/usr/bin/testr last --subunit > /var/tmp/packstack/latest/testrepository.subunit" || true
elif [ -d .stestr ]; then
$SUDO /usr/bin/stestr last || true
$SUDO bash -c "/usr/bin/stestr last --subunit > /var/tmp/packstack/latest/testrepository.subunit" || true
fi
popd
fi
if [ "${COPY_LOGS}" = true ]; then
source ./tools/copy-logs.sh
recover_default_logs
fi
if [ "${FAILURE}" = true ]; then
exit 1
fi
exit $result