forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·278 lines (239 loc) · 8.4 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
#!/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="$WORKSPACE/exported-artifacts"
readonly TEMPLATES_SERVER="https://templates.ovirt.org/kubevirt/"
if [[ $TARGET =~ openshift-.* ]]; 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
if [[ $TARGET =~ .*-crio-.* ]]; then
export KUBEVIRT_PROVIDER="os-3.11.0-crio"
elif [[ $TARGET =~ .*-multus-.* ]]; then
export KUBEVIRT_PROVIDER="os-3.11.0-multus"
else
export KUBEVIRT_PROVIDER="os-3.11.0"
fi
elif [[ $TARGET =~ .*-1.10.4-.* ]]; then
export KUBEVIRT_PROVIDER="k8s-1.10.4"
elif [[ $TARGET =~ .*-multus-1.12.2-.* ]]; then
export KUBEVIRT_PROVIDER="k8s-multus-1.12.2"
elif [[ $TARGET =~ .*-genie-1.11.1-.* ]]; then
export KUBEVIRT_PROVIDER="k8s-genie-1.11.1"
else
export KUBEVIRT_PROVIDER="k8s-1.11.0"
fi
export KUBEVIRT_NUM_NODES=2
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
# Remote file includes only sha1 w/o filename suffix
remote_sha1="$(curl -s "${remote_sha1_url}")"
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 =~ openshift.* ]]; 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/kubectl.sh "$@"; }
# If run on CI use random kubevirt system-namespaces
if [ -n "${JOB_NAME}" ]; then
export NAMESPACE="kubevirt-system-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)"
cat >hack/config-local.sh <<EOF
namespace=${NAMESPACE}
EOF
else
export NAMESPACE="${NAMESPACE:-kubevirt}"
fi
# Make sure that the VM is properly shut down on exit
trap '{ make cluster-down; }' EXIT SIGINT SIGTERM SIGSTOP
# Check if we are on a pull request in jenkins.
export KUBEVIRT_CACHE_FROM=${ghprbTargetBranch}
if [ -n "${KUBEVIRT_CACHE_FROM}" ]; then
make pull-cache
fi
make cluster-down
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-sync
# 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
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
exit 1
fi
done
kubectl get pods -n $i
done
kubectl version
mkdir -p "$ARTIFACTS_PATH"
ginko_params="--ginkgo.noColor --junit-output=$ARTIFACTS_PATH/tests.junit.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: local
EOF
# Run only Windows tests
ginko_params="$ginko_params --ginkgo.focus=Windows"
elif [[ $TARGET =~ multus.* ]] || [[ $TARGET =~ genie.* ]]; then
# Run networking tests only (general networking, multus, genie, ...)
# If multus or genie is not present the test will be skipped base on per-test checks
ginko_params="$ginko_params --ginkgo.focus=Networking|VMIlifecycle|Expose|Networkpolicy"
fi
# Prepare RHEL PV for Template testing
if [[ $TARGET =~ openshift-.* ]]; then
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: local
EOF
fi
# Run functional tests
FUNC_TEST_ARGS=$ginko_params make functest