forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·316 lines (271 loc) · 9.34 KB
/
test.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
#!/bin/bash
#
# This file is part of the KubeVirt project
#
# 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.
#
# Copyright 2017 Red Hat, Inc.
#
# CI considerations: $TARGET is used by the jenkins build, to distinguish what to test
# Currently considered $TARGET values:
# vagrant-dev: Runs all functional tests on a development vagrant setup (deprecated)
# vagrant-release: Runs all possible functional tests on a release deployment in vagrant (deprecated)
# kubernetes-dev: Runs all functional tests on a development kubernetes setup
# kubernetes-release: Runs all functional tests on a release kubernetes setup
# openshift-release: Runs all functional tests on a release openshift setup
# TODO: vagrant-tagged-release: Runs all possible functional tests on a release deployment in vagrant on a tagged release
set -ex
export WORKSPACE="${WORKSPACE:-$PWD}"
readonly ARTIFACTS_PATH="${ARTIFACTS-$WORKSPACE/exported-artifacts}"
readonly TEMPLATES_SERVER="https://templates.ovirt.org/kubevirt/"
readonly BAZEL_CACHE="${BAZEL_CACHE:-http://bazel-cache.kubevirt-prow.svc.cluster.local:8080/kubevirt.io/kubevirt}"
if [[ $TARGET =~ windows.* ]]; then
export KUBEVIRT_PROVIDER="k8s-1.11.0"
else
export KUBEVIRT_PROVIDER=$TARGET
fi
if [ ! -d "cluster-up/cluster/$KUBEVIRT_PROVIDER" ]; then
echo "The cluster provider $KUBEVIRT_PROVIDER does not exist"
exit 1
fi
if [[ $TARGET =~ os-.* ]]; then
# when testing on slow CI system cleanup sometimes takes very long.
# openshift clusters are more memory demanding. If the cleanup
# of old vms does not go fast enough they run out of memory.
# To still allow continuing with the tests, give more memory in CI.
export KUBEVIRT_MEMORY_SIZE=6144M
fi
if [[ "$TARGET" =~ .*sriov.* ]]; then
export KUBEVIRT_NUM_NODES=1 # to be sure the guest lands on the master node
else
export KUBEVIRT_NUM_NODES=2
fi
export RHEL_NFS_DIR=${RHEL_NFS_DIR:-/var/lib/stdci/shared/kubevirt-images/rhel7}
export RHEL_LOCK_PATH=${RHEL_LOCK_PATH:-/var/lib/stdci/shared/download_rhel_image.lock}
export WINDOWS_NFS_DIR=${WINDOWS_NFS_DIR:-/var/lib/stdci/shared/kubevirt-images/windows2016}
export WINDOWS_LOCK_PATH=${WINDOWS_LOCK_PATH:-/var/lib/stdci/shared/download_windows_image.lock}
wait_for_download_lock() {
local max_lock_attempts=60
local lock_wait_interval=60
for ((i = 0; i < $max_lock_attempts; i++)); do
if (set -o noclobber; > $1) 2> /dev/null; then
echo "Acquired lock: $1"
return
fi
sleep $lock_wait_interval
done
echo "Timed out waiting for lock: $1" >&2
exit 1
}
safe_download() (
# Download files into shared locations using a lock.
# The lock will be released as soon as this subprocess will exit
local lockfile="${1:?Lockfile was not specified}"
local download_from="${2:?Download from was not specified}"
local download_to="${3:?Download to was not specified}"
local timeout_sec="${4:-3600}"
touch "$lockfile"
exec {fd}< "$lockfile"
flock -e -w "$timeout_sec" "$fd" || {
echo "ERROR: Timed out after $timeout_sec seconds waiting for lock" >&2
exit 1
}
local remote_sha1_url="${download_from}.sha1"
local local_sha1_file="${download_to}.sha1"
local remote_sha1
local retry=3
# Remote file includes only sha1 w/o filename suffix
for i in $(seq 1 $retry);
do
remote_sha1="$(curl -s "${remote_sha1_url}")"
if [[ "$remote_sha1" != "" ]]; then
break
fi
done
if [[ "$(cat "$local_sha1_file")" != "$remote_sha1" ]]; then
echo "${download_to} is not up to date, corrupted or doesn't exist."
echo "Downloading file from: ${remote_sha1_url}"
curl "$download_from" --output "$download_to"
sha1sum "$download_to" | cut -d " " -f1 > "$local_sha1_file"
[[ "$(cat "$local_sha1_file")" == "$remote_sha1" ]] || {
echo "${download_to} is corrupted"
return 1
}
else
echo "${download_to} is up to date"
fi
)
if [[ $TARGET =~ os-.* ]] || [[ $TARGET =~ (okd|ocp)-.* ]]; then
# Create images directory
if [[ ! -d $RHEL_NFS_DIR ]]; then
mkdir -p $RHEL_NFS_DIR
fi
# Download RHEL image
rhel_image_url="${TEMPLATES_SERVER}/rhel7.img"
rhel_image="$RHEL_NFS_DIR/disk.img"
safe_download "$RHEL_LOCK_PATH" "$rhel_image_url" "$rhel_image" || exit 1
fi
if [[ $TARGET =~ windows.* ]]; then
# Create images directory
if [[ ! -d $WINDOWS_NFS_DIR ]]; then
mkdir -p $WINDOWS_NFS_DIR
fi
# Download Windows image
win_image_url="${TEMPLATES_SERVER}/win01.img"
win_image="$WINDOWS_NFS_DIR/disk.img"
safe_download "$WINDOWS_LOCK_PATH" "$win_image_url" "$win_image" || exit 1
fi
kubectl() { cluster-up/kubectl.sh "$@"; }
export NAMESPACE="${NAMESPACE:-kubevirt}"
# Make sure that the VM is properly shut down on exit
trap '{ make cluster-down; }' EXIT SIGINT SIGTERM SIGSTOP
make cluster-down
# Create .bazelrc to use remote cache
cat >ci.bazelrc <<EOF
startup --host_jvm_args=-Dbazel.DigestFunction=sha256
build --remote_local_fallback
build --remote_http_cache=${BAZEL_CACHE}
build --jobs=4
EOF
# Build and test images with a custom image name prefix
export IMAGE_PREFIX_ALT=${IMAGE_PREFIX_ALT:-kv-}
# build all images with the basic repeat logic
# probably because load on the node, possible situation when the bazel
# fails to download artifacts, to avoid job fails because of it,
# we repeat the build images action
set +e
for i in $(seq 1 3);
do
make bazel-build-images
done
set -e
make bazel-build-images
make cluster-up
# Wait for nodes to become ready
set +e
kubectl get nodes --no-headers
kubectl_rc=$?
while [ $kubectl_rc -ne 0 ] || [ -n "$(kubectl get nodes --no-headers | grep NotReady)" ]; do
echo "Waiting for all nodes to become ready ..."
kubectl get nodes --no-headers
kubectl_rc=$?
sleep 10
done
set -e
echo "Nodes are ready:"
kubectl get nodes
make cluster-build
# I do not have good indication that OKD API server ready to serve requests, so I will just
# repeat cluster-deploy until it succeeds
until make cluster-deploy; do
sleep 1
done
hack/dockerized bazel shutdown
# OpenShift is running important containers under default namespace
namespaces=(kubevirt default)
if [[ $NAMESPACE != "kubevirt" ]]; then
namespaces+=($NAMESPACE)
fi
timeout=300
sample=30
for i in ${namespaces[@]}; do
# Wait until kubevirt pods are running
current_time=0
while [ -n "$(kubectl get pods -n $i --no-headers | grep -v Running)" ]; do
echo "Waiting for kubevirt pods to enter the Running state ..."
kubectl get pods -n $i --no-headers | >&2 grep -v Running || true
sleep $sample
current_time=$((current_time + sample))
if [ $current_time -gt $timeout ]; then
echo "Dump kubevirt state:"
make dump
exit 1
fi
done
# Make sure all containers are ready
current_time=0
while [ -n "$(kubectl get pods -n $i -o'custom-columns=status:status.containerStatuses[*].ready' --no-headers | grep false)" ]; do
echo "Waiting for KubeVirt containers to become ready ..."
kubectl get pods -n $i -o'custom-columns=status:status.containerStatuses[*].ready' --no-headers | grep false || true
sleep $sample
current_time=$((current_time + sample))
if [ $current_time -gt $timeout ]; then
echo "Dump kubevirt state:"
make dump
exit 1
fi
done
kubectl get pods -n $i
done
kubectl version
mkdir -p "$ARTIFACTS_PATH"
ginko_params="--ginkgo.noColor --junit-output=$ARTIFACTS_PATH/junit.functest.xml"
# Prepare PV for Windows testing
if [[ $TARGET =~ windows.* ]]; then
kubectl create -f - <<EOF
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: disk-windows
labels:
kubevirt.io/test: "windows"
spec:
capacity:
storage: 30Gi
accessModes:
- ReadWriteOnce
nfs:
server: "nfs"
path: /
storageClassName: windows
EOF
# Run only Windows tests
ginko_params="$ginko_params --ginkgo.focus=Windows"
elif [[ $TARGET =~ multus.* ]]; then
ginko_params="$ginko_params --ginkgo.focus=Multus|Networking|VMIlifecycle|Expose"
elif [[ $TARGET =~ genie.* ]]; then
ginko_params="$ginko_params --ginkgo.focus=Genie|Networking|VMIlifecycle|Expose"
elif [[ $TARGET =~ sriov.* ]]; then
ginko_params="$ginko_params --ginkgo.focus=SRIOV"
elif [[ $TARGET =~ gpu.* ]]; then
ginko_params="$ginko_params --ginkgo.focus=GPU"
elif [[ $TARGET =~ (okd|ocp).* ]]; then
ginko_params="$ginko_params --ginkgo.skip=Genie|SRIOV|GPU"
else
ginko_params="$ginko_params --ginkgo.skip=Multus|Genie|SRIOV|GPU"
fi
# Prepare RHEL PV for Template testing
if [[ $TARGET =~ os-.* ]]; then
ginko_params="$ginko_params|Networkpolicy"
kubectl create -f - <<EOF
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: disk-rhel
labels:
kubevirt.io/test: "rhel"
spec:
capacity:
storage: 15Gi
accessModes:
- ReadWriteOnce
nfs:
server: "nfs"
path: /
storageClassName: rhel
EOF
fi
# Run functional tests
FUNC_TEST_ARGS=$ginko_params make functest